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 bit-error-rate 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 (m-sequences). We also provide tables of m-sequence feedback taps.
Linear feedback shift registers can be implemented in two ways. The Fibonacci implementation consists of a simple shift register in which a modulo-2 sum of the binary-weighted taps is fed back to the input. (The modulo-2 sum of two 1-bit 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 binary-weighted value of the output stage, again using modulo-2 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, modulo-2 addition is performed using exclusive-OR (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 multiple-return shift register generator (MRSRG) or modular shift register generator (MSRG).
A given set of feedback connections can be expressed in a convenient and easy-to-use shorthand form, with the connection numbers being listed within a pair of square brackets. In doing so, connection g0 (defined in Figures 1 and 2) is implied, and not listed, since it is always connected. Although gm 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
[f1, f2, f3, ..., fJ]
where subscript J is the total number of feedback taps (not including g0), f1 = m is the highest-order feedback tap (and the size of the LFSR), and fj represent the remaining feedback taps. The value of each fj is equal to the subscript of the corresponding connection g. Note that the tap numbers fj 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 eight-stage shift register with feedback connections at taps g8, g4, g3, g2, and, as always, at g0.
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 Convention
The 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
[f1, f2, f3, ..., fJ] g
where subscript J is the total number of feedback taps (not including input g0), f1 = m is the highest-order feedback tap (and the size of the LFSR), and fj are the remaining feedback taps. The value of each fj 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
[f1, m-f2, m-f3, ..., m-fJ] 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 g8, g6, g5, g4, and implied g0. The feedback taps are specified as [8, 6, 5, 4]g for the Galois form, and [8, 8-6, 8-5, 8-4]f = [8, 2, 3, 4]f = [8, 4, 3, 2]f for the Fibonacci form.
LFSR 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=2m-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 m-sequence. In certain industries m-sequences are referred to as a pseudonoise (PN) or pseudorandom sequences, due to their optimal noise-like characteristics. (Informally, even non-maximal sequences are often called pseudonoise or pseudorandom sequences.)
Technically speaking, maximal length generators can actually produce two sequences. The first--the trivial one--has 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 one--the useful one--has a length of 2m-1. Together, these two sequences account for all 2m states of an m-bit state register.
When the feedback taps of an LFSR are non-maximal, the length of the generated sequence depends upon the initial state of the LFSR. A non-maximal generator is capable of producing two or more unique sequences (plus the trivial all-zeros 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 non-maximal sequence the generator can produce accounts for all 2m states of an m-bit state register.
Properties of non-maximal sequences are generally inferior to those of maximal sequences. So the use of non-maximal sequences in real systems is usually avoided in favor of their maximal-length counterparts.
Finite (Galois) field mathematics are used to derive m-sequence 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 gi 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 modulo-2:
0 + 0 = 0
0 * 0 = 0
As an example of polynomial representation, the generator polynomial
G(X) = X3 + X1 + 1
represents an LFSR with feedback taps 3 and 1, denoted as [3, 1]:
Now, here is the key to determining m-sequence 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) XN+1, where N = 2m-1 (the length of the m-sequence). 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 m-sequence. First we note that m = 3 and N=23-1=7. It can be shown that its polynomial, X3+X1+1 , cannot be factored, and it can be shown that its polynomial is a factor of X7+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 m-sequences for a given register size.
For example, we may be asked to find all sets of maximal-length feedback taps for an LFSR with m=3 registers. We do this as follows: The length of the m-sequences will be N=23-1=7. We know that the solution lies in all the primitive factors of polynomial X7+1. We use modulo-2 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 m-sequence 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 m-sequence feedback sets. More specifically, given any one of its m-sequence feedback sets,
[f1, f2, f3, ..., fJ]
there will be a companion set described as
[f1, m-f2, m-f3, ..., m-fJ]
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 m-sequence, the mirror image of the feedback set will produce the mirror image of the m-sequence. And, of course, the resulting sequence will also be an m-sequence since all possible states are exhausted. An astute reader may have noticed in the last example that the two derived sets of m-sequence feedback taps, [3, 1] and [3, 2], are in fact mirror images of each other.
Tables of m-sequence feedback taps are presented below for the reader's convenience.
If the reader wishes to determine m-sequence feedback sets not available here, the method described in this section can be used to do so. Howerver, writing a software that performs modulo-2 polynomial factorization using, for example, the famous Berlekamp algorithm will typically not be a trivial task for a non-mathematician. Fortunately there are off-the-shelf 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.
Properties of m-sequences include the following:
1. An m-bit register produces an m-sequence of period 2m-1.
2. An m-sequence contains exactly 2(m-1) ones and 2(m-1)-1 zeros.
3. The modulo-2 sum of an m-sequence and another phase (i.e. time-delayed version) of the same sequence yields yet a third phase of the sequence.
3a. (A corollary of 3.) Each stage of an m-sequence 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 m-sequence for 2m-1 positions, will span every possible m-bit number, except all zeros, once and only once. That is, every state of an m-bit 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 non-equal numbers. Then in any m-sequence there are:
6. If an m-sequence is mapped to an analog time-varying 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/(2m-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 = -(one-bit) to time 0, and then decline linearly from time 0 to time = +(one-bit).
Other interesting facts regarding m-sequences 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 m-sequence.
2. The feedback set for any given m-sequence consists of an even number of taps, never odd (as defined in Figures 1 and 2, including output gm but not including input g0).
tables contain m-sequence 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.