C++ Class Libraries For Error Control Codes: Purdue E-Pubs
C++ Class Libraries For Error Control Codes: Purdue E-Pubs
Purdue e-Pubs
ECE Technical Reports Electrical and Computer Engineering
8-1-1994
Okan K. Ersoy
Purdue University School of Electrical Engineering
Nazari, Jamshid and Ersoy, Okan K., "C++ Class Libraries for Error Control Codes" (1994). ECE Technical Reports. Paper 195.
http://docs.lib.purdue.edu/ecetr/195
This document has been made available through Purdue e-Pubs, a service of the Purdue University Libraries. Please contact epubs@purdue.edu for
additional information.
TR-EE 94-26
AUGUST 1994
C++ Class Libraries for Error Control Codes*
Jamshid Nazarit
Okan K . Ersoy
Purdue U ~ ~ ~ i v e ~ - s i t y
West Lafayette, IN 47907
Abstract
A tutorial o n error control code is given and encoding and decoding using finite field
transfi~rnisare outlined. Several C++ class libraries are then designed to implement
some of the concepts in error cont,rol codes. A high level description of these libraries
are given and several programs that. uses these libraries are presented. RS and BCH
codes can be generated by these libraries from primitive polynomials where the user
specifies the code size a.nd number of errors t o be corrected. Using these libraries power
progra.ins in error co~lt~rol
codes can be writtnenlinless tllan few pages.
'This researcl~was sponserd by APPCOM Inc, West. Li~fayette,I N 4790fj. T h e programs and C++
libraries discussed in this paper can be ohtailled by an allon!rnlolis user fro111 cn.ecn.p~rrdue.eo'u
from pub
directory. T h e name o i files are C++ECC.README and C++EC'C.tnr..Z.
'Received 1'h.D. in Electrical Eiigiileeri~lg,from P u r d l ~ eUl~iversibv011 M a y 1991.
1 Introduction
Error control codes are widely used in digital commuilication and storage systems. The
purpose of error control coding is to add redulldancy to trailsmitted or stored data. This
provides the means for detecting and correcting errors that occur in a real systern.
Section 2 gives a brief description of a digital colnmullicatio~lsystem. Section 3 gives
a brief desci-iption of algebra used in the design of encoders and decoders. In this section,
the finite or Galois fields are explained and their properties examined.
Section 4 gives a brief description of several topics in error control coding [2, '3, 61. The
aim of this section is to familiarize ourself with the terminologies, which are used in later
sections of this paper. Encoding and Decoding techniques, which use finite field transforms
[I],are described in Section 5.
Section 6 describes C++ class libraries for error control codes. Using these classes we
can generate RS and BCH codes where the user specifies code size and llu~nberof errors to
be corrected. These classes are used to implement several programs in error control codes.
Section 7 gives the concludiilg remarks for this chapter.
the figure, the digita.1 source is producing streams of bits which need to be transmitted to
the receiving end. The information bits are first grouped into k bits. This is shovin as the
vector u in ,;he figure. The encoder takes these k bits, a.dds several reclunda.nt bits and
produces the vector v of size n bits. Here the vector v is referred to a.s a code word. The
redundant b..ts, which axe a.dded to each information vector u, are referred to as parity
bits. The number of parity bits is n. - k. The number of parity bits deterniines how many
errors can be corrected. The higher the number of pa.rity bits, the more error bits which
can be corrected success full^. However the ra.te of actual information tra.nsmitted decrea.ses
because we 1-lave to pa.ss more bits a.cross the cha.nne1. Because of the -'noise", as data is
passed through the cha.nne1, the received da.ta, vector r will not Ile the sa.me a.s the vector
v. The decoder uses redundant illformation in r to detect errors and correct tE.em. After
stripping the parity bits the corrected d a t a is passed t o the receiving end.
1. C1osu:re property. If two elements are picked from a set and the binary operation * is
applied then the result will be in the set.
2. Associative property. Any three elements a , b and c in the set satisfy the condition
3. Set ha,s an identity element e. For any element n in the set, we ha.ve the cc~ndition
4. Each element in the set has a,n inverse. i.e. (L and (L' a.re elements in the set and we
have the condition
1
n t a = aI t a = e
From t h e definition, a field must contain at least two elements the additive identity 0 and
multiplicative identity 1. T h e number of elements in the field is called the order of the field.
A field which has a finite number of elements is called a finite field. Finite fields are also
known as C'alois fields. Finite field which has q elements will be denoted by Gj?(q). The
additive inverse of a field element n is denoted by - a. The multiplicative inverse of a field
element b is denoted by b-' .
T h e set F={0,1) is a G F ( 2 ) if the addition and the multiplication operatior~son field
elements 0 .and 1 are the illodulo-2 addition and Modulo-:! multiplication. Table 1 shows
Modulo-2 addition and multiplication on the field elements. In GF(2), 1 + 1 = Cl implying
1. l f l . l + l f l , . . . . l + l + l + . . .
must be fie:.d elements and a.t some time one of the sums must be zero. Similarly the set of
non-zero elements a.re closet1 under multiplicatiou a.nd the sequence
a , an, a a a , . . ., a n n n
must repeat a t one point. The smallest positive integer r1 such that a n = 1 is called the
order of the field element a . If order of a field elenlent is q - 1 then this element is it primitive
element of field GF(q). From the definition of order of a field element, the products of a
primitive element will produce all non-zero field elements.
Theorem 3.1 For any nonzero field element n in GF(q), we have n9-' = 1.
SO we have 09-' = 1.
Proof: Let us assume the order of a nonzero field element is 12 and it does not divide q - 1,
1.e.
q - 1 = n,nz + T O<r<?z
Proof: Let us a.ssnine it is not. i.e. X = r s a.nd r and s smallel. t11a.n A. Since I::=,1 and
zg=,1 are lield elements, their product is a field element. Using distributive property we
11ave T 3 T 3
C'Cl=Cl=O
1=1 j=l k= 1
Therefore one of tlie sums Cr=,1 or Cg=,1 must be zero. But this is not possible because
we chose X to be the smallest positive numbel- such that C>=,1 = 0. So the characteristic
of a Galois field is a. prime number.
3.4 Polymomials Over GF(q)
A polynomial over G F ( q ) is a polynomial which 11a.s coefficients from field elements. For
example in GF(2) the polynomia.1
will have coefficients which are 0 or 1. If an-1 = 1 then the degree of the polynomial is
n - 1. A field element b is a root of the polynomial f ( X ) , if f(D) = 0. In this case (X - b)
is said to divide f ( X ) . A polynomiad of degree m is said to be irreducible over C;F(q) if it
is not divisi'3le by any polynomials over GF(q) of degree less than m but greater than 0.
We will be dealing with a special type of irreducible polynomial known as primitive
polynomial :in GF(2). Any irreducible polynomial over GF(2) divides the polynomial X n - 1
where n = :!m - 1. -4ny irreducible polynomial p ( X ) of degree in is said to be a primitive
polynomial if the smallest positive integer n for which p(-Y) divides X n - 1 is n == 2m - 1.
Since Xzand p ( X ) are rela.tively prime then r.;(-X-)is not zero a.nd its degree is m - 1 or
less. Now, we will show that ?;(-I-) is not equal to rj(,X-). Assume they a.re same and we
draw a contiadiction. Let us assume j > i
+
Since p(-Y) and -Yi are rela.tively priine then p ( _ ' i ) must divide 1 dyj-i. This is a contra-
diction, because p ( X ) is primitive polynomial and divides S n- 1 where lz = 2" - 1. Here
j - i < n. Zach cy5s shown to be represeilted by a polynomial of degree nz - 1 or less and
since these polyllomials a.re unique the cyi elements a.re unique.
Addition between two elements of the set F is closed. Two polynolnials when added
will produce another polynomial of degree m - 1 or less. Therefore addition will produce
an element which it is in the set. The multiplicatio~lbetween two elements is also closed.
Additive inverse of each element is itself. And multiplicative inverse of a iloilzero element
f f i is f f 2 m - l - i
. So we have shown that GF(2m) is a Galois field. In most cases we will be
using this extended field.
In this section we want to show how each element of G F ( ' ~ is ~ )represented by a ~~olynomial
+ +
of degree 2 or less. We will use the primitive polynomial p(X) = .ri3 .Y 1 wit11 the
condition p ~ ~= +
a )0. Since p ( a ) = 0 we have ( r 3 = a 1. a4,a 5 and n6 are represented as
follows:
(r-1=,.ff3=ff(ff + I ) = , ? + ,
Proof: Let $(X)to be the minimal polynomial of P. Assume it is not irreducible. So choose
$ ( X ) = a ( X ) b ( X ) ,with degree of a ( X ) and b ( X ) to be less than the degree of + ( X ) .
Since +(P) = 0, a(P) or b(P) must be zero. This is a contradiction because th.e minimal
polynomial is chosen to be the smallest degree polynomial which has P as its roots. And
here we find out that there is a lower degree polynomial a ( X ) or B ( X ) which has P as its
roots. So the minimal polynomial of a field element is irreducible. II
The conjugates of a field element P is the elements
where P q e == p. It can be shown that if a field element P is a root of a polynomial then the
conjugates of are also the roots of the same polynomial. I11 fact a minimal polynomial of
field element P can be constructed using the following formula:
JI(a4) = a12 + a 4 + 1
= cr5+a4+1
+ + + ( a + cr) + 1
= ( a 2 cr 1 ) 2
= 0
We used the reduction that a' = 1. Note that the roots are conjugates.
Syndrome decoding.
Guarantees on error detection and correction.
Note that the vector v is just a linear combillation of rows of the matrix G . Vector v
contains the k information bits and n - k parity bits. If these two segments are not mixed
then t h e generator matrix G produces a systematic block code. The k information bits can
easily be extracted from a code word generated from a systematic block code. Therefore
systematic block codes are usually desired. To obtain a systematic block code, the generator
matrix should contain a k x k identity matrix.
4.3 Parity Check Matrix
We can corne up with another matrix H which is made of n - k independent row vectors
such that each of the row vectors is orthogonal to the rows of the generator mat.rix G, i.e.,
T h e H matrix constructed this way is referred to as the parity check naatn'x. Since a code
word v is made of a linear combination of the rows of the G matrix then v . H T = 0.
Theorem 4.1 T h e minimum distance, dm;,, of a linear block code is equal to minimum
weight, w,;,, of a nonzero code word.
Proof:
A bit 0 or 1 sent through a channel is erased if the receiver cannot make the decision
whether it 1s 0 or 1. In this case The receiver produces erasure bits denoted by '?'. A
BSC is a binary symmetric erasure channel (BSEC) if the receiver produces erasures. T h e
probabilities of BSEC is as follows:
4.11 Nearest-Neighbor D e c o d i n g R u l e
We first give a geometric representcction of a block code and then define the nearest-neighbor
decoding rule. Ea.ch code word is put in the center of a sphere .Sof radius t . We will have
qk of these :;pheres. Also let each sphere S conta.in the n-tuples which have distances t or
less from the code word which is in the center of the sphere. These n,-tuples-will not be
code words because the minimum distance between any two code words is assumed to be
+
2t 1. If a.11 the possible n,-tuples don't lie outsitle ally of the spheres then we have a perfect
code. This definition is similar to the definition given before.
A received vector may fa.11 inside any of the q%pl~eres. In \vhich case the code word in
the center 01' the sphere is the tra.nsmitted vector. If the decoder ca.lcula.tes a.11 the distances
between the received vector and each of the code words a.nd chooses the code word which
results in the smallest dista.nce, it is said to use the neccrest-neighbor decoding rtile. This is
also known ,AS the maxin2trin-likelihood decoding.
Proof: Let us assume the received vector r is a code word v. but the decoder assigns it to
another code word w, i.e.. decoding error happens. We ha.ve
P r o b ( r ) is independent of the decoding rule so to rniniinize P r o b ( E ) is to minimize Prob(E1r).
This can b e accomplisl~edby maximizing the probability of correct decoding Prob(w = v J r )
(or just Prob(vlr)). Using Bayes rule. we have
Assuming a11 the code words are equally likely we need to masilnize Prob(rlv). For discrete
memoryles:; channel
n.
therefore we have
log Prob(r1v) = + ( n - d(r, v)) . log(1 - p )
d ( r , v) - log 11
d ( r , v) . log -+ n - l o g ( l - 11)
log Prob(r1v) = 1)
p- 1
The second term in the right hand side is independent of the decoding rule. So if p < 1/2
then log(p/(p - 1 ) ) is negative, therefore, to maximize Prob(r1v) is to minim~zed(r,v).
So we have shown that if we use the nearest-neighbor decoding rule. i.e., calculating the
distance between the received word and all other code words ancl picking the code word
which has the smallest distance, then the probal)ility of decoding error is minimized. 0
4.13 Probability o f E r r o i l e o u s D e c o d i n g
The decoder is gua.ranteed to correct t or less errors but is ca.pa.bleof correcting more errors.
For a binary symmetric channel with the transition probability 11. the probability that the
decoder commits a.n erroneous decoding is upper l~oundedby
4.14 A Eirief Descriptioil of Cyclic Codes
One cyclic shift of an n-tuple
The ith cyclic shift of the vector v produces the vector v'. In a linear block code, if every
cyclic shift of a code vector produces another code vector then the block code i:s called a
cyclic code.
T h e components of a vector v maybe used as coefficients of a polynomial v ( X ) of degree
n - 1, i.e.,
+
v ( X ) = vo v l X + u 2 X 2 + . . - + V , - ~ - Y ~ - ~
Vector v ( X ) is referred to as a code ~~olynominl.
Similarly vector u inaybe represented by a
message polpomicrl u ( X ) of degree k - 1. It call be shown that
v i = .Yiv ( X ) mod ( X n - 1)
and also for any (12, k) cyclic code there exist a polynomial g(.Y) of degree .n - k,
Syndrome p~3lynomialis the remainder of the division of the received code polynomial
by g ( X ) . If the syndrome polynomial is not zero then error must have occurred. Error
correction can be done by using !LIeggitt decoder or variations of Meggitt decoding called
error-trapping decoding.
Where $;(X) is the minimal polynomia.1 of pi. Since the degree of ea,ch polynomial is m or
less then n -. k 5 mt. We should n~entionthat BCH codes are defined for 112 2 :3.
If the field element /3 is a primitive element then we obtain a primitive t-error-correcting
BCH code and ea.ch code word will have n = qm - 1 bits. If the field element 9 is not the
primitive el.ement then we ol)ta.in a non-primitive t-error-correcting BCII code where each
code word has n # qn2 - 1 bits.
Roots cf each code polynoillial obtained from the generator polynomial are P , . . . , P2t
and their conjugates. Therefore the the minimum distance! &,,, of the code is greater than
+
or equal 2t 1.
Since the vector g(X) is a factor of any valid code word. The code word eva.lu;ited a t the
roots of g(X) should give value of 0. The syndrome S; of a received vector r[X) is obtained
by evaluating r(Pi). If syndrome values are zero no errors have occurred. Berlekamp-
Massey algorithm maybe used to find error location polynomial. The roots or the error
location polynomial is used to give the location of the errors. For the binary case there
is no need to find the error values. However, for non-binary case Forney algorithm maybe
used t o find the error values.
The degree of g(,Y) is n - k = 2t. The size of each code word is the order of the element P.
If p is a primitive element then we obtain the primitive R,S code a,nd ea,ch code word has
length n = q - 1.
a Transform e~lcodi~lg
method is explained.
Where element ,B is an element of GF(qm) and has order 12. From Theorem 3.2 7% divides
q m - 1. The:refore Finite field transform of any size vector is not possible. Inder: i and j
are called time and frequency respectively. The vectors v and V are called time-domain
function and frequency-domain function. The vectors v and V are also known as signal and
spectrum res:pectively.
Theorem 5.1 The polynomia.1 v(_Y) has a zero a t if and only if the j t h frequency
component V; equals zero.
Proof: We have v ( p j ) = 0
n-l
Therefore, 4 = 0. a
Similarly it can be shown that the polynomial V ( X ) has a zero at a-' if and only if the
ith time component v; equals zero.
Equation 3 is used to convert a.n n-tuple vector v from G F ( q ) into a.n n-tuple transform
vector V in G F(qm).if we take a.n arbitrary spectrum vector V and ta.ke its inverse finite
field transform using Equaiion 4 we may get a signal vector v which is not in GF(q).
This problem can be asvoided if the following equations known as corzjuyncy constr6:ints are
satisfied:
vg
= V j q modn j = o>. . . , 7 2 - 1
T h e co~nponentsof the vector V are Vo, Vl, . . ., Vn-l. To meet the conji~gacycon-
straint, a value selected for any frequency components fixes the values of other frequency
component!;. For example for q = 2, it = 15, any valid value for V3 gives
T h e frequency components V6, V9 and Vlz are not arbitrary and can be obtained in terms
of V3.
To meel; the conjugacy constraints, we may divide the indices 0 , . . ., n - 1 into several
classes where the frequency components in each class is related to each other. These classes
are referred t o as the conjugacy classes. T h e conjugacy class for index j denoted by Aj is
where mj ir; the smallest positive integer which satisfies the equation
j . qml mod n = j
3. Use i~lformatioilsymbols in GF(qm)to specify the va.lues for the free spectral compo-
nent:.
4. Use conjugacy constraint equations to calculate the values of other dependent spectral
components.
5. Take the inverse finite field transform of the resulting frequency function t o obtain an
encoded time-domain code word.
In some codes, such as Reed-Solomon codes, the time and spectral domains are the
same. In these codes, ta.king the inverse transform of any spectrum will result in a valid
time-domain code word. Therefore. the conjuga.cy constrains on these codes isre already
met.
The above transform encoding steps are clarified further by giving several examples
which are given next.
2. Conj-lgacy constraints are already met, because the time and spectruln domains are
the same. T h e spectral components Ifo, and If6 are "free" and there are no "de-
pendent" spectra.1 components.
3. Pick any field element from GF(8) for each of the three free va.ria.bles.
4. We don't do anything in this step. There a.re no dependent spectra.1 components.
5 . We u,je Equation 4 t o obtain the inverse finite field transform of the resulting frequency
function. As an esample, let us find the time componeilt us for specifi'c values of
Ifo = a 2 , V5 = a6 and If6 = a. We have
6 ..
v, = 1 -p-.l.v,
7 mod 2 1=0
T h e number of information symbols, b = 3. T h e encoding in this esample produces a (7,3)
non-binary RS code. If we represent each element of GF(8) by 3 binary bits then we obtain
a (21,9) binary code.
Ezample 2: In this example, the time domain is in GF(2) and the spectrum domain is
in GF(8). 'We are interested in obtaining a code which can correct 1 error, so t = 1. We
also use the primitive field element a , so our n = 7. The steps of the transform encoding is
as follows:
1. v1 = v2 = 0
2. To meet the conjugacy constraints, we determine the conjugacy classes which are:
The "free" variables are \lo and 115. However we must meet tlle condition Vo2 = Vo.
The "dependent" varia.bles are I/,, V5, and V6.
3. From GF(8) the elements 0, 1 are the only elements that satisfy the collstraint V: =
Vo. Pick 0 or 1 for Vo. T h e equivalent "bit content" of Vo is 1 bit. Select to be any
field element from GF(8). Tlle equivalent "bit content" of 13 is 3 binary bits. So we
shoulcl expect to get a ( 7 , 4 ) code.
4. The dependent values are V4 = V22, V6 = \/32 and V5 = 1/62 and then Since Vl = V2 = 0,
we have V4 = 0.
5. We use Equation 4 and Table 3 to obtain the inverse finite field transform of the
resulting frequency function. Let us find the time domain component v3 f'or specific
values of Ifo = 1 and \I3 = a6. First we 1la.ve V6 = = Q .5 and = I/i2 = a3 and
then
Note that e.sc11 v; will be a value from GF(2). This example produces a j 7 , 4 ) binary code
which is capable of correcting up to 1 error.
First we want to detect to see if any errors have occurred, if no errors have occurred then
we are done and the received vector is a valid code word. If errors have occurred then we
want to find the location of the errors and the error values in those locations. So our goal is
find the error vector e which when subtracted from the received vector r will produce the
desired code word v.
We are ~nterestedin decoding BCH codes. In BCH codes, the field elements P' for
i = 1, . . . , 2 t are the roots of a valid code word. Or from Theorem 5.1, the finite field
transform a-a valid code word will contaill zeros a t locations 1 through 2t. Therefore, we
define the tr-ansforrn decotliny me thoti as follows:
1. Find the finite field tra.nsform of the received vector r, and denote it by the vector R.
3. Set E j = R j for j = 1 , . . . ,26. These 2t va.lues are referred to as the syndrome values.
T h e remaining n - 2t error spectrum components are determined recursively via a
method known as the recursive exte,nsion of the error spectrum which is explained
later in this section.
4. Take the inverse tra,nsform of the vector E , to obtain the time-tlorna.in vector e.
Subtract the vector e from the vector r to obta.in the desired. code word v.
Another wajr to do the last step, is to subtract the error spectrum vector E from the received
spectrum vector R to obtaln the desired spectrum code vector V. The inverse fiilite field
transform of' the vector V will produce the desired code word in the time-domain.
Where 11; a1e the coefficients of the e,rror locato,r polynomial !2(X),i.e..
This equatic~nis defined so that if we find the roots of this equa.tion and find the inverse of
each root wt? obta.in the 1oca.tion of each error.
We have a set of n equations in 7. The number of unknowns in the error spectrum is
n - 2t and the number of unknowns in the error locator polynomial IZ(X) is u. So there are
+
a total of n - 2t v unknowns. Of these n equa.tions we have t equations which involves
the known error spectrum componeilts and the coefficieilts of the error locator pc~lynomjal.
These equations are
This is a set of v equations and the v unknowns. The uilkllowns !Ij for j = 1 , . . ., v can be
found directly or iteratively. We will esamine both a direct method, known as the Peterson
method, ancl an iterative method, known as the Berleba,mp-~Ifnsseyalgorithm, to solve for
the unknowns.
After the Ai coefficients are found then i z - 2t error spectrums can be found from
Equations 7. These calculations a.re shown in Ta.ble 4. The equa.tions axe evaluated from
top to the down. In this way, d l the varia.bles in the right hand side of the equ ;L t 'ions are
known. We now esamine a direct lnethod for finding the coefficients of the error locator
polynomial.
Where L is the length of the current shift register, il(-Y)is the desired error loca-
tor polynomia.1 a.nd B(X) is an intermediate polynomial used to reduce it nonzero
discrepancy. The discrepancy is explained in step 3.
2. Set
r-r+1
3. Compilte the r t h discrepancy, A,.. The discrepancy is nonzero when (7% - 1)th shift
register does not produce E, correctly.
4. If the 7th discrepailcy is zero, then ( r - 1)shift register does not need to be modified, it
ahead:, produces E l , EZ7 .
. . . E,. Go to step 8 to modify the intermediate polynomial
B(.Y).
If the .r discrepancy is is nonzero do the nest step.
5 . Compute new collnection poiy~lomialfor wllicll the r discrepancy is made to be zero.
6. Find out if the new shift register needs to be lengthened. From the Ber1ekam:p-Massey
theorem we need t o have L, >_ L,-l and L, >
r - LTml.
If 2L 1 1 r then shift register does not need t o be lengthened, store the new shift
register into, r l ( X ) ,i.e.,
7. We want to store in the intermediate polynomial B ( X ) the last shift register which it
had nonzero discrepancy and a length increase. This iilsures that tlie resulting shift
registe~has the minimal length. The old shift register norma.lized with its discrepancy
is stored in B ( X ) , i.e.,
The nel.v shift register T ( X ) for which the discrepancy 4, was reduced to zero is put
in A ( X ) , i.e.,
A(X) -T ( X )
And thl: length of the shift register is updated by:
Go to nest step.
9. Check to see if r = 2t. If the number of iterations I. is less than 2t then go to step 2
to continue.
If T = 2t then we are done, go t o the next step.
10. If the degree A(_Y) is not equa.1 to L then more than i. errors have occurred, otherwise
A ( X ) is the desired error 1oca.tor polynomial.
The polynomia.1 updates of !1(X), T(.Y), and B ( X ) each require a t most t multiplica-
tions. There are a total of 2t iterations, therefore. it takes 6t 2 multiplications to find the
error locator polynomia.1. This method is more efficient than the direct method which re-
quires t 3 0per:itions. Nest we give a decoding esample which uses the algorithms mentioned
above.
5.10 Example of a Transform Decoding
In the Example 1 of the transform encoding we showed an encoding method for a (7,3) RS
code. Here, we will give a specific decoding example and show the steps for decoding it.
Exampc'e: Let us assume a zero vector was sent, but because of the "noise" we received
the followiilg vector r
r = (O,O, a 6 , 0, a 2 , 0,O)
Our goal ic; t o find the error vector e which when subtracted from the received vector r ,
produces the desired transmitted vector v. Here we should expect t o get the zero vector
for v.
We will use the steps that we gave in the transform decoding subsection which are:
1. Find the finite field transform of the received vector r. From Equation 3 vie have
E2
d e t E3
El
E2 = d e t "a" a51=a2i0
Since the determinant is nonzero then 2 errors must have occurred From Equation 10
we have
Therefore from direct method we obtain the following values for R1 and A:!,
nl = a !I2 = Q6
A(X) = 1
B(-Y) = 1
L = O
For r = 1,
For r = 2
For r = 3
For r = 4
Degree A(X) = 2, therefore, more than 2 errors have not occurred. T h e results from
Berleltamp-Massey Algorithm for hl and 112 are
These were also the va.lues we got from the direct method. Now we are ready t o find
the remaining 12 - 2t spectral components E5, E6,and Eo.From Table 4 we have,
4. Take .;he inverse transform of the vector E, t o obtain the time-domain vector e. From
Equat.ion 4, t h e inverse finite field transform is calcula.ted as follows:
T h e error vector e then becomes
Subtracting vector e from the vector r we obtain the desired code word v which is
the zero code word.
Note that we did not use Ro, Rs, ant1 R6, i.e.. Only 2t spectrlm components were involved
in the calculations.
-4s we inentioned above, another way to do the last step of the decoding, was to subtract
the error spectrum E from the received spectrum vector R to obtain the desired code word
spectrum 'V. For this esample
v = (0, 0, 0,o. o,o, 0)
Taking the inverse finite field trailsform of V produces the code word in the tiine-domain.
We again get the zero code word as before.
6 C + + Class Libraries for Error Control Codes
In this section we give description of severa.1 C++ cla.ss 1ibra.ries. These C++ classes provide
the fol1owi:ng services:
a Encoding and decoding of R.S and BCH codes for a given code size 71 such that up to
t errors can be corrected.
First we give description of ea,cll C++ class with sample code segments showing how to use
each class. Sections 6.6, 6.7, G.S, and 6.9 describe several progra,ms where these classes are
used. For topics in programming languages concepts and constructs and object oriented
analysis and design see [l3, 31. For topics in how to do programming in C and C++
languages .see references [5. 12, 7, 14? 81.
following services:
1
add two G F polynomials pl(.Y) and p 2 ( X ) and print result do
polygf result = p l +
p2;
result.print();
11
find length of G F polynomial pl (S)and value of
it:: second coefficient and value of its third exponent do
int len = pl.length();
int coefficient = pl.coef( 1 );
int exponent = pl.expo( 2 );
r Fill array V with the contents of the array insg such that the conjugacy constraints
are met.
int pp[ = { 6, 1, 0 };
num=n-2t
segments o:F how we can use this class. The class provides the following services:
I
Define an RS code for user specified values of n and t .
Decotle a vector v of n elements having t or less errors into msg array of k elements.
Decoding is based on taking finite field transform of vector v to produce spectrum
vecto-r V. If an error has occurred Berlekamp Massey algal-ithm is used to generate
error locator polynomial. Using Recursive extension method the remaining error
spectrum values are obtained. After error spectrum is subtracted from V spectrum.
we obtain msg by estracting information from V. See Sections .5.G: 5.10: 5.1, 5.9, and
5.7.
6.9 E r r o r Coiltrol C o d e P r o g r a m n n - 0 u t p u t . c ~
This program is written in C++ language and is based on the C++ class ccode of Section 6.5.
T h e program listing is given in the .4ppendix D.
The input d a t a to this program contains a.n arbitrary number of lines where each line
contains k numbers. Each number is a 0 or 1 and is separated from the next number with
one or moi:e white spaces. T h e program produces jn, k ) code and can correct t or less errors.
T h e us,er neetls to provide the followillg information when the program is run:
5. An optional file name used only in decoding stage. If file naille is given the program
produces a suinmary report in this file. Each section of summary report starts with a
line ~ontainingtwo numbers. The first number is the actual number of errors occurred
and the second number is how nlany vectors had this many errors. Follow~ngthis line
is 0 3r more lines stating which vectors had this many errors. Each vector number is
princed one per line.
During encoding, pr0gra.m takes an input line of size k binary llunlbers and produces an
output line of size n bina.ry numbers. It repeats this process for all input lines. During
decoding 1;he prograin takes an input line of size n bina.ry numbers. cor1.ectinp; any errors
and producing an output line of k bina.ry numbers, Again the process is repeated for all
input lines.
7 Coilcluding Remarks
This paper was aimed to give a tutorial in error control code tecl~niquesand show several
practical ;spplications. It can also be shown t11a.t these techniques ca.n be useful to do
classification in neural networks [I1, 101.
Another goal of the paper was to outline the design of several C++ class libraries. We
also gave a higher level description of these 1ibra.ries and presented several programs that
uses these libraxies. These libraries provides 11s the capability to generate R!; and BCH
codes frorn primitive polynomials ~vllerethe user specifies the code size and number of
errors to Ile corrected. Using these libraries we showed power progranls in error control
codes can be written in less than few pages.
[l] R. E. Blahut. Transformation techniques for error control codes. IBM J . Research
Develop., 23, May 1979.
[2] R. E. Blahut. Theory and Prrrctice of Error Control Codes. .Addison-Wesley, Reading,
Massitchusetts, 1984.
[3] Grady Booch. Object-Oriented Analysis and Design with ilppliccitions. The Ben-
jamin/Cummings Publishing Company, Inc., Redwood City, Calif., 1994.
[4] Welsh. Dominic. Codes and Crgptogmphy. Oxford Science Publications, Oxford Uni-
versity Press, New York, 1988.
[6] Shu Ilin and Daniel J. Costello. Error control coding : fundnmenta1.s and o:pplications.
Prentice-Hall, Englewood Cliffs, N. J., 1983.
[7] Stanley B. Lippman. C++ Prinzer. Addison Wesley, Reading, MA, second edition,
1991.
[8] Scott Meyers. Effective C++, 50 Specific Ti17clgs to Inzprove Your Progmnzs and Designs.
Addison Wesley, R.ea.ding, Ivl-4. 1992.
[9] Arnold M. Michelsoll and Allen W. Levesque. Error control technique:: for digital
comrr;:unication. Wiley, New York, Wiley, 198.5.
[lo] Jamsllid Nazarj and Okan. I<. Ersoy. Experiments of error control codes in neural
ZZZZ~l'.l',Y.\=\'S.YZZZZ, Submitted .June 1994.
networks. !ITeunrl~Vet~vorks
[ll] Janlsllid Nazari and Okan. I<. Ersoy. Utilization of hadama.rd matrices and error control
codes for classification in neural networks. ATeurcrl ATetworks, Submitted Ju.ne 1994.
[13] Ravi ;Sethi. Proqrumming Languages Concepts nnrl Constructs. Addison-Wesley, Read-
ing, R4a.ssachusetts. second edition, 1989.
*/
v o i d b i n a r y - c h a n n e l ( i n t v [I , i n t n , i n t max-err );
i n l i n e inl: getRnum( i n t M )
C
return( rand() % M );
>
main( i n t a r g c , c h a r **argv )
C
if ( argc != 3 )
C
f p r i n t f ( s t d e r r , "Usage: %s max-err seed\n" , a r g v 0 1 );
exit( 1 );
>
i n t mi~x-err = a t o i ( a r g v [ 1 1 ) ;
i n t seed = a t o i ( a r g v [ 2 1 );
s r a n d ( s e e d 1;
i n t k = bch.k(); / / number of i n f o r m a t i o n d i g i t s
int *lnsg = new i n t [ k 1; a s s e r t ( msg != 0 ) ; // information i t s e l f
int *v = new i n t [ n 1; a s s e r t ( v ! = 0 ) ; / / encoded ( r e c e i v e d ) msg
register int i ;
i n t b.lknum = 1 ;
w h i l e ( ! c i n . eof ( ) )
C
f o r ( i = 0 ; i < k ; i++) / / r e a d a message.
c i n >> msg [ i 1;
i:E ( ! c i n . g o o d ( ) )
break;
f o r ( i = 0 ; i < k ; i++)
c o u t << msgC i 1 << " " ;
c o u t << "\n";
delete [I msg;
delete C] v ;
3
v o i d b i n a r y - c h a n n e l ( i n t v[], i n t n , i n t max-err )
C
i n t nilm-err = g e t b u m ( max-err+l ) ; / / number of e r r o r s t o g e n e r a t e
c e r r ,:< "Channel g e n e r a t e d " << num-err << " e r r o r s \ n n ;
regisiier i n t i , j ;
f o r ( i = 0 ; i < n u t - e r r ; i++)
{
j = getRnum( n ) ;
i l i ( V C j 1 == 0
V C j 1 = 1;
e:.se
v[ j 1 = 0 ;
3
3
B Error Control Code Program code-rs.cc
Following is the program listing for Reed-Solomon code of iz = 255, t = :3, see Sectiotl 6.7.
As it is seen it1 the program, the number of errors to be corrected c a n ea.sily be changed to
lower and higher values.
/*
LLLLLLLLL,LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL/;
I ** * * * * * * * * * * * * * * * ~ ~ * * # * * * * * * * * * * # # * # # # * * * * . , * * * . * . . . . * . . , * . l l * * * * * . * . . .
*/
// -*- c++ -*-
// c o d e - ~ ~ . ~ ~
//
//----------------------------------------------------------------------.-
//
// This is a sample program which shows how RS code can be defined
// and used.
//
//
// Modification History:
// February 18, 1993 - (jn) Original version is written.
//
//----------------------------------------------------------------------.-
v o i d encode( ccode * r s , i n t n , i n t km )
C
i n t *msg = neu i n t [ km+l 1 ; a s s e r t ( msg ! = 0 ) ; / / i n f o r m a t i o n i t s e l f
i n t *Tr = neu i n t [ n 1; a s s e r t ( v ! = 0 ) ; / / encoded ( r e c e i v e d ) Insg
unsigned c h a r c h ;
regis1;er i n t i , c o u n t ;
while ( 1 )
C
count = 0 ;
u h i l e ( c i n . g o o d ( ) %% count < km )
i
c i n . g e t ( ch ) ;
msgC count++ 1 = c h ;
>
ij! ( ! c i n . g o o d ( ) )
count- -;
msg[ km 1 = c o u n t ;
rm:->encode( msg, v ) ;
c o u t << SYNC << " \ n M ;
f o r ( i = 0 ; i < n ; i++ )
c o u t << v[ i 1 << "\n" :
i f ( count ! = km )
break ;
>
delete [I msg;
delete C] v;
v o i d decode( ccode * r s , i n t n , i n t km, i n t t )
C
i n t *rlsg = new i n t c km+l 1; a s s e r t ( msg ! = 0 ) ; / / i n f o r m a t i o n itse1.f
i n t *v = new i n t C n 1 ; a s s e r t ( v ! = 0 ) ; / / encoded ( r e c e i v e d ) nlsg
i n t b:.knum = 1 ;
int x
register i n t i , rv, len;
w h i l e ( c i n >> x , c i n . g o o d ( ) && x == SYNC )
C
f o r ( i = 0 ; i < n ; i++)
c i n >> v[ i I ;
I n n = msg[ km I ;
f o r ( i = 0 ; i < l e n ; i++)
p r i n t f ( "%c", msg[ i 1 ) ;
b:.knum++ ;
>
delete [I msg;
delete [I v;
i f ( cin.good() )
C
c e r r << "\nSync e r r o r i n block " << blknum << "\n";
exit( I ) ;
>
void m3()
(
i n t e:rC1 = ( 3 , I , 0 3; // p r i m i t i v e polynominal, m=3
i n t n = 7;
i n t t = 1;
ccode b c h l ( e 3 , 3 , 2 , n , t ) ; // alpha=2
p r i n t i : ( "n=%d t = % d k=%d\n", n , t , bchl . k ( ) ) ; // # of i n f o digfits
void m4()
(
i n t e4:C] = ( 4 , 1 , 0 3; // p r i m i t i v e polynominal, m=4
i n t n = 15;
i n t t = 1;
ccode b c h l ( e4, 3 , 2 , n , t ) ; // alpha=2
p r i n t i ' ( "n=%d t = % d k=%d\nU,n , t , bchl . k ( ) ) ; // # of i n f o d i g i t s
t = 2;
ccode bch2( e 4 , 3 , 2 , n , t ) ; // alpha=2
p r i n t i ' ( "n=%d t = % d k=%d\nN,n , t , bch2.k() 1;
t = 3;
ccode bch3( e4, 3 , 2 , n , t ) ; / / alpha=:!
, n , t , bch3 . k ( ) ) ;
p r i n t f ( "n=%d t = % d k=%d\nN
void m5()
int eEC1 = C 5, 2, 0 1; // primitive polynominal, m=5
int n = 31;
int t = 3;
ccode bchl( e5, 3, 2, n, t ) ; // alpha=2
printf( "n=%d t=%d k=%d\n", n, t, bchl.k() ); // # of info digi.ts
t = 4;
ccode bch2( e5, 3, 2, n, t ) ; / / alpha=2
printi( "n=%d t=%d k=%d\nM,n, t, bch2.k() );
t = 5;
ccode bch3( e5, 3, 2, n, t ) ; // alpha=2
printi( "n=%d t=%d k=%d\nM,n, t, bch3.k() ) ;
t = 6;
ccode bch4( e5, 3, 2, n, t ) ; // alpha=2
printi( "n=%d t=%d k=%d\nm,n, t, bch4.k() ) ;
t = 7;
ccode bch5( e5, 3, 2, n, t ) ; // alpha=2
printi( "n=%d t=%d k=%d\nW,n, t, bch5.k() ) ;
void usage( c h a r * s t r )
€
fprintf( stderr,
"Usage: %s- ( e i d ) <m> <t><nun-vects> [<summary-file>]\nM, str ) ;
cerr << " <m>=(315) o r d e r of p r i m i t i v e polynomial\n";
cerr << " <t>=number of b i t s t o c o r r e c t \ n " ;
exit( 1 ) ;
>
i n t check-'zrr-occr( i n t r v , i n t t , i n t blknum )
€
i f ( ryr == 0 )
re1:urn 0 ;
i f ( r a <= t )
f p r i n t f ( s t d e r r , "%d e r r o r s i n Block %d.\n", r v , blknum 1;
else
f p ~ : i n t f ( s t d e r r , "More than %d e r r o r s i n Block % d . \ n M ,t , blknum 1;
return rv;
void encode( ccode *bch, i n t msg[] , i n t v[] , i n t n , i n t k )
C
regis1;er i n t i ;
i n t l a s t = n - 1;
w h i l e ( ! c i n . eof ( ) )
C
f o r ( i = 0 ; i < k ; i++ ) / / r e a d a message.
c i n >> msg[ i 1;
id! ( ! c i n . g o o d ( ) )
break ;
bc:h->encode( msg, v ) ;
f o r ( i = 0; i < n; i + + )
i f ( i != l a s t )
C O U ~<< V [ i ] << I' ";
else
c o u t << v [ i 1 ;
c c u t << "\n";
1
if ( argc == 6 )
C
char summary-f ile [80 1;
FILE *outf ile ;
st:rcpy( summary-file, argv C 5 1 ) ;
ile = fopen( summary-file, "a"
or~tf );
if ( outfile == NULL )
C
fprintf(stderr , "File %s cannot be written.\nu, summary-f ile.);
exit( 1 ) ;
>
for ( i = 0; i < (t+2); i++ )
C
fprintf ( outfile, "%d %d\n" , i, summarycnt [ i 1 ) ;
for ( j = 0; j < summarycntC i 1; j++ )
fprintf ( outfile, "%d\n" , summary C i 1 [ j 1 ) ;
>
fclose( outf ile ) ;
1
case 5:
n = 31;
e = e5;
len = 3;
break;
1
ccode bch( e , l e n , 2 , n , t ) ; / / alpha=2
d e l e t e [I msg;
d e l e t e [I v ;
) //main(>