Encoding information using ReedSolomon codes
ReedSolomon codes are nonbinary, block, and error correcting codes may be used in storing information to avoid damaged data loss. It should be noted, that this approach will not be rational in many cases, but it helps to realize the noiseless coding with a variable percentage of recoverable information.
Using Reed Solomon codes one needs redundancy as doubled size of recovered data. Let me explain with on example: if we have a sequence of 10 characters and want to be able to repair errors in 3eh of them, then we need to store 10 3 * 2 = 16 characters. Variables, that we will use: n = 10, the number of information symbols; t = 3, maximal number of recovered symbols; g = 16, length of the encoded sequence. Thus, the formula can be written as: g = n + t * 2.
While encoding and decoding data, all arithmetic operations are performed in Galois fields. There applied the socalled polynomial arithmetic or Galois field arithmetic. Thus, the result of any operation is also part of this field. Specific Galois field consists of a fixed range of numbers. Galois field is defined by prime number p, which is called characteristic of the field, and positive integer m. The order, or number of elements is the form p^{m}. When m = 1, a field is called prime field. In cases when m>1, to construct the field we need monic irreducible of degree m. GF (p^{m})  the designation of the Galois field.
To work with the digital data is natural to use p = 2 as characteristic of the field. If m = 1 each element of code sequence is a bit, if m = 8  8 bits, ie byte. Actually ReedSolomon codes operate on bytes and are the most common.
Before moving on to the encoding and decoding operations we need todeal with the Galois field arithmetic on example of GF (2^{3}). This field consists of the numbers from 0 to 7.
The simplest is the operation of addition, which is a simple bitwise exclusive disjunction (XOR).
Example:
5+3=110=6
Unfortunately, multiplication is much more difficult to implement, to do it, we need to convert a number in polynomial form.
Example:
5=101=1∙x^{2}+0∙x^{1}+1∙x^{0}=x^{2}+1
As you can see the number in polynomial form is a polynomial whose coefficients are the values of bits in the binary representation of the number.
Multiplication of two numbers in polynomial form:
5∙7=(x^{2}+1)∙(x^{2}+x+1)=x^{4}+x^{3}+x^{2}+x^{2}+x+1=x^{4}+x^{3}+x+1=11011=27
Firstly, it should be noted that even in polynomial form addition is exclusive disjunction, and therefore x^{2}+x^{2}=0 . Secondly, the multiplication result 27 is not included in GF (2^{3}) (it consists of numbers from 0 to 7, as mentioned above). To deal with this problem it is necessary to use the generator polynomial. The generator polynomial is irreducible (by analogy with prime numbers is divisible by 1 and itself). For example we will use generating polynomial: (x)=x^{3}+x+1 .
It is also assumed that x satisfies the equation f(x)=x^{3}+x+1=0 .
The end of multiplication example:
The same result can be obtained as remainder of division of the obtained polynomial by the generator polynomial:
Multiplication table:
Division in polynomial form is quite hard to understand. It's much better to execute division using multiplication table:
Example: 6÷5=7
Exponentiation table of Galois field’s elements is also very impotant. Exponentiation is carried out in polynomial form, similar to multiplication.
Example:
5^{2}=(x^{2}+1)^{2}=x^{4}+x^{2}+x^{2}+1=x^{4}+x^{2}+x+x^{2}+x+1=x∙(x^{3}+x+1)=x^{2}+x+1=111=7
Exponentiation table:
Exponentiation table has cycle: seventh power corresponds to zeroth, then eighth corresponds to first, etc. You may want to check it out.
In Galois fields there exists a primitive element  an element whose powers include all nonzero elements of field. Exponentiation table shows that this condition correspond to all the elements (well, except for one of course). However, this does not always happen, for example, view exponentiation table for GF (16).
For fields we are considering (with characteristic 2) 2 is always chosen as primitive element. Considering his property, any element of field can be expressed as power of primitive member.
Example:
5=2^{6}7=2^{5}
Considering the cycle of exponentiation table, we can try again to multiply number:
5∙7=2^{6}∙2^{5}=2^{6+5}=2^{11}=2^{11 mod 7}=2^{4}=6
We got the same result.
Now we can try division:
6÷5=2^{4}÷2^{6}=2^{46}=2^{2}=2^{(2)mod 7}=2^{5}=7
This result is also matches with previous.
And in conclusion let’s try exponentiation:
5^2=(2^{6})^{2}=2^{6∙2}=2^{12}=2^{12 mod 7}=2^{5}=7
And again result matches.
This approach to multiplication and division is much easier than the real operation with the use of polynomials, and there is no need to store a large multiplication table, but a string of powers of primitive element.
So, before coding we chose GF(q), where q=p^{m}. The length of coding sequence should be q1. Thus, in case of using GF(8) coding sequence consists of 7 elements. Further we should determine which elements would be informational, and which of them would be check (redundant). At the very beginning, we said that the amount of redundant elements should be twice greater than the number of wrong elements, which we want to restore. If we need to correct twofold error (t = 2 – is the error multiplicity), then we should use four check symbols. Let’s apply this to our example: of seven elements there needed four redundant, and therefore three information elements to correct twofold error. The code sequence is as follows:
C=(c_{0}, c_{1}, c_{2}, c_{3}, c_{4}, c_{5}, c_{6}), where c_{0}, c_{1}, c_{2} – informational, c_{3}, c_{4}, c_{5}, c_{6} – redundant.
I want to draw attention to the fact that the correction of double error in the code sequence of the seven elements means that you can deal with error, the probability of which is not more than p_{er} = 2/7 ≈ 0,29. If the probability of mistake is grater, you need to increase the redundancy, otherwise recovery of distorted information will not work.
Let’s encode the sequence С=( 4, 6, 7, 0, 0, 0, 0), the last four elements – redundant and equal to zero.
C in polynomial form:
С(x)=4∙x^{0}+6∙x^{1}+7∙x^{2}+0∙x^{3}+0∙x^{4}+0∙x^{5}+0∙x^{6}=4+6∙x+7∙x^{2}
Formula for encoding: c_{j}'=C(z^{j}) , where z=2 – is a primitive element.
c_{0}'=C(2^{0} )=С(1)=4+6+7=5 c_{1}'=C(2^{1} )=С(2)=4+6∙2+7∙4=4+7+1=2 c_{2}'=C(2^{2} )=С(4)=4+6∙4+7∙6=4+5+4=5 c_{3}'=C(2^{3} )=С(3)=4+6∙3+7∙5=4+1+6=3 c_{4}'=C(2^{4} )=С(6)=4+6∙6+7∙2=4+2+5=3 c_{5}'=C(2^{5} )=С(7)=4+6∙7+7∙3=4+4+2=2 c_{6}'=C(2^{6} )=С(5)=4+6∙5+7∙7=4+3+3=4
We got encoded sequence: C'=(5,2,5,3,3,2,4). In polynomial form: С(x)=5∙x^{0}+2∙x^{1}+5∙x^{2}+3∙x^{3}+3∙x^{4}+2∙x^{5}+4∙x^{6}.
Formula for encoding: c_{j} =C' (z^{j}) .
с_{0}=C'(2^{0} )=C'(1)=5+2+5+3+3+2+4=4 с_{1}=C' (2^{1} )=C' (5)=5+2∙5+5∙7+3∙6+3∙3+2∙4+4∙2=5+1+6+1+5+3+3=6 с_{2}=C' (2^{2} )=C' (7)=⋯=7 с_{3}=C' (2^{3} )=C' (6)=⋯=0 с_{4}=C' (2^{4} )=C' (3)=⋯=0 с_{5}=C' (2^{5} )=C' (4)=⋯=0 с_{6}=C' (2^{6} )=C' (2)=⋯=0
While decoding we got (4, 6, 7, 0, 0, 0, 0), which is equal to original. To check if there are some mistakes it's enough to look at redundant elements. If they are still equal to zero, then there is no errors.
Error is another sequence which is added to the encoded. Assume, that errorvector looks like: f' =(0, 0, 5, 0, 3, 0, 0), then encoded sequence with mistake is:
C_{f}'=C'+f'=(5,2,0,3,0,2,4)
Let’s try to decode the given codeword: C_{f}'=5∙x^{0}+2∙x^{1}+0∙x^{2}+3∙x^{3}+0∙x^{4}+2∙x^{5}+4∙x^{6}=5+2∙x^{1}+3∙x^{3}+2∙x^{5}+4∙x^{6}
c_{0}^{f}=C'(2^{0} )=C'(1)=5+2+0+3+0+2+4=2 c_{0}^{f}=C'(2^{1} )=C'(5)=5+2∙5+3∙6+2∙4+4∙2=5+1+1=5 c_{0}^{f}=C'(2^{2} )=C'(7)=5+2∙7+3∙2+2∙6+4∙4=5+5+6+7+6=7 c_{0}^{f}=C'(2^{3} )=C'(6)=5+2∙6+3∙7+2∙5+4∙3=5+7+2+1+7=6 c_{0}^{f}=C'(2^{4} )=C'(3)=5+2∙3+3∙4+2∙2+4∙6=5+6+7+4+5=5 c_{0}^{f}=C'(2^{5} )=C'(4)=5+2∙4+3∙5+2∙3+4∙7=5+3+4+6+1=5 c_{0}^{f}=C'(2^{6} )=C'(2)=5+2∙2+3∙3+2∙7+4∙5=5+4+5+5+2=3
C_{f}=(2, 5, 7, 6, 5, 5, 3) – decoded sequence. As you can see, the last four elements are not equal to zero, which indicates an error. Firstly it's necessary to determine the position of distorted elements. For this we need to calculate the error location polynomial. His roots indicate positions of errors. In matrix form error location polynomial looks like L=[1, l_{1}, l_{2}, … l_{t}]. As far as in our example t=2, so L=[1, l_{1}, l_{2}].
Last four symbols of encoded sequence:
6

