
A linear feedback shift register (LFSR) is the heart of any digital system that relies on pseudorandom bit sequences (PRBS), with applications ranging from cryptography and biterrorrate measurements, to wireless communication systems employing spread spectrum or CDMA techniques. In this article we discuss the two implementations of LFSR generators, how to determine feedback taps for generating a maximal length sequence, and the properties of maximal length sequences (msequences). We also provide tables of msequence feedback taps. LFSR Generator ImplementationsLinear feedback shift registers can be implemented in two ways. The Fibonacci implementation consists of a simple shift register in which a modulo2 sum of the binaryweighted taps is fed back to the input. (The modulo2 sum of two 1bit binary numbers yields 0 if the two numbers are identical, and 1 if the differ: 0+0=0, 0+1=1, 1+1=0.)
Figure 1. Fibonacci implementation of LFSR.
The Galois implementation consists of a shift register, the content of which is modified at every step by a binaryweighted value of the output stage, again using modulo2 math.
Figure 2. Galois implementation of LFSR.
Given identical feedback weights, the two LFSR implementations will produce the same sequence. However, the initial states of the two implementations must necessarily be different for the two sequences to have identical phase (that is, zero bit offset relative to each other). The initial state of the Fibonacci form is called the initial fill or initial vector, and this initial fill comprises the first m bits output from the generator. The initial state of the Galois generator must be adjusted appropriately to attain the equivalent output of its first m bits. (In mathematical literature, the initial state of either form is called the seed.) When implemented in hardware, modulo2 addition is performed using exclusiveOR (XOR) gates. The Galois form is generally faster than the Fibonacci in hardware due to the reduced number of logic gates in the feedback loop, thus making it the favored form. It should be noted that, in some industries, the Fibonacci form LFSR is referred to as a simple shift register generator (SSRG), and the Galois form is referred to as a multiplereturn shift register generator (MRSRG) or modular shift register generator (MSRG). Conventions for Feedback Tap SpecificationA given set of feedback connections can be expressed in a convenient and easytouse shorthand form, with the connection numbers being listed within a pair of square brackets. In doing so, connection g_{0} (defined in Figures 1 and 2) is implied, and not listed, since it is always connected. Although g_{m} is also always connected, it is listed in order to convey the shift register size (i.e. the number of registers). Specifically, a set of feedback connections, or taps, is denoted as [f_{1}, f_{2}, f_{3}, ..., f_{J}] where subscript J is the total number of feedback taps (not including g_{0}), f_{1} = m is the highestorder feedback tap (and the size of the LFSR), and f_{j} represent the remaining feedback taps. The value of each f_{j} is equal to the subscript of the corresponding connection g. Note that the tap numbers f_{j} are customarily arranged in descending order from left to right. A set of feedback taps specified in this format is called a feedback tap set, feedback set, or feedback pattern. As an example, the [8, 4, 3, 2] feedback set would signify an eightstage shift register with feedback connections at taps g_{8}, g_{4}, g_{3}, g_{2}, and, as always, at g_{0}. A related convention is that an LFSR with m shift register stages is said to be an Rm LFSR. For example, an R8 generator is one with eight stages. An alternative to this convention is PNm, or PN8 in this example. (PN is an acronym for pseudonoise, which is a term used in some industries for maximal length pseudorandom sequences, which are discussed below.) A Competing ConventionThe reader might be aware that, in other literature or in some circles, it is noted that the tap order must to be reversed when switching between the Fibonacci and Galois forms of LFSR. The reason this isn't the case here in this article is because the tap numbers in the Galois implementation in Figure 2 are reversed from those in Fibonacci implementation in Figure 1. This conveniently takes the reversal into account, and so any given feedback set will produce the same sequence in either implementation. However, if the tap numbers aren't reversed, the feedback sets for the Fibonacci and Galois forms must be made distinguishable from each other. For sake of completeness, we will now describe the feedback set convention for that literature or mindset. (None of the following applies this article.) A set of feedback taps for a Galois generator is denoted as [f_{1}, f_{2}, f_{3}, ..., f_{J}]_{ g} where subscript J is the total number of feedback taps (not including input g_{0}), f_{1} = m is the highestorder feedback tap (and the size of the LFSR), and f_{j} are the remaining feedback taps. The value of each f_{j} is equal to the subscript of the corresponding connection g. The g subscript on the right bracket signifies the Galois LFSR form. The set of feedback taps for the equivalent Fibonacci generator is denoted as [f_{1}, mf_{2}, mf_{3}, ..., mf_{J}]_{ f} where the f subscript on the right bracket signifies the Fibonacci LFSR form. Note that subtracting the feedback tap numbers from m is equivalent to reversing the order of the feedback taps. As an example, consider an LFSR of size m = 8 with feedback connections at g_{8}, g_{6}, g_{5}, g_{4, }and implied g_{0}. The feedback taps are specified as [8, 6, 5, 4]_{g} for the Galois form, and [8, 86, 85, 84]_{f} = [8, 2, 3, 4]_{f} = [8, 4, 3, 2]_{f} for the Fibonacci form. Maximal Length SequencesLFSR generators produce what are called linear recursive sequences (LRS) because all operations are linear. Generally speaking, the length of the sequence before repetition occurs depends upon two factors, the feedback taps and the initial state. An LFSR of any given size m (number of registers) is capable of producing every possible state during the period N=2^{m}1 shifts, but will do so only if proper feedback taps have been chosen. For example, such an an eight stage LFSR will contain every possible combination of ones and zeros after 255 shifts. Such a sequence is called a maximal length sequence, maximal sequence, or less commonly, maximum length sequence. It is often abbreviated as msequence. In certain industries msequences are referred to as a pseudonoise (PN) or pseudorandom sequences, due to their optimal noiselike characteristics. (Informally, even nonmaximal sequences are often called pseudonoise or pseudorandom sequences.) Technically speaking, maximal length generators can actually produce two sequences. The firstthe trivial onehas a length of one, and occurs when the initial state of the generator is set to all zeros. (The generator simply remains in the zero state indefinitely.) The other onethe useful onehas a length of 2^{m}1. Together, these two sequences account for all 2^{m} states of an mbit state register. When the feedback taps of an LFSR are nonmaximal, the length of the generated sequence depends upon the initial state of the LFSR. A nonmaximal generator is capable of producing two or more unique sequences (plus the trivial allzeros one), with the initial state determining which is produced. Each of these sequences is referred to as a state space of the generator. Together, every nonmaximal sequence the generator can produce accounts for all 2^{m} states of an mbit state register. Properties of nonmaximal sequences are generally inferior to those of maximal sequences. So the use of nonmaximal sequences in real systems is usually avoided in favor of their maximallength counterparts. Galois Field Mathematics and MSequencesFinite (Galois) field mathematics are used to derive msequence feedback taps. Any LFSR can be represented as a polynomial of variable X, referred to as the generator polynomial: Equation 1. Generalized generator polynomial. The coefficients g_{i} represent the tap weights, as defined in Figures 1 and 2, and are 1 for taps that are connected (fed back), and 0 otherwise. The order of the polynomial, m, represents the number of LFSR stages. Rules of linear algebra apply to the polynomial, but all mathematical operations are performed in modulo2: Modulo2 addition: 0 + 0 = 0 Modulo2 multiplication: 0 * 0 = 0 As an example of polynomial representation, the generator polynomial G(X) = X^{3} + X^{1} + 1 represents an LFSR with feedback taps 3 and 1, denoted as [3, 1]:
Now, here is the key to determining msequence feedback taps: The generator polynomial of Equation 1 is said to be primitive if it cannot be factored (i.e. it is prime), and if it is a factor of (i.e. can evenly divide) X^{N}+1, where N = 2^{m}1 (the length of the msequence). It can be shown that an LFSR represented by a primitive polynomial will produce a maximal length sequence. Consider again the example of the [3, 1] LFSR just given. We wish to know if this generator will produce an msequence. First we note that m = 3 and N=2^{3}1=7. It can be shown that its polynomial, X^{3}+X^{1}+1 , cannot be factored, and it can be shown that its polynomial is a factor of X^{7}+1. Thus, we conclude that this LFSR will indeed produce a maximal length sequence. In this example, we went through the process of determining whether or not the given set of feedback taps would result in a maximal length sequence. Normally, however, we are required to do just the opposite. That is, we are normally asked to find all sets of feedback taps that will produce msequences for a given register size. For example, we may be asked to find all sets of maximallength feedback taps for an LFSR with m=3 registers. We do this as follows: The length of the msequences will be N=2^{3}1=7. We know that the solution lies in all the primitive factors of polynomial X^{7}+1. We use modulo2 linear algebra (probably with the aid of a computer algorithm) to find the prime factors to be The primitive polynomials are those factors whose order is the same as the register size, m = 3. Of the three prime factors we see here, the last two meet this criterion. Thus we see that there are exactly two sets of msequence feedback taps, [3, 1] and [3, 2]. It is interesting to note that, given any shift register size, there will always be an even number of msequence feedback sets. More specifically, given any one of its msequence feedback sets, [f_{1}, f_{2}, f_{3}, ..., f_{J}] there will be a companion set described as [f_{1}, mf_{2}, mf_{3}, ..., mf_{J}] whose sequence will be the mirror image of the original set's sequence. Note that subtracting feedback tap numbers from m for the companion set is equivalent to reversing the order of those taps. Thus we conclude that, for any given feedback set that produces an msequence, the mirror image of the feedback set will produce the mirror image of the msequence. And, of course, the resulting sequence will also be an msequence since all possible states are exhausted. An astute reader may have noticed in the last example that the two derived sets of msequence feedback taps, [3, 1] and [3, 2], are in fact mirror images of each other. Tables of msequence feedback taps are presented below for the reader's convenience. If the reader wishes to determine msequence feedback sets not available here, the method described in this section can be used to do so. Howerver, writing a software that performs modulo2 polynomial factorization using, for example, the famous Berlekamp algorithm will typically not be a trivial task for a nonmathematician. Fortunately there are offtheshelf solutions available. Maplesoft sells a product called Maple which includes a function called Berlekamp. This will return all primitive polynomial factors of any given polynomial. If you own MatLab or some other popular numerical computing environment, you might be able to find and download a free copy of a factorization script written by another user. MSequence PropertiesProperties of msequences include the following: 1. An mbit register produces an msequence of period 2^{m}1. 2. An msequence contains exactly 2^{(m1)} ones and 2^{(m1)}1 zeros. 3. The modulo2 sum of an msequence and another phase (i.e. timedelayed version) of the same sequence yields yet a third phase of the sequence. 3a. (A corollary of 3.) Each stage of an msequence generator runs through some phase of the sequence. (While this is obvious with a Fibonacci LFSR, it may not be with a Galois LFSR.) 4. A sliding window of length m, passed along an msequence for 2^{m}1 positions, will span every possible mbit number, except all zeros, once and only once. That is, every state of an mbit state register will be encountered, with the exception of all zeros. 5. Define a run of length r to be a sequence of r consecutive identical numbers, bracketed by nonequal numbers. Then in any msequence there are:
6. If an msequence is mapped to an analog timevarying waveform, by mapping each binary zero to 1 and each binary one to +1, then the autocorrelation function for the resulting waveform will be unity for zero delay, and 1/(2^{m}1) for any delay greater that one bit, either positive or negative in time. The shape of the autocorrelation function between 1 bit and +1 bit will be triangular, centered around time 0. That is, the function will rise linearly from time = (onebit) to time 0, and then decline linearly from time 0 to time = +(onebit). Other interesting facts regarding msequences and feedback sets that produce them include the following: 1. If the order of the feedback taps (as defined in Figures 1 and 2) is reversed, the resulting sequence will be the time reversal of the original sequence, and will also be an msequence. 2. The feedback set for any given msequence consists of an even number of taps, never odd (as defined in Figures 1 and 2, including output g_{m} but not including input g_{0}). Tables of MSequence Feedback Taps The following
tables contain msequence feedback sets for LFSR
sizes R3 through R32. The tables for R3 through
R24 contain all maximal feedback sets (except for
mirror image sequences). The tables for R25
through R32 contain maximal feedback sets for 2,
4, and 6 taps only. The last table contains a
sampling of "dense feedback sets"
(those with taps for at least half the stages)
for R25 through R32 registers.




