To the beginning

Reed–Solomon codes over field F256/C++

S.I.Khashin


rdso.h     header,
rdso.cpp realization.

Reed–Solomon error correction code. .

To (bufsize-2*NErr) the information bytes are added 2*NErr control.
bufsize must not be greater than 255! Thus, with bufsize = 255, the maximum number of bug fixes is 127.
If the received buffer of size bufsize to be spoiled no more than NErr bytes, then all the errors can be completely repair.
For example, if 235 information bytes to add 20 control, get the size of the encoded buffer is 255:

    c_form(10, 255);

If it spoil any 10 bytes, it will be noticed and corrected.
A greater number of errors you can see, but the fix will not succeed.
In this example, NErr = 10, bufsize = 255.

In module implements three functions:

// Preparing for (de)coding
// Nerr    - the maximal number of errors in buffer
// bufsize - buffer size, <= 255, must be: 2*NErr < bufsize
int c_form ( int NErr, int bufsize );

// The buffer must be a size of bufsize. The first (bufsize-2*NErr) a information for coding.
// After coding, the first 2*NErr bytes are control, the latter is the source information.
void c_code  ( char *buf );

// Decode buf of size (bufsize).
// Returns the number of corrced errors.
// If all errors can not be corrected, returns -1.
// This means that there are more than NErr errors.
int c_decode( char *buf );

Usage example:

char buf[255];
for(int i=0;i<235;i++) buf[i]=i;// fill 235 bytes of information
int NEr = 10;                   // maximal number of errors
c_form(NEr, 255);               // we will correct 10 errors in a buffer of length 255 bytes
                                // 235 informational and 20 control
c_code(buf);                    // Now buf contains 255 code 20 bytes+235 information

for (int i = 0; i < NEr; i++)   // make NEr errors
    buf[3 + 4 * i]++;

int nErr = c_decode(buf);       // Now buf of length 255 contains 235 informational bytes.
                                // The remaining 20 bytes are not used
printf("Nerr = %d\n", nErr);    // Because of the errors we made NErr=10, should be 10.

Remark 1. When coding the control bytes are AT the BEGINNING of the buffer in the positions (0,..2*NErr-1). Behind them are exactly the bytes of the source buffer.

Remark 2. In the limiting case, when NErr = 127 bufsize=255, we obtain in the block length of 255 only 1 information bytes and 254 control. In fact, the encoding in this case is reduced to the repetition of one byte of 255 times.

Speed of encoding and decoding

Encoding speed depends on maksialnoe the number of errors (NErr) almost linearly, at not too large NErr.

The decoding speed of the actual number of errors in a block does not depend on (almost).

At not too large the value of NErr (∼ 40-50) decode time about three times less time coding.

Time (in microseconds) of encoding (Tcod) and decoding (Tdec) of one block of data on the processor Intel(R) Pentium(R) CPU G4500 @3.50GHz according to from the specified maximum number of errors (NErr):

NErr Tcod Tdec   NErr Tcod Tdec   NErr Tcod Tdec   NErr Tcod Tdec
1 1.636 0.540 33 57.938 19.859 65 88.425 38.185 97 88.242 56.793
2 2.607 1.048 34 57.632 20.325 66 88.715 38.902 98 87.967 57.205
3 4.283 1.553 35 59.036 21.000 67 88.348 39.398 99 87.189 57.663
4 5.620 2.070 36 60.669 21.477 68 89.645 40.092 100 87.418 58.136
5 7.671 2.604 37 62.836 22.152 69 89.828 40.611 101 85.968 58.609
6 10.269 3.146 38 63.217 22.747 70 90.958 41.267 102 85.617 59.433
7 12.363 3.716 39 64.865 23.277 71 90.515 41.740 103 85.693 60.150
8 14.446 4.332 40 65.872 23.979 72 91.644 42.145 104 84.839 60.349
9 15.995 4.900 41 67.352 24.429 73 91.324 42.633 105 84.457 61.325
10 17.490 5.438 42 68.024 25.047 74 92.896 43.282 106 84.030 61.752
11 20.000 6.067 43 70.633 25.604 75 91.705 44.029 107 82.977 62.164
12 21.450 6.582 44 70.328 25.955 76 93.262 44.685 108 82.413 62.698
13 23.933 7.479 45 71.640 26.817 77 92.712 45.166 109 80.963 63.705
14 25.848 8.778 46 73.532 27.351 78 92.987 45.746 110 80.368 64.285
15 27.473 9.352 47 73.029 27.954 79 92.926 46.234 111 79.483 64.789
16 30.540 9.993 48 75.165 28.320 80 92.072 46.539 112 78.278 65.384
17 31.883 10.521 49 76.553 29.182 81 92.041 47.333 113 77.225 66.010
18 33.539 11.219 50 76.370 29.648 82 92.987 48.096 114 76.233 66.238
19 35.362 11.806 51 77.881 30.159 83 92.270 48.233 115 75.974 67.169
20 36.179 12.341 52 77.164 30.907 84 92.285 49.179 116 74.432 67.612
21 38.567 12.932 53 78.888 31.441 85 92.255 49.896 117 73.090 67.978
22 39.551 13.588 54 80.200 31.944 86 91.949 50.400 118 72.128 68.451
23 41.565 14.095 55 80.856 32.654 87 92.438 50.919 119 70.206 69.443
24 43.152 14.622 56 81.985 33.157 88 91.644 51.636 120 68.954 69.382
25 44.739 15.320 57 83.328 33.760 89 91.614 51.773 121 67.642 70.053
26 46.249 15.846 58 83.801 34.378 90 92.316 52.567 122 66.666 70.969
27 47.867 16.350 59 85.861 34.874 91 91.522 53.436 123 65.399 71.335
28 49.316 17.033 60 84.625 35.408 92 90.515 53.726 124 63.843 72.266
29 50.262 17.570 61 87.723 35.995 93 90.714 54.306 125 62.332 72.083
30 51.376 18.097 62 85.861 36.499 94 89.691 54.825 126 60.883 73.181
31 52.887 18.723 63 87.524 37.064 95 90.027 55.237 127 60.837 73.166
32 55.908 19.260 64 87.158 37.842 96 89.035 56.274


free counters