5

5

3

S_{0}

S_{1}

S_{2}

S_{3}

Let’s form a matrix and columnvector, to calculate L. In general case:
For our example:
Calculate M^{1} , considering, that we use Galois field arithmetic:
Just in case we will verify the calculations:
So:
L in polynomial form:
L(x)=1+4x+2x^{2}
Calculate roots with simple search:
L(2^{0} )=L(1)=1+4+2=7 L(2^{1} )=L(2)=1+4∙2+2∙4=1 L(2^{2} )=L(4)=1+4∙4+2∙6=1+6+7=0 L(2^{3} )=L(3)=1+4∙3+2∙5=1+7+1=7 L(2^{4} )=L(6)=1+4∙6+2∙2=1+5+4=0 L(2^{5} )=L(7)=1+4∙7+2∙3=1+1+6=6 L(2^{6} )=L(5)=1+4∙5+2∙7=1+2+5=2
So errors are in positions c_{2}' and c_{4}'.
Now we need to find the correct values. Bring L(x) to normal form:
L(x)=1+4x+2x^{2} *5
L(x)=x^{2}+2x+5
Errorvector looks like this:
?

?

?

6

5

5

3

f_{0}

f_{1}

f_{2}

f_{3}

f_{4}

f_{5}

f_{6}

Create convolution for f_{0}, f_{1}, f_{2}, and calculate them:
So F=(6, 3, 0, 6, 5, 5, 3). Since error was added to encoded sequence we need to encode F:
F(x)=6+3x+6x^{3}+5x^{4}+5x^{5}+3x^{6}
Since we already know positions of errors, it’s enough to calculate only and , all others will be equal to zero. But in order to accurately verify this let's honestly count all values:
f_{0}'=F(2^{0})=F(1)=6+3+6+5+5+3=0 f_{1}'=F(2^{1})=F(2)=6+3∙2+6∙3+5∙6+5∙7+3∙5=6+6+1+3+6+4=0 f_{2}'=F(2^{2})=F(4)=6+3∙4+6∙5+5∙2+5∙3+3∙7=6+7+3+1+4+2=5 f_{3}'=F(2^{3})=F(3)=6+3∙3+6∙4+5∙7+5∙2+3∙6=6+5+5+6+1+1=0 f_{4}'=F(2^{4})=F(6)=6+3∙6+6∙7+5∙4+5∙5+3∙3=6+1+4+2+7+5=3 f_{5}'=F(2^{5})=F(7)=6+3∙7+6∙2+5∙5+5∙6+3∙4=6+2+7+7+3+7=0 f_{6}'=F(2^{6})=F(5)=6+3∙5+6∙6+5∙3+5∙4+3∙2=6+4+2+4+2+6=0
Finally f'=(0, 0, 5, 0, 3, 0, 0). Add errorvector to wrong encoded sequence:
C'=C_{f}'+f'=(5,2,0,3,0,2,4)+(0,0,5,0,3,0,0)=(5,2,5,3,3,2,4)
As result we got correct encoded sequence.
Read on:
