0% found this document useful (0 votes)
11 views48 pages

C++ Class Libraries For Error Control Codes: Purdue E-Pubs

The document presents a tutorial on error control codes and outlines the design of C++ class libraries for encoding and decoding using finite field transforms. It describes the functionality of these libraries, which can generate Reed-Solomon (RS) and BCH codes based on user-defined parameters. The paper also includes a brief introduction to digital communication systems and the algebra necessary for understanding error control coding techniques.

Uploaded by

mohammadfaridi54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views48 pages

C++ Class Libraries For Error Control Codes: Purdue E-Pubs

The document presents a tutorial on error control codes and outlines the design of C++ class libraries for encoding and decoding using finite field transforms. It describes the functionality of these libraries, which can generate Reed-Solomon (RS) and BCH codes based on user-defined parameters. The paper also includes a brief introduction to digital communication systems and the algebra necessary for understanding error control coding techniques.

Uploaded by

mohammadfaridi54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 48

Purdue University

Purdue e-Pubs
ECE Technical Reports Electrical and Computer Engineering

8-1-1994

C++ Class Libraries for Error Control Codes


Jamshid Nazari
Purdue University School of Electrical Engineering

Okan K. Ersoy
Purdue University School of Electrical Engineering

Follow this and additional works at: http://docs.lib.purdue.edu/ecetr

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.

2 Digital Communication System


A block diagram of a, digital communication system is shown in Figure 1. -4s is shown in

Figure 1: Block Dia.gram of a Digita.1 Communication Systeni.

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.

3 Brief Introduction to Algebra


This sectiorl gives a brief description of algebra which provides the necessary tool; to design
encoders and decoders. We will define the mathematical concepts such as groups and fields.
Our focus will be on fields which have finite number of elements. These fields are referred
t o as finite fields or Galois fields. We state several properties of Finite fields and show how
Galois field:; are constructed.

3.1 Definition of a Group


A set G on which a bina.ry operation * is defined is called a gr-oup if the following conditions
are satisfied :

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

group if G is a group and a.ny two elements in C7 satisfies the


A set C, is a cornrn~~lalive
condition
n+b=b*n
For esamplc! set G={0,1,2) with modulo-3 aritllmetic is a. commnta.tive group.

3.2 Definition of a Field


In an infornlal term, a set F is a field if we ca.n do addition, multiplication, subtraction,
and division. Forma.11~a set F on which binary operations addition and multip1ir:ation are
defined is called a field if the following co~lditio~ls
a.1-esatisfied:

1. F is a commuta.tive group 1111cleraddition. The additive identity element is referred


to a.s the zero element a,nd denoted by 0.

2. T h e set of non-zero elements of F is a colnln~ltativegroup under multiplication. The


