Understanding Linear Feedback Shift Registers – The Easy Way Written by Dan Healy for UCSC’s CMPE125 class.
This tutorial will teach you how to use LFSRs, why other tutorials on the subject are so confusing, and how you can go about understanding the underlying mathematics if you really want to know. First, a glossary. Linear Feedback Shift Register (LFSR):
An n-bit shift register which pseudo-randomly scrolls between 2 n-1 values, but does it very quickly bec quickly because ause there the re is min minim imal al combinational logic logic involved. involved. Once it reaches reac hes its fin final al state, state , it will will traverse travers e the sequence seq uence exactly exac tly as before. b efore. It has many appli ap plicat catiions you should should already alrea dy be famil familiar iar with with if if you’re reading this. Primitive polynomial:
(very basically) A polynomial of degree n that has the form: 1 + … + xn , where (…) are zero or more terms with with a coefficient coefficient of 1. xn and 1 are always always present. For Fo r each degree, there there can be many many differ different ent prim primiti itive ve poly po lynomi nomials. als. These polynomi p olynomials als also must must satisfy sa tisfy other other mathematical mathematical conditions, co nditions, if you’re really interested see http://mathworld.wolfram.com/PrimitivePolynomial.html or google google it. it. O ne important property to note note is that their reciprocals also form primitive pol primitive poly ynomi nomials als (th (that is, is, they they come come in in pairs). pairs). Ex Exampl ample: e: 1 + x3 + x4 is Degree 4, its reciprocal is 1 + x + x4 (10011 and 11001), and both are prim primitiv tive. Taps :
Lines that run from the output of one register within the LFSR into XOR gates that determine input to another register within within the LFSR. LFS R. These are chosen chose n based base d on o n the primiti primitive ve poly po lynomi nomial. al. Type 1 or External External LFSRs : One way of implementing LFSRs; all XOR gates are fed sequentially into one another and end up as the input to the lleas eastt (or most, either is correct) corre ct) si s ignifi gnificant cant bit of the LFSR. Simply Simply put, the XORs XO Rs are external from the shift register. Type 2 or Internal Internal LFSRs : Another LFSR implementation; XOR gates feed into different registers within the LFSR, and are not sequenti seq uential. al. Simply Simply put, the XORs XO Rs are inside inside the shift shift register.
Other tutorials on this subject are confusing because they only address one type of implementation, don’t explain how they got the taps, or they show the implementation of an LFSR and then in a table show the taps corres co rrespo pondin nding g to a different different pri pr imitiv mitivee polyn p olynomi omial al of the same degree. d egree. K eep all of this this in mi mind if you loo look k elsewhere. Consi Co nside derr a simple simple 3-bit 3- bit LFSR. The only only primi primitive tive poly po lynomi nomials als for for degree d egree 3 are 1 + x2 + x3 and 1 + x +
1/15/13
Understanding Linear Feedback Shift Registers – the easy way
x3 (they are reciprocals of each other, 1011 and 1101). Since we have two primitive polynomials, and we have two different implementation strategies, we therefore have four unique ways of implementing the LFSR. In fact, each of these implementations can differ according to which register is the most significant bit (either way will have 2n-1 states, but with different sequences).
A and B illustrate a Type 1 / External LFSR. C and D illustrate a Type 2 / Internal LFSR . A and C illustrate the implementation of 1 + x2 + x3 B and D illustrate the implementation of 1 + x + x3
Since xn and 1 are always present in primitive polynomials, you can think of them as being used as the output of the shift register and the input of the shift register, respectively. For an n-bit LFSR, you need to discover a primitive polynomial associated with it to implement it. Tap tables on the internet will list taps as such: N = 3, Taps at 0, 1, 3 (this corresponds to 1 + x + x 3) This tutorial uses the 0 and 3 as taps because they correspond to the powers of x in the primitive polynomial. Sometimes Tap tables will omit the 0 and 3, since they must be present. Other times, they may use 0 to mean the output of the least significant register (so for N = 3, their taps would be listed as "0, 2" instead of "1, 3"). They usually only list the taps associated with one primitive polynomial, but more than one exists. All of this explains why different tap tables will sometimes show you different numbers!
Here’s another pair of examples, for n = 8 and using the primitive polynomial 1 + x 2 + x3 + x4 + x8:
1/15/13
Understanding Linear Feedback Shift Registers – the easy way
Internal:
External:
Warning! The images above show the Reset line used incorrectly. The registers should be seeded to a nonzero value; all-zeroes is called the lock- up state and will not change. Therefore, at least one register must be
preset . Your choice in seed value determines the order of states, and ultimately the value at the 2n -1 state. Note that it is also possible to design LFSRs to have an all-ones lock-up state instead, but this will not be discussed here for brevity. Special thanks to all those who have pointed out this omission. Here is a good tap table provided by Scott R. Gravenhorst! In this link, the taps listed omit "0." Again, keep in mind that other polynomials do exist. Good luck! Images blatantly stolen from http://www.ee.ualberta.ca/~elliott/ee552/studentAppNotes/1999f/Drivers_Ed/lfsr.html and http://www.edacafe.com/books/ASIC/Book/CH14/CH14.7.php Comments? Contact Dan Healy:
[email protected]