Verilog Implementation of Reed - Solomon Code
Verilog Implementation of Reed - Solomon Code
Using a mathematical formulation, let (x1, x2, ..., xn) be the input sequence of n distinct values
over the finite field F; then the codebook C created from the tuplets of values obtained by
evaluating every polynomial (over F) of degree less than k at each xi is
where F[x] is the polynomial ring over F, and k and n are chosen such that 1 ≤ k ≤ n ≤ N.
As described above, an input sequence (x1, x2, ..., xn) of n=N values is created as
,
where α is a primitive root of F. When omitting 0 from the sequence, and since αN-1 = 1, it
follows that for every polynomial p(x) the function p(αx) is also a polynomial of the same
degree, and its codeword is a cyclic left-shift of the codeword derived from p(x); thus, a
Reed–Solomon code can be viewed as a cyclic code.
1. GALOIS FIELD:
A Finite Field is a field with a finite field order (i.e., number of elements), also called a
Galois field. The order of a finite field is always a prime or a power of a prime . For each
prime power, there exists exactly one finite field GF(pm ).A Field is said to be infinite if it
consists of infinite number of elements, for e.g. Set of real numbers, complex numbers etc.
Finite field on the other hand consist of finite number of elements. GF(pm ) is an extension
field of the ground field GF(p), where m is a positive integer. For p = 2 , GF(2m ) is an
extension field of the ground field GF(2) of two elements (0,l).
GF(2m ) is a vector space of dimension m over GF(2) and hence is represented using a basis
of m linearly independent vectors. The finite field (2m ) GF contains (2m −1) non zero
elements. All finite fields contain a zero element and an element, called a generator or
primitive element α , such that every non-zero element in the field can be expressed as a
power of this element. The existence of this primitive element (of order 2m -1) is asserted by
the fact that the nonzero elements of GF(2m ) form a cyclic group.
.
1.1 PROPERTIES OF GALOIS FIELDS
1. In GF(2m) fields, there is always a primitive element α , such that you can express
every element of GF(2m ). You can generate every field GF(2m ) using a primitive
polynomial over GF(2), and the arithmetic performed in the GF(2m) field is modulo
this primitive polynomial.
2. If α is a primitive element of GF(2m), its conjugate α 2m is also primitive elements of
3. GF(2m ).
4. If α is an element of order n in GF(2m), all its conjugates have the same order n.
5. If α , an element in GF(2m), is a root of a polynomial f(x) over GF(2), then all the
distinct conjugates of α , also elements in GF(2m), are roots of f(x).
6. Every element α of GF (2m) has a unique minimal polynomial over GF (2).
7. The minimal polynomial φ (x), which is also irreducible, of an element α in GF(pm) is
8. Any operation on elements of the field will preserve the closure property. Every
element has an additive and multiplicative inverse (except for ’0’ which has no
multiplicative inverse).
A Galois field GF (2m) with primitive element α is generally represented as (0, 1, α ,α2 ,
2k -2
………. α ). The simplest example of a finite field is the binary field consisting of the
elements (0, 1). Traditionally referred to as GF(2)2 , the operations in this field are defined as
integer addition and multiplication reduced modulo 2. Larger fields can be created by
extending GF(2) into vector space leading to finite fields of size 2m . These are simple
extensions of the base field GF(2) over m dimensions. The field GF(2m) is thus defined as a
field with 2m elements each of which is a binary m-tuple. Using this definition, m bits of
binary data can be grouped and referred to it as an element of GF(2 m). This in turn allows
applying the associated mathematical operations of the field to encode and decode data [10].
Let the primitive polynomial be φ (x), of degree m over GF(2m). Now any ith element of the
field is given by
Hence all the elements of this field can be generated as powers of α . This is the polynomial
representation of the field elements, and also assumes the leading coefficient of φ (x) to be
equal to 1.
1.3 ADDITION/SUBTRACTION:
Generally the field GF (2 m ) represents a set of integers from zero to 2m- 1. Addition and
subtraction of elements of GF(2m) are simple XOR operations of the two operands. Each of
the elements in the GF is first represented as a corresponding polynomial. The addition or
subtraction operation is then represented by the XOR operation of the coefficient of
corresponding polynomials. However since the more complex operations are extensively
used in RS encoding and decoding algorithms, the development of their hardware structures
have received considerable attention. Note that GFA does not distinguish between addition
and subtraction operations; both are considered as XOR operations. Since both operations
follow modulo arithmetic, the result always evaluates to a value within the field.
1.4 MULTIPLICATION
Multiplication operation over the Galois Field is a more complex operation than the
addition/subtraction operation. It is also based on modulo arithmetic.
This partial result, however is not a element of the field GF(2). Hence the highest order term
xh of C (x) has to be reduced using the following property of the irreducible polynomial
p
The substitution starts with the highest order term c2m-2 x2m-2 is used to produce a partial result
Cp of one degree less than Cp :
This shifting operation is continued until Cp(x) is of degree m-1, i.e. it becomes an element of
GF(2m). The result of a GF(2) multiplication is a (2m –1 ) bit word, which represents a degree
(2m– 2) polynomial in extended form. For m=8, the product is represented as follows:
Consider two operands in the GF(28),
The product is a 15-bit word, containing the coefficients of the extended form polynomial
Prod(a). This word contains the coefficients of the extended form polynomial Prod (a). The
extended form polynomial is reduced modulo f(x). This is equivalent to calculating the
remainder from the extended form polynomial divided by f(x). The remainder in this case is a
polynomial of degree 7 with 8 binary coefficients and therefore represents a valid element of
GF(28).
[b(0)+b(1)α+b(2)α2+b(3)α3+b(4)α4+b(5)α5+b(6)α6+b(7)α7]*
[a(0)+a(1)α+a(2)α2+a(3)α3+a(4)α4+a(5)α5+a(6)α6+a(7)α7]=
b(0)*[a(0)+a(1)α+a(2)α2+a(3)α3+a(4)α4+a(5)α5+a(6)α6+a(7)α7]+
b(1) α *[ a(0)+a(1)α+a(2)α2+a(3)α3+a(4)α4+a(5)α5+a(6)α6+a(7)α7]+
α8=1+α2+α3+α4
α9=α2+α3+α4+α5
α10= α2+α4+α5+α6
α11= α3+α5+α6+α7
α12=1+α2+α3+α6+α7
α13=1+α+α2+α7
α14=1+α+α4
2. RS ENCODING
represent the result of multiplication of the data unit with the generator polynomial. One
important property of G(x) is that it exactly divides c (x), assume Q(x) and P(x) to be the
corresponding quotient and remainder, hence the codeword looks like
Here P(x) is the polynomial which represents the check symbols. Dividing by the generator
polynomial and rewriting gives
Q(x) can be identified as ratio and – P(x) as a remainder after division by G(x). The idea is
that by concatenating these parity symbols to the end of data symbols, a codeword is created
which is exactly divisible by g(x). So when the decoder receives the message block, it divides
it with the RS generator polynomial. If the remainder is zero, then no errors are detected, else
indicates the presence of errors.
The lowest degree term in X n−k M(x) is m0 x n-k 0 , while P(x) is of degree at most n-k-1,
it follows that the codeword is given by
and it
consists of the data symbols followed by the parity-check symbols.
2.2 RS ENCODER
As previously mentioned, RS codes are systematic, so for encoding, the information symbols
in the codeword are placed as the higher power coefficients. This requires that information
symbols must be shifted from power level of n-1 down to n-k and the remaining positions
from power n-k-1 to 0 be filled with zeros. Therefore any RS encoder design should
effectively perform the following two operations, namely division and shifting. [28] suggests
that both operations can be easily implemented using Linear-Feedback Shift Registers.The
parity symbols are computed by performing a polynomial division using GF algebra. The
steps involved in this computation are as follows:
1. Multiply the message symbols by Xn-k. This shifts the message symbols to the left to
make space for the n-k parity symbols.
2. Divide the message polynomial by the code generator polynomial using GF algebra.
3. The parity symbols are the remainder of this division. These steps are accomplished in
hardware using a shift register with feedback. The architecture for the encoder is
shown in Figure 1.
The encoder block diagram shows that one input to each multiplier is a constant fieldelement,
which is a coefficient of the polynomial g(x). For a particular block, the information
polynomial M(x) is given into the encoder symbol by symbol. These symbols appear at the
output of the encoder after a desired latency, where control logic feeds it back through an
adder to produce the related parity. This process continues until all of the k symbols of M(x)
are input to the encoder. During this time, the control logic at the output enables only the
input data path, while keeping the parity path disabled. With an output latency of about one
clock cycle, the encoder outputs the last information symbol at (k+1)th clock pulse. Also,
during the first k clock cycles, the feedback control logic feeds the adder output to the bus.
After the last symbol has been input into the encoder (at the kth clock pulse), a wait period of
at least n-k clock cycles occurs. During this waiting time, the feedback control logic disables.
Feedback
Gate
g0 g1 g2 g2t-1
b b
b0 b1 2t-2 2t-1
Input symbols
Select Input or
Parity symbols
b
2t-2
The encoder block diagram shows that one input to each multiplier is a constant field
element, which is a coefficient of the polynomial g(x). For a particular block, the information
polynomial M(x) is given into the encoder symbol by symbol. These symbols appear at the
output of the encoder after a desired latency, where control logic feeds it back through an
adder to produce the related parity. This process continues until all of the k symbols of M(x)
are input to the encoder. During this time, the control logic at the output enables only the
input data path, while keeping the parity path disabled. With an output latency of about one
clock cycle, the encoder outputs the last information symbol at (k+1)th clock pulse. Also,
during the first k clock cycles, the feedback control logic feeds the adder output to the bus.
After the last symbol has been input into the encoder (at the kth clock pulse), a wait period of
at least n-k clock cycles occurs. During this waiting time, the feedback control logic disables
the adder output from being fed back and supplies a constant zero symbol to the bus. Also,
the output control logic disables the input data path and allows the encoder to output the
parity symbols (k+2th to n+1th clock pulse). Hence, a new block can be started at the n+1th
clock pulse [28].
2.3 Properties
The Reed-Solomon code is a [n, k, n-k+1] code; in other words, it is a linear block code of
length n (over F) with dimension k and minimum Hamming distance n-k+1. The Reed-
Solomon code is optimal in the sense that the minimum distance has the maximum value
possible for a linear code of size (n,k); this is known as the Singleton bound. Such a code is
also called a maximum distance separable code.
For practical uses of Reed–Solomon codes, it is common to use a finite field F with 2m
elements. In this case, each symbol can be represented as an m-bit value. The sender sends
the data points as encoded blocks, and the number of symbols in the encoded block is n = 2m
− 1. Thus a Reed–Solomon code operating on 8-bit symbols has n = 28 − 1 = 255 symbols per
block. (This is a very popular value because of the prevalence of byte-oriented computer
systems.) The number k, with k < n, of data symbols in the block is a design parameter. A
commonly used code encodes k = 239 eight-bit data symbols plus 16 eight-bit parity symbols
in an n = 255-symbol block; this is denoted as a (n,k) = (255,239) code, and is capable of
correcting up to 8 symbol errors per block.
The Reed–Solomon code, like the convolutional code, is a transparent code. This means that
if the channel symbols have been inverted somewhere along the line, the decoders will still
operate. The result will be the inversion of the original data. However, the Reed–Solomon
code loses its transparency when the code is shortened. The "missing" bits in a shortened
code need to be filled by either zeros or ones, depending on whether the data is
complemented or not. (To put it another way, if the symbols are inverted, then the zero-fill
needs to be inverted to a one-fill.) For this reason it is mandatory that the sense of the data
(i.e., true or complemented) be resolved before Reed–Solomon decoding.
3. Simuation results:
1.inputs:
Generation polynomial:
gin6=8'h8E; gin7=8'hCD;
gin8=8'hFA; gin9=8'hEE;
gin10=8'hFF; gin11=8'h0C;
gin14=8'h35; gin15=8'h89;
datain
datain = 8'hF0;
datain = 8'h82;
datain = 8'hEE;
datain = 8'h71;
datain = 8'h04;
datain = 8'h24;
datain = 8'h9A;
datain = 8'hEA;
datain = 8'h6E;
datain = 8'hEF;
datain = 8'hDD;
datain = 8'hF0;
datain = 8'hAC;
datain = 8'h1C;
q15=E4
q14=9A
q13=AB
q12=86
q11=05
q10=D5
q9=D0
q8=E5
q7=E1
q6=3D
q5=F7
q4=06
q3=2C
q2=0D
q1=D7
q0=62
RTL schematic:
Timing Summary:
Minimum period: 5.933ns
Maximum Frequency: 168.554 MHz
Minimum input arrival time before clock: 6.985ns
Maximum output required time after clock: 4.782ns