multiplicative identity element is is referred to as the one a.nd denoted by 1.
3. Multi-?lication is distributive over a,ddition. For ally ele1nent.s a , b a.nd c in the set F
we have the condition.
~ C ) = 111.0 + nc
I L ( f

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

Table 1: Modulo-2 Addition and h,lultiplication.

that 1 = -1. So subtractioil is the same as addition.


T h e set F= {0,1,2,3,4) is a G F ( 5 ) if the addition and the multiplication operations on
field elements are Modulo-5 addition and Modulo-.5 multiplication. Table 2 shows Modulo-5
addition anti multiplication on the field elements. From this tahle 3 + 2 = 0. Therefore

Table 2: Modulo-5 Addition and ~!Iultiplica.tion.

additive inverse of 3 denoted by - 3 is 2. Also from the ta.ble 3 x 2 = 1. So m~lt~iplicative


inverse of 3 denoted by 3-' is 2. Additive and b1ultiplica.tive inverses are used t o do
subtra.ction and division. For esa.mple

3.3 Properties of Galois F i e l d


In this section we will state several properties of Galois fields and proof some of these
properties. Let 11s now t o coilsider a. finite field of q elements. T h e snlallest positive integer
:z:=l
A such t h a t 1 = 0 is called the charncteri.l;tic of the field GF(q). Since the elements in
the field are closed under addition

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.

Proof: Since field elements are closed under multiplication, we have

where each 6; is a ilonzero element of GF(c1). But this is equal to

SO we have 09-' = 1.

Theorem 3.2 In G F ( q ) order of any nonzero field element divides rl - 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

aq-' = 1 an.d a n = 1, therefore r must be zero, a contradiction. So order of any nonzero


field elemen;; divides q - 1.

Theorem 3.3 The cha.ra.cteristic X of Ga.lois field is a. prime number.

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.

3.5 Construction of GF(2")


For values of m > 1, Galois field GF(2") is an extension of C;a.lois field CiF(2). In this
section we will show how we can construct GF(Zm)from GF(2). This is done by using a
t s 1 and a syln bol a with the condition
primitive polynomial p(z) of degree m and e l e l n e ~ ~0,
that p ( a ) = 0.

Theorem 3.4 The set F = {0,1, a , a 2 , . . . , } forms a field.


Proof: The polynomial p(x) is a primitive polynomial therefore from the definition it divides
~2"'-I +
1 i-e.,

a2m-2 is the last element in the field before it repeats.


Nest we want to show that the elements of the set F are unique. To show t11.i~we use
the primitive polynomial p ( x ) again. So

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 ) = , ? + ,

Each element of the field was shown to be represented by a polynomial of degree 2 or


less. Table 3 shows each elelneilt is represented by a polvnomial a.nd equivalent %tuple
representation.

Table 3: Polynomial a.nd 3-tuple Representation of GF('23). Each ele~nelltof GF(23) is


represented by a polyl~o~llial
and a. 3-tuple equiva.lent represe11ta.tion

3.7 Minimal Polynoillial of a Field element in G F ( 2 " )


Let us take any nonzero element /3 from GF(2") and q = 2". From Theorem 3.1 we have
that any nonzero element to the power of q - 1 is 1, i.e.
+
So ,8 is a root of the polynomial xZrn-' 1. The smallest degree polynomial which has P
as one of its roots is called the mininzal polynomial of the field element 0.

Theorem 3.5 Minimal polynomial of a field element /? is irreducible.

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:

3.8 Roots of Polynomials in GF(q)


Polynomial;; over real numbers sometimes have roots which belong to an estended field of
complex numbers. Similarly the polynomials over GF(q)can have roots which belong to the
extended field GF(q m ). For example, we used the primitive polynomial p ( X ) = X3 X 1 + +
t o construct the extended field G F ( ~ ~ ) . polynomial has degree 3, therefore il, has three
This
roots. None of its roots belong to GF(2) and they all belong t o the estended field GF(23).
To determine its roots, each field element of GF(23) is substituted into p ( X ) and those
which result in p ( X ) = 0 are the roots. The roots of this polynomial are cr, cr2 and cr 4 . For
example:

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.

4 Brief Topics in Error Control Coding


In this section we will give a brief description of several basic concepts in coding. This
section contains the following:
Definition of a block code and a linear block code.

Encoding via a generator matrix.


Parity check matrix

Syndrome of a received vector.


Undetectable error patterns.
Definition of distance and weight in a block code.

Syndrome decoding.
Guarantees on error detection and correction.

Definition of a perfect code.

Binary symmetric channel (BSC).


Nearest-neighbor decoding rule.
Probi~bilityof undetected errors.
Probi~bilityof erroneous decoding.

A brief description of cyclic codes.


A brief description of BCH codes over GF(q m ).
A brief description of RS codes over GF(q).

4.1 Definition of a Block Code and a Linear Block Code


During encoding a vector of 6 q-ary bits is converted into a vector of n q-ary bits. These
n bit vectors are referred t o as code word.^. The number of code words is q k . The set of qk
code words is called a block code. A block code is called a linear (n, k) block cordeif it can
be generated from a k-dimensional subspace of an n-tuple vector space over GF(q).

4.2 Encoding via a Generator Matrix


We construct a generator matrix G by picking k n-tuple independent row vectors g l , g z ,
.. ., g k
ancl arranging them as rows of the matrix G. Here matrix G is made c~felements
form the field GF(q).
Encoding can be accomplished by the following equation:

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.

4.4 Syndrome of a Received Vector


Due t o "noise" a received vector r might not be the same as the transmitted vector v . So
we can assume
r=v+e
where e is a,n n-tuple error vector. T h e calculation s = r - HT is referred to as the syndrome
of the received vector r. So error detection is accomplished by calculating the syndrome of
the received vector r and error has occurred if the syndrome is not 0. Also note that the
syndrome of a vector r is the same as the syndrome of the error vector e.

4.5 Undetectable Error Patterns


If the error vector is such that it changes a code word v into another valid code word, then
syndrome c;xlculation will still be zero. So these types of errors are called undetectable errors
patterns. T h e number of undetectable error patterns is qk - 1 and the number of detectable
errors is q n - q k .

4.6 Definition of Distance and Weight in a Block Code


T h e Hamming distance, d(v,w), between two code words v and w is the number of places
these code words differ. If we calculate the Hamming distance between any two code words
and find the smallest number of these distances we obtaiil the nzinimum distance, d ~ , ,of
the block code. T h e Hamming weight (or simply weight) of a code word v , denoted by
w(v), is the number of nonzero elements in the code word v .

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:

dm;, = mill d(v, w )


= min w(v w )+
= min w(x)
-
- Wmin
4.7 Sy~lclro~lle
Decoding
This type of decoding first involves partitioning possible q n code words into q"isjoint sets.
The partitioning also known as stanrlnrd array construction is a.s follows. Arrange all the g k
code words into a row with the zero code word as the first element. Pick an n-tuple which
is not used before and place it as the first element in the second row, i.e. this element is
now below the zero code word. Note that, this element is an error pattern and pick those
error patterxs with smallest error weigl~tsfirst. For t l ~ eremaining columns of this row, add
each code word with the error pattern and put the resulting n-tuple under the code word.
Pick an0the.r n-tuple which is not seen before as the leader of the third row and fill the row
as before. Continue this process until we run out of all the n-tuples. Each row js called a
coset, and the first element of the coset is called the coset leader. It can be shown that all
the element:; in each coset has the same syndrome value. Each of the q k columns contains
q n - k elements, and the columns are disjoint.
We can create a table with the coset leaders in the first column, and their syndrome
values in the second column. Tlle table-lookup clecotling or syltdronze-decorlirtg is as follows:
1. Compilte the syndrome of the received vector
2. Find the error pattern w l ~ i c lcorresponds
~ to this syndrome in the table.
3. Add this error pattern to the received vector to obtain the code word ~vhichwas
transmitted.
4. Strip the parity bits.
If a decoder detects that there are Inore tllan t errors and refuses to decode the received
word then we have an incomplete decoder. If a decoder goes a.1lea.d and decodes any received
word, regarc.less of the number of errors that the code word llligl~thave, it is called a complete
decoder.

4.8 , Gua1:antees on Error Detection and Correction


A block code with mii~imumdista.nce dm;, gur1r~ntee.scall detect a.11error patterns of dm;,- 1
or fewer errors. However it is capa,l~leof detecting some error pa.tterns with dm;, or more
errors. A block code wl~ichcan correct t errors is called a t-error correcting code. T h e
number of errors which is guamnteerl t o be corrected by a block code is given by

However the, blocli code 1na.y correct t + 1 or more error pa.tterns.


4.9 Definition of a Perfect Code
During the c:onstruction of the stantlard array we were picking t l ~ eerror pattern:; with the
smallest weights first, i.e., the error patterns which have weigl~ts1 are selected first and
then the emor patterl~swl~ichhave weights 2 are selected nest a.nd so on. Finally error
which have weights t are selected as the coset leaders. .~\fterthis step 1,here may
not be any more n-tuples left to create the a.dditio11a.l cosets in the sta.nda.rd arr<%y.If this
happens then the block is referred to as a t-error correcting perject code. Perfect codes exist
and they art? rare.
4.10 B i n a r y S y ~ l l ~ l l e t rC
i ch a n n e l ( B S C )
Binary symmetric channel is an example of a discrete nlelnoryless channel. A bit 0 sent
through a channel might he received as a bit 0 01- hit 1. The prol~ahilityof send.ing 0 and
receiving 1 is denoted by Prob(ll0). Similarly a bit 1 sent through a, channel nlay be received
as a bit 1 01- bit 0. The proha,bility of sending 1 and receiving 0 is denoted by Prob(OJ1). If
the transitional probabilities Prob(Ol1) and Prob(ll0) are equal then t h e channel is referred
to as a bina,ry symmetric channel a.nd the transitional probability d u e is referred to as p.
The probabilities of BSC is as follows:

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.

Theorem 4,.2 Probability of decoding error is mi~limjzedwhen using the nearest-neighbor


decoding rule.

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.

If we take log of both sides we have


n
log P r o b ( r v ) = 1log P ~ o b ( r ~ l v ~ )
i= 1

For binary symmetric channel?


Prob(r; # v;~u;)= p

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.12 Probability of U n d e t e c t e d Errors


Let A; to represent the number of code words which has weight equal to i. Then the numbers
.Ao, .Al,. . . , A, are called the weight distributiorz of a. blocli code. Errors are ~ ~ n d e t e c t e d
when error patterns are identical to nonzero code words. For a biilarv symmet~,icchannel
with the transition probability p the probability of undetected error is given by

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

produces the n-tuple


1
V = (v~-I,VO,V~,...,~~-~,V~-Z)

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,

s u c l ~that every code polynonlial is a multiple of g ( X ) . T h e genera.tor polyllolnial g ( X ) can


also be shown to be a factor of the polynomial X n - 1.
The encoding of cyclic codes is accomplished by multiplying each message polynomial
with the generator polynomial g(.Y). However this does not produce systematic code words.
The systema,tic code words can be generated by the following equation,

x"-" u ( X ) + ( x " - ~ . u(-Y) mod g ( X ) )

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.

4.15 A E;rief Descriptioil of BCH Codes Over GF(ql")


T h e Bose, C:haudhuri, and Hocquenghem (BCII) codes is an important class of random
error-correcting cyclic codes. The generator polynomial g(.Y) of a BCH code contains 2t
consecutive roots of p, i.e., g ( p i ) = 0 for 1 5 i 5 2t. In addition g(.Y) must also be the
smallest degree polynomia.1. To a.clijeve these we find the least common multiple ( L C M ) of
minimal polynomial of roots of g ( S ) , i.e,

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.

4.16 A Brief Descriptioi~of RS codes over GF(q)


Reed-Solon~on(RS) codes are special type of BCH codes which have code polynomials over
GF(q). Wf.ere q is a prime number, or power of a prime. Usually we select q = 2m.
The minimal polynomial of field element is (.Y- P ) . TO get a t-error correcting q-ary
code, we select p , . . . , P2t as the roots of the genera.tor matrix. The generator matrix is

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.

5 Encloding and Decoding using Finite Field Transform


This section explains the following topics:
a Defin.ition of the finite field transform is given.

a Defimtion of the inverse finite field tra.nsform is given.

a Conjugacy constraints are explained?

a Transform e~lcodi~lg
method is explained.

a Two examples in transform encoding are given.

a Transform decoding is explained.

a Recu~siveextension of the error spectrum is expla.ined.

a .4 direct method is explained t o find the error 1oca.tor polynomial.

a Berleliamp-Massev algoritllm is explained to find the error locator polynornial.

a An E.uample of tra.usform decoding is given.


5.1 Definition of the Finite Field Trailsforin
The finite field transform of the vector v over the field elements GF(q) is given by the
equation

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.

5.2 Definition of t h e Inverse Finite Field Transforill


Inverse finite field transform of the vector V is defined as follows:

Where p is the chara.cteristic of the field GF(q).


If the code polynomial over v is v ( X ) and the code polynomial over V is V ( X ) then
we have the following theorem.

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

In the example above A3 = {3,6,9,12}.


So far we have divided indices 0,. . ., n - 1 into several conjugacy classes. The conjugacy
classes which contain any index in the range 1,. . . , 2 t will have 0 in the spectrum vector V
in all of their indices. Now let us select a conjugacy class A with p elements, such t h a t it
does not have any indices in the range 1 , . . . ,2t. Let us refer to these classes as free classes.
Let us pick one of the indices in set A, say index j , as a free element, where we want t o
store a GF(2rn) field element. T h e values stored in the other indices are based on Vj. Now,
we need to determine which field elements of GF(2") may be stored in Vj. It can be shown
that the only valid field elements that can be stored in Vj are zero element and those field
elements t h a t have order 27' - 1. Therefore, the bit content of Vj is p bits. The total bit
content, k, is the summation of these p values in the free sets.

5.4 Trarisform Encoding


We are interested in block codes which will have multiple-error correction capabilities. T h e
BCH codes are linear cyclic codes which meet this criteria. In the encoding of the BCH
codes, we need t o find a generator polynomial g(,Y). This polynomial is obtained by finding
the least common multiple of minimal polynomials of 2t consecutive field elements. So the
roots of g ( X ) are ,f3j for j = 1 , . . . , 2 t and their conjugates. T h e generator polynomial g ( X )
multiplied with a message polynomial produces a code word.
T h e mu.ltiplication of two polynomials g ( X ) and u ( X ) in the time domain is equivalent
t o the cyclic convolution of their corresponding coefficients. T h e convolution in the time
domain is ecquivalent t o the inverse finite field transform of the product of finite field trans-
forms of g(.X) and u ( X ) . From Theorem 5.1 we also have that if a polynomial has a root
a t ,f3j then its spectrum component 5 is 0, so we define the transform encoding method a s
follows:
1. Set fi.equency components Ifj = 0 for j = 1, . . . , 2 t

2. To meet conjugacy constraints, identify ':free7' a.nd "rlepentlent" spectra.1 components.

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.

5.5 Exa.mples of Transform Encoding


Here, we will give two esamples in transform encoding. Both examples use the elements
from GF(8). As a reminder, the field elements of GF(8) are

And the polynomial representation of each field element is given in Ta.ble 3.


Exnmpi'e 1: In this example, the time and spectrum domains are both in GF(S). We
are interested in obta.ining a code which can correct up t o 2 errors, so t = 2. We will use
the primitive field element a which has order 7 , so n = 7.
The steps of the transform encoding method, whicll was given above, are explained for
this example which are as follows:

1. Set fi-equency components If1 = If2 = If3 = If4 = 0

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.

5.6 Tran.sform Decoding


We have received a vector r which is an n-tuple over GF(q). Because of "noise" this vector
may have been corrupted, therefore. we can think of the received vector r as the sum of a
valid code word v and an error vector e, i.e.,

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.

2. If R j == 0 for j = 1 , . . . , 2 t then no errors have occurred and the received vector r is


the de,jired code word. So we don't do any of the following steps.

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.

5.7 Recu.rsive Extellsioil of the Error Spectrum


We are given an error spectrum vect.or E where the locations Ei for j = 1.. . . , 2 t are known
and we want to determine the remaining ,n - 2t spectrum components. We assume that the
actual number of errors which have occurred, denoted by v, is less than or equa.1 to t. It
can be shown that
V

Ek = - C !iiEk-; k = O....:n- 1 (7)


j=1

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

Since Aj = O for j > v we have

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

Ta,ble 4: Recursive Extension of the Error Spectrum.

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.

5.8 Direct Method for Fiildiilg the Error Locator Polynoinial


We are interested in solving the u equations in 9 t o determine the .Aj values. These equations
can be written in matrix form as
- - -
&I E,,,- 1 Ev-2 ... E l- - I -Evil
Evil E,, Eu-l . . . E.2 A.2 -E u i . 2
Eu+2 &+I Eu . . . E.3 113 = -EU+3

E2u-l E2u-2 Ezv-3 . . . Ev - - i l , - -E?u -


We can find the coefficients of the error locator poly~~omial by fillding the inverse of the ma-
trix. And m.ultiplying the inverse with the right hand side produces the desired c~nknowns.
But before we ca.n find the inverse, we need to know if the inverse exists. We also need
to find the number of errors, v , which has actually occurred. To do this, set 17 = t and
calculate the determina.nt. If the determinant is nonzero then inverse exists and the number
of errors is :!. If the determinant is zero, decrease v by 1, and repeat the process until the
determinant becomes nonzero. Since the determinant is nonzero then the inverse exists.
This direct method is also known as the Peterson method.
In this method, the number of computations for finding the inverse of the t by t matrix
is proportional to t3 operations. For large t this method is not feasible and we need to
use another method which is more efficient. The Berlekamp-Massey Algorithm is examined
next .

5.9 Berl ekamp-Massey Algoritl~m


We are interested in solving the v equations in 9 iteratively. This method desciibed here
is the Berlertarnp-~2.lnsseyalgorithm which is computationally more efficient than the direct
method. During iterations, the algorithm builds a smallest length linear-feedback shift
register which produces the sequence in 9. The algorithm is as follows:

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.

So T ( X )is the new shift register which produces E l , E 2 , . . . ,E, correctly.

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.,

Go to itep 8 t o modify the intermediate polynomial B ( X ) .


If 2L < r then shift register needs to be lengthened, do the next step.

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 t o step 9 to see if we are done.

8. Modify intermediate polynomial B ( X ) as follows:

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

Therefore the spectrum of the received vector r is:

2. All R j for j = 1 , . . . , 4 are not zero therefore errors have occurred.

3. Set E j = R j for j = 1 , . . . , 4 . El = a 5 , E2 = 0, E3 = a 4 ,and E4 = as. T h e remaining


error spectrum components are determined recursively via recursive extension method.
To use the recursive extension we need to find the error locator polynomial. We will
use both the direct and iterative methods t o find the coefficients of the error locator
polynomial.
Direct Method: Let us first t o find out how many errors actually have occurred. To do
this, we examine the determinant of the matrix in Equation 10. Assume v = t = 2.

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

Subst.~tutinginto above equa.tions we get

Therefore from direct method we obtain the following values for R1 and A:!,

nl = a !I2 = Q6

Berlekamp-hfasse y Algorithm: Here we use the Berlekamp-Massey algori tllm t o find


the ~c~efficients
of the error locator polynomial.
For r = 0,

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,

T h e resulting error spectrum E is

E(-Y)= ( I ?as,0?a', a5,a', 1)

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 Arithmetic of polynomials over GF(2).

a Automatic generation of Galois field tables from primitive polynomials.

a Algebra over field elements in GF(2").

a Arithmetic of polynomials over GF(2").

a Automatic generation of conjugacy classes.

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.

6.1 C++ Class polybin


This class deals with binary polynomials, i.e. the coefficients of each polynomial is 0 or 1.
Table 5 gives sample code segments of how we ca.n use t.liis class. The class provides the

Table .5: Sample Code Segment for C1a.s~polybin.


+
T o define polynonunl PI(,'() t o be X I 0 ,Y8+. S% +S' + + 1 do
int expoll] = { 10, 8, 4 . 2, 1, 0 );
polybin p l ( espol, 6 );

T o add poly~aoinialsp l ( S ) , p?(.Y) and ps(,Y) amd priiil res.ul2 do


polybin result = pl + p2 + p.3;
result.print();

T o fi1t.d rernaznder of l ~ u opolynon1ic7ls PI(,\-) nird p ( S ) (10


result = pl 9% p2;

T o copy p o l y i ~ o m z a fpl(.Y) i n t o polyi~oiniafp ? ( S ) do


poly bin p2 = pl;

Result ~uzllbe zero in t11.efo1lowz~1.gexpvessloil


+
result = (p5 % p4) ( p 5 % p 4 ) ;

following services:

Sun1 several binary polynomials.


Fincl remainder of two binary polynomials.

Copy a polynomial t o another polynomial.

Print a binary polynomial.

6.2 CS-+Class gf2m


This class provides automatic generation of Galois field tables from primitive polynomials.
see Sections 3.5 and 3.6. Table 6 gives sample code segments of how we can use this class.

Table 6: Sample Code Segment for Class gf2m.


To construct Galois field GF(2'"), for example m=9
we can use primitive polynomzal X 3 + ,Y + 1 and do
int en = { 3, 1, 0 ) ;
gf2m gf( e , 3 );

To print the constructed Galois field table do


gf.print()

To find order of field element a%n GF(23) do


int ans = gf.ord( 6 ); (a 4 = 6 i n vector notation)

To multiply two field elements a


" 4 and a
" 5 do
ans = gf.inul( 4, .5 ); (a ns=2)

T o add or subtract two field elements a and b do


ans = gf.add( a, b );

T o divide two field elements a and b do


ans = gf.div( a, b );

To find inverse of field element a do


ans = gf.inv( a );

T o do a c where a is a field element and c is a constant do


ans = gf.pow( a, c );

The class provides the following services:


Find. order of a field element.

Multiply two field elements.

Add or subtract two field elements.

Divide two field elements.


Find. inverse of a field element.

Raise a field element t o a power.


Print generated Galois field table.

6.3 CS-+Class polygf


This class deals with Galois Field (GF) polynomials. Here coefficients of each polynomial
are elements of a Galois field. Table 7 gives sample code segments of how we (can use this

Table 7: Sample Code Segment for Class polygf.


To define polynomial pl ( X ) m b e a " X 4 +x' + 1 in GF(23) do
int primpolyl] = { 3, 1, 0 ); primitive polynomial is X 3 + X + 1
gf2m gf( primpoly, 3 )
int expo! = { 4, 2, 0 ) ;
int coefl] = { 5, 2, 1 ); coefficients are given in vector notation
int 1eligthGfpoly = 3;
polygf p l ( &gf, coef, expo, 1engthGfpoly );

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 );

multiply G F polynomial p l ( X ) with a field elemen,t a do


result = pl.multC( a );

multiply G F polynomral p l ( S ) with


result = pl.multX();
X do
I
multiply G F polynomial p l ( X ) with X and field element a do
result = pl.multCX( a );

class. The class provides the following services:


I
Sum two G F polynomials.
Mukiply a G F polynomial with a field element.

Get the length of resulting polynomial.


Get i t h coefficient of a G F polynomial.
Get ith exponent of a G F polynomial.
Mul1;iply a G F polynomial with X. This causes each exponent of the G F polynomial
t o be increased by 1.
Mul1;iply a G F polynomial with a field element and X.
-
r Print a G F po1ynomia.l.

6.4 CS.+ Class colljugacy


This class provides automatic genera.tion of coqjugacy classes for a given size code word
and numb'er of errors to be corrected. see Section 5.3. Table 8 gives sample cocle segments

Table 8: Sample Code Segment for Class conjugacy.


- -
T o generate coitjugacy classes for code sire n such that we
carz correct t errors do
int primpolyu = { 6, 1, 0 ); Primitive polynominl is X6 + ,Y +1
gf2m gf( primpoly, 3 ) Length of primpoly i s S
int n = 63;
int t = 3;
conjugacy a( &gf, n, t );

T o get n.um.ber of z n f o r n ~ a t i o nbits I; i n eacl~code word do


int num = a.k(); i~um=45
-
T h e conjugncy object a prod.uced (65',45) code. T h e order of prln~ttirle
polyitomtal m. was 6 crud n was 2"' - 1. W e ccin also generate
other code sizes, t o have n = 21 (21 divides 63), and t = :3 do
conjugacy b( &gf, 21, 3 );
int num = b.k(); num=6

LT o p r i i ~ tconjugacy classes for object a do


a.print();
1
i
use conleizts of nlsg io fill V such thnt the conjtlgacy const.raznfs are met a'o
a.fillV( msg, V );

eztract iiiformnlioit from V ccnd fill msg do


a.estractV( V, rnsg );
1
of how we can use this class. The class provides the followiilg services:
r Generate conjngacy classes for given code size n such that we can correct t errors.
r Get the number of information bits in each code word.

r Fill array V with the contents of the array insg such that the conjugacy constraints
are met.

r Extract information from V and fill msg.


r Print the conjugacy classes.

6.5 C+-+ Class ccode


This class provides encoding and decoding methods for binary and Reed-Solomon codes for
arbitrary values of n and t where ,n is the size of the codeword and t is number of errors to
be corrected. T h e value n is based on any given field element. This means that the user has
the option to generate primitive and non-primitive codewords. Table 8 gives sa.mple code

Table 9: Sample Code Segment for Class ccode.


- -
To define a Reed-Solomon code of sire n = 7 capable of
corr-ecting t = 2 information symbols in GF(8) do
int pp[ = { 3, 1, 0 }; Primitive polynomial of order in = 3
int ppLength = 3;
int beta = 2; A field element from GF(2m)
int n = 7; Order of field element beta.
int t = 2;
int GenRS = 1; Generate RS code
ccode RS( pp, ppLength, beta, n, t, GenRS );

number of information symbols k in each code word of RS do


int num = RS.k();

int pp[ = { 6, 1, 0 };
num=n-2t

define a BCH code of sire n = 63 capable of correcting t = 3 bits do


Primitive polynomial of order m = 6
1
int ppLength = 3;
int beta = 2; A field element from GF(2m)
int n = 63; Order of field element beta.
int t = 3;
ccode BCH( pp, pplength, beta, n, t );

number of information. bits k in each code word of BCH do


int num = BCH.k(); nu1n=45
i
I- I
To encode msg array of k elements and put result znto v array of n elements do
X.encode( msg, v ); S is RS or BCH

decode v array and put result into msg array do


X.decode( v, msg ); S is RS or BCH

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 .

Define a BCH code for user specified values of n and t .

Get number of information symbols in the resultant code

Encotle msg of k elements into a vector v of n elements. Encoding is based on filling


the sl~ectrumvector V with msg such that the conjugacy constraints ar~emet and
then doing inverse finite field transform of V produces v a code word in the time
domain. See Sections .5.4,5.5, 5.3, and 5.2.

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.6 Errtor Coiltrol Code Prograill code-bin.cc


This progritm is written in C++ language and is based on the C++ class ccode of Section 6.5.
T h e progra,m listing is given in the Appendix A.
The input d a t a to this program contains an arbitrary number of lines where each line
contains k numbers. Each number is a 0 or 1 and is separated from the nest number with
one or more white spaces. The program produces ( 6 3 , 4 5 ) code and can correct 3 or less
errors. As .t is seen from the program listing, the program can easily be modified to produce
other code sizes.
The user provides two additiona.1 information when the pr0gra.m is nin. The first piece
of informaloionis the noise level in the communication channel. The noise level is specified
by the maximum number of errors nzrrxErr that the channel induces on each encoded word.
The secontl piece of inforination is a seed number seed for the random number generator.
After user specifies mnxErr and seer1 the program does the following:
1. Read an input line.
2. Encode the input line.
3. Pass encoded word through the commu~~ication channel. The channel produces a
random number between 0 , . . . ,mnxErr. This number specifies the number of errors
t o generate on this code word. Tlle challnel then genera.tes errors in randorn locations
of thq? encoded word.
4 . Decode the received encoded message from channel, correcting any errors.
5. Print the decoded messa.ge.

6.7 Error Control Code Program code-rs.cc


This program is written in C++ language and is based on the C++ class ccode of Section 6.5.
The program listing is given in the Appendis B.
The input d a t a to this program conta.ins an a.rbitrary number of lines w11el.e each line
contains a]-bitra.ry nulnber of ASCII cha.racters. Code size is 25.5 and can correct 3 or less
errors. The number of informatio~lsvlnbols is 249. The number of errors to be corrected
call easily be cha.nged to lower and higher values.
The us'x tells the program to [lo encoding by the -e flag and to do decoding by -d flag.
Given an :lSCII file to the pr0gra.m a.s input and specifying -e fla.g, an .ASCII output file
can be generated. The encoded file will be sequences of numbers, instead of alphanumeric
characters. The encoded output file. which is crypted, can be transmitted from point A to
point B a.s if the communication channel is secure. Without the right decoder the contents
of the file is not understandable. The encoded file can be corrupted by t errors or less in each
code word and the origina.1 file can still be obtained by using the -4 fla.g. One application
of this pro,=ramis to send secure e-mail to a.nother pa.rty which I1a.s the same program. For
topics in cryptogra.phy see for esample [ 4 ] .
6.8 E r r o r Coiltrol C o d e P r o g r a m query.cc
This progr,am is written in C++ language and is based on the C++ class ccode of Section 6.5.
The program listing is given in the Appendix C. The program prints (n,,k , t ) values for
several BC:H codes from primitive polynomials. No input is required by the user.

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:

1. -e tcb do encoding or -d to do decoding.


2. m tk.e order of a primitive polynomial. The valid values for nl is set to be 3 or 5.

3. t is ~ n a s i m u mnumber of errors to be corrected.

4. T h e number of lines in the input file.

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.

[5] B. W. 1Cernigha.n and D. M. Ritchie. The C Progra~nmingLarzguage. Prentice-Hall,


Englewood Cliffs, N.J, second edition, 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.

[12] Ira P311l. C++ for Pcr..~.cnlProgmmnzer.~. Benja.min/Cun~mi~~gs


Pub. Co.? Redwood
City, Calif., 1991.

[13] Ravi ;Sethi. Proqrumming Languages Concepts nnrl Constructs. Addison-Wesley, Read-
ing, R4a.ssachusetts. second edition, 1989.

[14] Bjarne Stroustrup. Tlze C++ Progrunznzing Lang?rnges. Addison-Wesle~y, Reading,


Massitchusetts, second edition, 1991.

A Error Control Code Program code-bin.cc


Following is the program listing for BCII code of n = 6:3. t = 3, see Section 6.6. As it is
seen, the program ca.n easily be lnodifiecl to generate other code sizes.
/*
LALLALLLLhLLLLALLLLLLLLLLLLLLLLLLLLLL4LLLLALAALLLLLLLLLLLLLLLLLLLLLLLLLL
Q b @ @ b 1 1 @ @ b @ @ b @ b @ 8 @ b @ @ @ b @ 8 1 b b @ b Q @ I @ I I b ~ I @ 8 ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ @ ~ # ~ ~ ~ ~ ~ ~ @ @

% Author: Jamshid Nazari Purdue U n i v e r s i t y


%
% (C) COPYRIGHT 1993, by Jamshid Nazari. A l l r i g h t s r e s e r v e d .
b @ ~ . . . @ * * . b . b b . ~ I . . b @ b b b . ~ . . . . I @ , , . @ . , . b , , . . * * . , , , . @ @ . , @ , , , , , , b , * , , ,
ALLLLLAALLILALLLLLLLLLLLLAALLLALLALLALLLAALLLLLLALLLLLLLLLLLLALLLLLLLLLLL
, @ @ @

*/

// This i.s a sample program which shows how we encode b i n a r y d a t a


//
//
// Modification History:
// February 18, 1993 - ( j n ) Original version i s written.
//

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 e6fl = 1 6 , 1 , 0 >; / / p r i m i t i v e polynominal , m=6


i n t n = 63;
i n t t = 3;
ccode bch( e 6 , 3 , 2 , n , t ) ; // alpha=2

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;

bch. encode( msg, v ) ;


b i n a r y - c h a n n e l ( v , n , max-err ) ;
i n t r v = bch.decode( v , msg ) ;
i:e ( r v > t
f p r i n t f ( s t d e r r , "Morg t h a n %d e r r o r s i n b l o c k % d . \ n " ,
t , blknum 1;
e:Lse
if ( r v > O )
f p r i n t f ( s t d e r r , "%d e r r o r s have o c c u r r e d i n b l o c k % d . \ n " .
r v , blknum ) ;

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 * * * * * . * . . .

% Author: Jamshid Nazari Purdue University


%
% (C) COPYRIGHT 1993, by Jamshid Nazari. All rights reserved.
LLLLLLALXALLLALALLLALLLLLALLLLLLLALLLLLLLLLLLLALLLLLLALL/.LLLAALLLALLLAA/;
1 ~ ~ ~ * Q Q 1 1 Q Q Q * Q Q Q ~ ~ ~ I Q ~ I Q ~ I Q Q Q ~ Q ~ ~ e ~ ~ e ~ I ~ ~ ~ ~ ~ Q Q Q Q Q Q Q Q ~ l Q Q Q Q Q Q # l Q 8 Q * Q Q * Q Q Q

*/
// -*- 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.
//
//----------------------------------------------------------------------.-

const int SYNC = 99999;

void encode( ccode *rs, int n, int km ) ;


void decode( ccode *rs, int n, int km, int t ) ;

main( int argc, char *argvCI )


C
if ( argc ! = 2 )
C
fprintf ( stderr, "Usage: %s C-edl\nM, argvc 0 1 1;
exit( 1 1;
}

int e8C1 = C 8, 4, 3, 2, 0 } ; // primitive polynominal, m=8


int e8-len = 5;
int n = 255;
int t = 3; // maximum # of error can correct
ccode rs( e8, e8-len. 2, n, t, 1 ) ; // alpha=2

int k = rs.k(); / / number of information digits


cerr << "k= " << k << "\nl';
int km = k - 1 ; / / use 1 byte as the length of block
decode( %rs , n , km, t ) ;
e::it( 0 ) ;
>
f prin1;f ( s t d e r r , "Usage : %s 1-edl \n" , argv C 0 1 );

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 ;

r v = rs- >decode( v , msg ) ;


i f ( rv > t )
f p r i n t f ( s t d e r r , "More t h a n %d e r r o r s i n Block % d . \ n N ,
t , blknum ) ;
e:.se
if ( r v > O )
f p r i n t f ( s t d e r r , "%d e r r o r s have o c c u r r e d i n Block % d . \ n U ,
r v , blknum ) ;

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 ) ;
>

C Error Control Code Program query.cc


Following is the program listing which prints (n.,I;. t ) values for several BCH codes, see
Section 6.8.
/*
# / # # Q # # # # # l ~ e # e # # ~ # # ~ # # 4 # # # # # # # # # # # # # # I 1 # # # ~ # 4 1 ~ ~ 4 # # # 0 # # # # # # @ # # # # # ~ ~ # # @ ~ # #
I.LLLLLLLL,,LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLALLALLLLLLLLLLLLLLLLLALLL
% Author: Jamshid Nazari Purdue U n i v e r s i t y
%
% (C) COPYRIGHT 1993, by Jamshid N a z a r i . A l l r i g h t s r e s e r v e d .
~ r ~ r r ~ r ~ o ~ ~ o o o r ~ r r ~ r ~ o ~ o ~ ~
LLLALLLLL,.LLLLhLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLALLLLLLLLLLLLLLLLLLLLLLLL
*/
// -*- c+i- -*-
/ / query .c:c
//
//--------.---------------------------------------------------------------
//
// This program p r i n t s ( n , k , t ) f o r s e v e r a l BCH codes.
//
//
// Modif j-cation History:
// Fetbmary 18, 1993 - (jn) Original version is written.
//

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() ) ;

main( int argc, char **argv )


C

D Errnor Control Code Program nn-output .cc


Following is the program listing which can do encoding and decoding for several EICH codes,
see Section 6.9.
/*
LLLLLLLLLXLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

% Author: Jamshid Nazari Purdue University


%
% (C) COPYRIGHT 1993, by Jamshid Nazari. All rights reserved.
. ~ . * # * * # * # * # * # # * # # # . . * # . . * # . * . # . * * # # . . # * # # # * # # # * # # # # # # * @ # # ~ @ * @ # ~ ~ ~ ~ # # * # #
LLLLLLLLLILLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
*/
//
// This program performs encoding and decoding. The input i s r e a d from
/ / s t a n d a r d i n p u t and t h e output is w r i t t e n i n t o s t a n d a r d o u t p u t .
// s e e u s a g e ( ) .
//
// Format: of <summary-file> (when p r e s e n t ) i s a s f o l l o w s :
// <#errcrs> <freq> Example <summary-file>
// <line$!> 0 3
// <line$!> 12
// ... 15
/ / <#errclrs> <f r e q > 27
// <lined!> 1 0
/ / <lined:> 2 0
// ... 3 2
// 13
// 22
/ / I n t h i s example:
// - Lines 12, 15, 27 had 0 e r r o r s . The l i n e # a r e i n i n c r e a s i n g o r d e r .
/ / - No l i n e s had 1 e r r o r .
// - No l i n e s had 2 e r r o r s .
// - Lines 13 and 22 had 3 e r r o r s . The l i n e # a r e i n i n c r e a s i n g o r d e r .
//
// liodif i c a t i o n History:
// February 18, 1993 - ( j n ) Original version is written.
//
//-----------------------------------------------------------------------.

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

v o i d decode( i n t a r g c , c h a r **argv, ccode *bch, i n t msg[I,


i n t v [I , i n t n , i n t k , i n t t )
C
i n t **summary = new i n t * [ t + 2 1 ; a s s e r t ( summary ! = 0 1;
i n t *summarycnt = new i n t [ t + 2 1 ; a s s e r t ( summarycnt ! = 0 ) ;
i n t num-vects = a t o i ( a r g v [ 4 1 ) ;
register int i , j ;
f o r ( i = 0 ; i < ( t + 2 ) ; i++)
C
swnmary[ i 1 = new i n t [ num-vects 1; a s s e r t ( summary [ i 1 != O ) ;
smnmarycnt [ i 1 = 0 ;
f o r ( j = 0 ; j < num-vects; j + + )
summary[ i I [ j I = 0 ;
>
i n t bl.lcnum = 1 ;
i n t l a s t = k - 1;
while :8 ! c i n . eof (1 )
C
foj: ( i = 0 ; i < n ; i++) / / r e a d encoded d a t a
c i n >> v[: i I ;
i f ( !cin.goodo )
break ;
j = check-err-occr( bch->decode( v, msg ) , t , blknum ) ;
simary [ j 1 [ summarycnt [ j ]++ 1 = blknum++;

for ( i = 0; i < k ; i++ )


if ( i ! = last )
cout << msgC i 1 << " " ;
else
cout << msg C i 1 ;

cout << "\n";


>

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

for ( i = 0; i < (t+2); i++ )


delete [I summary[ i 1 ;
delete [ ]summary;
delete [I summarycnt ;
1 // decode0

main( int argc, char **argv )


i
if ( argc ! = 5 %% argc ! = 6 )
usage ( argv C 0 1 ) ;

int m = atoi( argvC 2 1 1;


if ( m ! = 3 &% m ! = 5 )
usage( argvC 0 I ;
i n t t = a t o i ( argv[ 3 1 ) ;
i n t e3[] = { 3 , 1 , 0 1 ; / / p r i m i t i v e polynominal, m=3
i n t e!i[] = C 5, 2, 0 1 ; // p r i m i t i v e polynominal, m=5
i n t n, len;
i n t *f!;
switch ( m )
C
c a s e 3:
n = 7;
e = e3;
len = 3;
break;

case 5:
n = 31;
e = e5;
len = 3;
break;
1
ccode bch( e , l e n , 2 , n , t ) ; / / alpha=2

i n t k = bch.k(); // number of information d i g i t s

i n t *u.sg = new i n t C k 1 ; a s s e r t ( msg ! = 0 ) ; / / information i t s e l f


i n t *v = new i n t [ n 1 ; a s s e r t ( v ! = 0 ) ; // encoded ( r e c e i v e d ) ms.g

if ( strcmp( argv[ 1 1 , "-el' ) == 0 )


encode( t b c h , msg, v , n , k 1;
e l s e i f ( strcmp( a r g v c 1 1 , "4") == 0 )
decode( a r g c , a r g v , kbch, msg, v, n , k , t ;
else
usage ( argv C 0 1 ;

d e l e t e [I msg;
d e l e t e [I v ;
) //main(>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy