Home Blog Articles Conference Portfolio Flash-point RSS RU EN

# Volodymyr Bondarenko

Web Technology Expert
RECENT POSTS
 Writing program for cleaning the crowded C: drive on Python Encoding information using Reed-Solomon codes What is the differents between Apache Cordova and PhoneGap? Updated map of subway and trains of Berlin - 02.09.2013 TAG CLOUD
CONTACT
COUNTER

## Encoding information using Reed-Solomon codes Reed-Solomon codes are non-binary, 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 so-called 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 pm. 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 (pm) - 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 Reed-Solomon 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 (23). 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∙x2+0∙x1+1∙x0=x2+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=(x2+1)∙(x2+x+1)=x4+x3+x2+x2+x+1=x4+x3+x+1=11011=27

Firstly, it should be noted that even in polynomial form addition is exclusive disjunction, and therefore x2+x2=0 . Secondly, the multiplication result 27 is not included in GF (23) (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)=x3+x+1 .

It is also assumed that x satisfies the equation f(x)=x3+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:

52=(x2+1)2=x4+x2+x2+1=x4+x2+x+x2+x+1=x∙(x3+x+1)=x2+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 non-zero 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=26
7=25

Considering the cycle of exponentiation table, we can try again to multiply number:

5∙7=26∙25=26+5=211=211 mod 7=24=6

We got the same result.

Now we can try division:

6÷5=24÷26=24-6=2-2=2(-2)mod 7=25=7

This result is also matches with previous.

And in conclusion let’s try exponentiation:

5^2=(26)2=26∙2=212=212 mod 7=25=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=pm. The length of coding sequence should be q-1. 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=(c0, c1, c2, c3, c4, c5, c6), where c0, c1, c2 – informational, c3, c4, c5, c6 – 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 per = 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∙x0+6∙x1+7∙x2+0∙x3+0∙x4+0∙x5+0∙x6=4+6∙x+7∙x2

Formula for encoding: cj'=C(zj) , where z=2 – is a primitive element.

c0'=C(20 )=С(1)=4+6+7=5
c1'=C(21 )=С(2)=4+6∙2+7∙4=4+7+1=2
c2'=C(22 )=С(4)=4+6∙4+7∙6=4+5+4=5
c3'=C(23 )=С(3)=4+6∙3+7∙5=4+1+6=3
c4'=C(24 )=С(6)=4+6∙6+7∙2=4+2+5=3
c5'=C(25 )=С(7)=4+6∙7+7∙3=4+4+2=2
c6'=C(26 )=С(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∙x0+2∙x1+5∙x2+3∙x3+3∙x4+2∙x5+4∙x6

Formula for encoding: cj =C' (z-j) .

с0=C'(20 )=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 error-vector looks like: f' =(0, 0, 5, 0, 3, 0, 0), then encoded sequence with mistake is:

Cf'=C'+f'=(5,2,0,3,0,2,4)

Let’s try to decode the given codeword: Cf'=5∙x0+2∙x1+0∙x2+3∙x3+0∙x4+2∙x5+4∙x6=5+2∙x1+3∙x3+2∙x5+4∙x6

c0f=C'(20 )=C'(1)=5+2+0+3+0+2+4=2
c0f=C'(2-1 )=C'(5)=5+2∙5+3∙6+2∙4+4∙2=5+1+1=5
c0f=C'(2-2 )=C'(7)=5+2∙7+3∙2+2∙6+4∙4=5+5+6+7+6=7
c0f=C'(2-3 )=C'(6)=5+2∙6+3∙7+2∙5+4∙3=5+7+2+1+7=6
c0f=C'(2-4 )=C'(3)=5+2∙3+3∙4+2∙2+4∙6=5+6+7+4+5=5
c0f=C'(2-5 )=C'(4)=5+2∙4+3∙5+2∙3+4∙7=5+3+4+6+1=5
c0f=C'(2-6 )=C'(2)=5+2∙2+3∙3+2∙7+4∙5=5+4+5+5+2=3

Cf=(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, l1, l2, … lt]. As far as in our example t=2, so L=[1, l1, l2].

Last four symbols of encoded sequence:

 6 5 5 3 S0 S1 S2 S3

Let’s form a matrix and column-vector, 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+2x2

Calculate roots with simple search:

L(20 )=L(1)=1+4+2=7
L(21 )=L(2)=1+4∙2+2∙4=1
L(22 )=L(4)=1+4∙4+2∙6=1+6+7=0
L(23 )=L(3)=1+4∙3+2∙5=1+7+1=7
L(24 )=L(6)=1+4∙6+2∙2=1+5+4=0
L(25 )=L(7)=1+4∙7+2∙3=1+1+6=6
L(26 )=L(5)=1+4∙5+2∙7=1+2+5=2

So errors are in positions c2'  and c4'.

Now we need to find the correct values. Bring L(x) to normal form:

L(x)=1+4x+2x2 |*5

L(x)=x2+2x+5

Error-vector looks like this:

 ? ? ? 6 5 5 3 f0 f1 f2 f3 f4 f5 f6

Create convolution for f0, f1, f2, 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+6x3+5x4+5x5+3x6

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:

f0'=F(20)=F(1)=6+3+6+5+5+3=0
f1'=F(21)=F(2)=6+3∙2+6∙3+5∙6+5∙7+3∙5=6+6+1+3+6+4=0
f2'=F(22)=F(4)=6+3∙4+6∙5+5∙2+5∙3+3∙7=6+7+3+1+4+2=5
f3'=F(23)=F(3)=6+3∙3+6∙4+5∙7+5∙2+3∙6=6+5+5+6+1+1=0
f4'=F(24)=F(6)=6+3∙6+6∙7+5∙4+5∙5+3∙3=6+1+4+2+7+5=3
f5'=F(25)=F(7)=6+3∙7+6∙2+5∙5+5∙6+3∙4=6+2+7+7+3+7=0
f6'=F(26)=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 error-vector to wrong encoded sequence:

C'=Cf'+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.

 Tags:  кодирование Name: Mail (hide): Site: Text:          