Chapter 5
Cyclic CodesDr.Mohammed Taha El Astal
Note: This PPT is an enhanced version of Dr.Musbah Shaat’s PPT.
2
Definition
Definition: An (n,k) linear code C is cyclic if every
cyclic shift of a codeword in C is also a codeword in C.
• This mean that If c0 c1 c2 …. cn-2 cn-1 is a codeword, then
cn-1 c0 c1 …. cn-3 cn-2
cn-2 cn-1 c0 …. cn-4 cn-3
: : : : :
c1 c2 c3 …. cn-1 c0 are also codewords.
• Cyclic is a great feature. Why?
3
Example
• The (7,4) Hamming code discussed
before is cyclic:
1010001 1110010 0000000 1111111
1101000 0111001
0110100 1011100
0011010 0101110
0001101 0010111
1000110 1001011
0100011 1100101
4
Code Polynomial
• Example:
1010001 ; 1+X2+X6
0101110 ; X+X3+X4+X5
• Each codeword is represented by a polynomial of
degree less than or equal n-1.
• .deg[ ]c(X) n 1
c = c0 c1 c2 …. cn-1. c(X) = c0 + c1X+ …. + cn-1 Xn-1
where the power of X corresponds to the bit position, and the coefficients are 0’s and 1’s.
5
Implementing the Shift
• What is the relation between c(X) and c (i)(X)?
c = c0 c1 c2 …. cn-1. c(X) = c0 + c1X+ …. + cn-1 Xn-1
c(i) = cn-i cn-i+1… cn-1 c0 ..
...cn-i-1
c(i)(X) = cn-i + cn-i+1 X + …. + cn-1 Xi-1
+ c0Xi +…. +cn-i-1 X
n-1
i shifts to the right
Apparently, shifting a bit one place to the right is equivalent to multiplying
the term by X.
6
• Rearranging,
Xic(X) = cn-i Xn +…+ cn-1 Xn+i-1 + c0X
i + c1X i+1 + …+ cn-i-1 Xn-1
• Add to the polynomial the zero-valued sequence:
(cn-i + cn-i ) + (cn-i+1 + cn-i+1 )X + …. + (cn-1 + cn-1 )Xi-1
• This leads to
Xic(X) = cn-i (Xn +1) + cn-i+1 X (Xn +1) +…. + cn-1 Xi-1 (Xn +1) +
cn-i + cn-i+1 X +…. + cn-1 Xi-1 +
c0Xi +c1X i+1 + …. + cn-i-1 X
n-1
• That is: Xic(X) = q(X)(Xn +1) + c(i)(X)
Where q(X)= cn-i + cn-i+1 X +…. + cn-1 Xi-1
Implementing the Shift (2)
• For i shifts:
Xic(X)= c0Xi +c1X
i+1 + ….+ cn-i-1 Xn-1 + cn-i Xn ….+ cn-1 Xn+i-1
7
• Summary:
c(i)(X) is the remainder from dividing Xic(X) by (Xn +1).
c(i)(X) = Rem[Xic(X)/ (Xn +1)] = Xic(X) mod (Xn +1).
• Example: c = 0101110. c(3) = 1100101
Mathematically: c(X) = X + X3 + X4 + X5.
X3c(X) = X4 + X6 + X7 + X8
Rem[X3c(X)/ (X7 +1)] = 1 + X + X4 + X6
c(3) = 1100101
Implementing the Shift (3)
8
The Code Polynomial of Minimum
Degree• TH 5.1: The nonzero code polynomial of minimum degree in
a cyclic code C is unique. Show?
• TH 5.2: Let g(X) = g0 + g1X +….+ gr-1Xr-1 +Xr be the nonzero
code polynomial of minimum degree in an (n,k) cyclic code.
Then the constant term g0 must be equal to 1.
• For the (7,4) code given in the Table 5.1, the nonzero code
polynomial of minimum degree is g(X) = 1 + X + X3
(If not, the sum of the two polynomials will be a code polynomial of
degree less than the minimum. Contradiction)
(If not, then one cyclic shift to the left (n-1 to right) will produce a code
polynomial of degree less than the minimum. Contradiction)
EELE 6338 9
10
Generator Polynomial
Let g(X), the minimum-degree polynomial in C, have degree r
• Since the code is cyclic:
Xg(X), X2g(X),…., Xn-r-1g(X) (Cyclic shift versions) are code
polynomials in C. (Note that deg[Xn-r-1g(X)] = n-1).
• Since the code is linear:
(a0 + a1X + …. + an-r-1 Xn-r-1)g(X) is also a code polynomial, where ai =
0 or 1.
• TH 5.3: A binary polynomial of degree ≤ n-1 is a code
polynomial if and only if it is a multiple of g(X). Show?
If a code polynomial c(X) is not a multiple of g(X), then Rem[c(X)/g(X)]
will be a code polynomial of degree less than the minimum.
11
• All code polynomials are generated from the multiplication
c(X) = a(X)g(X).
deg[c(X)] n-1, deg[g(X)] = r, => deg[a(X)] ≤ n-r-1
There is a total of 2n-r polynomials of degree ≤ n-r-1
Therefore the number of codewords = 2n-r = 2k
Therefore, r = deg[g(X)] = n-k
• Since deg[a(X)] ≤ k-1, the polynomial a(X) may be taken
to be the information polynomial u(X) (a polynomial
whose coefficients are the information bits). Encoding is
performed by the multiplication c(X) = u(X)g(X).
• g(X), generator polynomial, completely defines the code.
Generator Polynomial (2)
12
• TH 5.4:
In an (n,k) cyclic code, there exists one and only
one code polynomial of degree n-k,
1+ g1X + g2X2 + …+ gn-k-1X
n-k-1 +Xn-k
Every code polynomial is a multiple of g(X), and
every binary polynomial of degree n-1 or less that
is a multiple of g(X) is a code polynomial.
Generator Polynomial (3)
13
(7,4) Code Generated by 1+X+X3
Infor. Code Code polynomials
0000 0000000 0 = 0 . g(X)
1000 1101000 1 + X + X3 = 1 . g(X)
0100 0110100 X + X2 + X4 = X . g(X)
1100 1011100 1 + X2 + X3 + X4 = (1 + X) . g(X)
0010 0011010 X2 + X3 + X5 = X2 . g(X)
1010 1110010 1 + X+ X2 + X5 = (1 + X2) . g(X)
0110 0101110 X+ X3 + X4 + X5 = (X+ X2) . g(X)
1110 1000110 1 + X4 + X5 = (1 + X + X2) . g(X)
0001 0001101 X3 + X4 + X6 = X3 . g(X)
14
Infor. Code Code polynomials
1001 1100101 1 + X + X4 + X6 = (1 + X3) . g(X)
0101 0111001 X+ X2 + X3 + X6 = (X+ X3) . g(X)
1101 1010001 1 + X2 + X6 = (1 + X + X3) . g(X)
0011 0010111 X2 + X4 + X5 + X6 = (X2 + X3). g(X)
1011 1111111 1 + X + X2 + X3 + X4 + X5 + X6
= (1 + X2 + X3) . g(X)
0111 0100011 X + X5 + X6 = (X + X2 + X3). g(X)
1111 1001011 1 + X3 + X5 + X6
= (1 + X + X2 + X3) . g(X)
(7,4) Code Generated by 1+X+X3. (2)
15
Properties of the Generator
Polynomial
• TH 5.5: The generator polynomial g(X) of an (n,k) cyclic
code is a factor of Xn+1.
• TH 5.6: If g(X) is a polynomial of degree n-k and is a
factor of Xn+1, then it generates an (n,k) cyclic code.
16
Constructing g(X)
• To construct a cyclic code of length n,
1. find the factors of the polynomial Xn+1.
2. The factor (or product of factors) of degree n-k serves
as the generator polynomial of an (n,k) cyclic code.
• Clearly, a cyclic code of length n does not exist for
every k.
• The code generated this way is guaranteed to be
cyclic. But we know nothing yet about its minimum
distance. The generated code may be good or bad.
17
Cyclic Codes of Length 7
Example (5.1-mod): What cyclic codes of length 7 can be
constructed?
X7+1 = (1 + X)(1 + X + X3)(1 + X2 + X3)
r=n-k k=n-r.
g(X) Code g(X) Code
(1 + X) (7,6) (1 + X)(1 + X + X3) (7,3)
(1 + X + X3) (7,4) (1 + X) (1 + X2 + X3) (7,3)
(1 + X2 + X3) (7,4) (1 + X + X3)(1 + X2 + X3) (7,1)
What if u=(1010) u= 1 + X2 v(x)= 1 + X + X2 + X5
• 1110010
18
Encoding of Systematic Cyclic Codes
c(X) = b(X) + Xn-k u(X) a(X)g(X) = b(X) + Xn-k u(X)
Xn-k u(X)= a(X)g(X) + b(X)
Or b(X) = Rem[Xn-k u(X)/g(X)]
Encoding Procedure (Systematic code):
1. Multiply u(X) by Xn-k
2. Divide Xn-k u(X) by g(X), obtaining the remainder b(X).
3. Add b(X) to Xn-k u(X), obtaining c(X) in systematic form.
uk-1…. u2 u1u0 bn-k-1 …. b2 b1 b0
b(X) = b0 + b1X+….+bn-k-1Xn-k-1 u(X) = u0+u1X+ ….+uk-1X
k-1
, then c(X) = b(X) + Xn-k u(X)
19
Example
Consider the (7,4) cyclic code generated by g(X) = 1 + X +
X3. Find the systematic codeword for the message 1001.
Encoding of Systematic Cyclic Codes (2)
Systematic
u(X) = 1 + X3
X3u(X) = X3 + X6
b(X) =
Rem[X3u(x)/g(X)] = X + X2
Therefore, c = 0111001
Not Systematic
u(X) = 1 + X3
c(X) = u(x)g(X) = 1+X + X4+X6
Therefore, c = 1100101
20
Generator Matrix of Cyclic Codes
• Formed as follows:
– 1st row: coefficients of g(X) followed by k-1 zeros
Other rows are the k-1 cyclic shifts of first row
• The matrix can be arranged in systematic form
by row operations.
EELE 6338 21
Generator Matrix of Cyclic Codes (2)
Generator Matrix in Systematic form
EELE 6338 22
• This mean, you should determine the reminders of
Xn-k+i (for i=0,1,…k-1) over g(X) and then formulate
in G.
Example 5.4
EELE 6338 23
24
Encoder Circuit
• Switch Down & Gate ON: k message bits are shifted into
the channel. The parity bits are formed in the register.
• Switch Up & Gate OFF: Contents of register are shifted
into the channel.
g2g1
++ + +
Gate
gr-1
25
(7,4) Encoder Based on 1 + X + X3
Input 1 1 0 1
Register : 000 110 101 100
100initial 1st shift 2nd shift 3rd shift 4th shift
Codeword: 1 0 0 1 0 1 1
+ +
Gate
Check this: https://www.youtube.com/watch?v=JQ6Ad4fCGIo
26
Decoding of Cyclic Codes
1. Syndrome computation
2. Associating the syndrome to the error pattern
3. Error correction• Refer to https://www.youtube.com/watch?v=d5u9hbVvT4o
27
Syndrome Computation• Let assume that the received word is r0 r1 …. rn-1 :
– r(X) = r0 + r1X +….+ rn-1Xn-1
• If r(X) is a correct codeword, it is divisible by g(X).
Otherwise:
– r(X) = q(X)g(X) + s(X). and deg[s(X)] ≤ n-k-1.
– s(X) is called the syndrome polynomial.
• The syndrome polynomial depends on the error pattern
only. Show?
• s(X) is obtained by shifting r(X) into a divider-by-g(X)
circuit. The register contents are the syndrome bits.
s(X) = Rem[r(X)/g(X)] = Rem[ {a(X)g(X) + e(X)}/g(X)] = Rem[e(X)/g(X)]
Syndrome Circuit
EELE 6338 28
29
Circuit for Syndrome Computation
++
Gate
r = 0010110
Shift Input Register contents
0 0 0 (initial state)
1 0 0 0 0
2 1 1 0 0
3 1 1 1 0
4 0 0 1 1
5 1 0 1 1
6 0 1 1 1
7 0 1 0 1 (syndrome s)
30
More on Syndrome Computation
• TH5.8 Let s(X) be the syndrome of a received polynomial r(X)
= r0 + r1X +….+ rn-1Xn-1 . Then the remainder resulting from
dividing Xs(X) by g(X) is the syndrome of r(1)(X), which is a
cyclic shift of r(X). Proof?
• Proof: r(X) = r0 + r1X +….+ rn-1Xn-1
r(1)(X) = rn-1 + r0X +….+ rn-2Xn-1 = rn-1 + Xr(X) + rn-1X
n
= rn-1(Xn+1) + Xr(X)
c(X)g(X) + y(X) = rn-1 g(X)h(X)+ X{a(X)g(x) + s(X)}
where y(X) is the syndrome of r(1)(X) .
Xs(X) = {c(X) + Xa(X) + rn-1 h(X)}g(X) + y(X)
Therefore, Syndrome of r(1)(X)= Rem[Xs(X)/g(X)].
31
• Note: for simplicity of notation, let Rem[Xs(X)/g(X)] bedenoted by s(1)(X).
– s(1)(X) is NOT a cyclic shift of s(X), but the syndrome of r(1)(X)which is a cyclic shift of r(X).
• Example:
r(X) = X2 + X4 + X5; g(X) = 1 + X + X3. Find s(1)(X) ?
s(X) = Rem[r(X)/g(X)] = 1 + X2
r(1)(X) = X3 + X5 + X6
s(1)(X) = Rem[r(1)(X)/g(X)] = 1 (polynomial)
Also, s(1)(X) = Rem[Xs(X)/g(X)] = 1.
• N.B. It follows from TH 5.8 that, in general, the remainders(i)(X) resulting from dividing Xis(X) by g(X) is the
syndrome of r(i)(X).
More on Syndrome Computation (2)
32
Shift Input Register contents
0 0 0 (initial state)
1 0 0 0 0
2 1 1 0 0
3 1 1 1 0
4 0 0 1 1
5 1 0 1 1
6 0 1 1 1
7 0 1 0 1 (syndrome s)
8 (input gate off) - 1 0 0 (syndrome s(1)
)
9 - 0 1 0 (syndrome s(2)
)
++
Gate
Gater = 0010110
More on Syndrome Computation (3)
33
More on Syndrome Computation (4)
• Let r(X) = r0 + r1X +….+ rn-1Xn-1 has the syndrome s(X).
• Then r(1)(X) = rn-1 + r0 X + ….+ rn-2Xn-1 has the syndrome:
s(1)(X) = Rem[r(1)(X)/g(X)].
• Define r1 (X) = r(X) + Xn-1 = r0 + r1X +….+ (rn-1+1)Xn-1
• The syndrome of r1 (X), call it s1 (X):
s1 (X)= Rem[{r(X)+ Xn-1}/g(X)] = s(X) + Rem[Xn-1/g(X)]
r1(1)(X), which is one cyclic shift of r1 (X), has the syndrome
s1(1)(X) = Rem[X s1 (X)/g(X)] = Rem[Xs(X)/g(X)+ Xn/g(X)]
= s(1)(X) + 1 (since Xn +1 = g(X)h(X))
• Therefore, adding “1” to the left of R removes the effect ofthe erroneous digit on the syndrome
• Important
• https://www.youtube.com/watch?v=dW3NhK2oWcc
35
General Decoding Circuit
Important : Refer to the CyclicDecoding.pdf for the explanation and worked example
• Again , don’t forget, go to the
CyclicDecoding.pdf for the explanation and
worked example regarding the full-image of
the decoding that illustrated in the class
session.
Cyclotomic Coset • The cyclotomic coset of 𝑞 modulo 𝑛 that contain 𝑖 is
defined as follows:
𝐶𝑖 = 𝑖. 𝑞𝑖 𝑚𝑜𝑑 − 𝑛 ∈ 𝑍𝑛: 𝑗 = 0,1,⋯
• When 𝐶𝑖1 , ⋯ , 𝐶𝑖𝑡 are disjoint sets and 𝑗=1ڂ𝑡 𝐶𝑖𝑗 = 𝑍𝑛
the set {𝑖1, ⋯ , 𝑖𝑡} is called complete set of representatives
of cyclotomic coset.
37
• Example 1: Find the cyclotomic cosets of 2 mod-7. n=7
and q=2.
• 𝐶𝑖 = 𝑖. 𝑞𝑗 𝑚𝑜𝑑 − 𝑛 ∈ 𝑍𝑛: 𝑗 = 0,1,⋯ =
𝑖. [1,2,4,8,⋯ ] 𝑚𝑜𝑑 − 7
• 𝐶0 = 0 , 𝐶1 = 1,2,4 = 𝐶2 = 𝐶4, 𝐶3 = 3,5,6 = 𝐶5 = 𝐶6• Complete sets 0,1,3 𝑜𝑟 0,2,5 … . .
How to Factorize 𝒙𝒏 + 𝟏 over GF(2)
• Step 1: Find the complete set of representatives of
cyclotomic coset of 2 mod-n {𝑆𝑖1 , 𝑆𝑖2 , ⋯ , 𝑆𝑖𝑡}.
• Step2: Find the minimum number m such that
𝑅𝑒𝑚2𝑚−1
𝑛= 0.
• Step3: Construct the field GF( 2𝑚) using the
primitive polynomials from the Table 2.7 page 42.
Note that for m=3,4,6, and 15
primitive polynomial=1 + 𝑥 + 𝑥𝑚
EELE 6338 38
• Step 4: Obtain the minimal polynomials Φ2𝑚−1 .𝑆𝑖
𝑛
of the elements 𝛼2𝑚−1 .𝑆𝑖
𝑛 for every element in the
complete set found in step1.
Recall that : 𝛼𝑥 and its conjugates are roots of the
minimal polynomial.
• Step 5: Evaluate 𝑥𝑛 + 1 = ς𝑖=1𝑡 Φ
2𝑚−1 .𝑆𝑖𝑛 (𝑥)
EELE 6338 39
Factorization of 𝒙𝟕 + 𝟏 in EX.5.1
• Form Example 1 the complete set 𝑆 = 𝑠1, 𝑠2, 𝑠3= {0,1,3}.
• 𝑅𝑒𝑚2𝑚−1
7= 0 → 𝑚 = 3.
• We need to construct the field GF(8)=GF(23) using
the generator polynomial 1 + 𝑥 + 𝑥3 .
Let 𝛼 to be root fro the primitive polynomial 1+ 𝛼 + 𝛼3 = 0 𝛼3 = 1 + 𝛼.
Elements of the field : 0, 1, 𝛼, 𝛼2, 𝛼3 = 𝛼. 𝛼2 = 1+ 𝛼, 𝛼4 = 𝛼2 + 𝛼, 𝛼5 = 𝛼2 + 𝛼 + 1, 𝑎𝑛𝑑 𝛼6= 𝛼2 + 1.
EELE 6338 40
• We need to find Φ2𝑚−1 .𝑆𝑖
𝑛 (x)= Φ23−1 .𝑆𝑖
7
where 𝑆 = 𝑠1, 𝑠2, 𝑠3 = {0,1,3}.
Φ 0 (x), Φ 1 (x), Φ 3 (x)
Φ 0 (x)= x + 𝛼0 = x + 1
Φ 1 (x)= x + 𝛼1 x + 𝛼2 x + 𝛼4 = 1 + x + x3
Φ 3 (x)= x + 𝛼3 x + 𝛼5 x + 𝛼6 = 1 + x2 + x3
X7+1 = (1 + X)(1 + X + X3)(1 + X2 + X3)
EELE 6338 41
Factorization of 𝒙𝟕 + 𝟏 in EX.5.1 (2)
42
Error Trapping Decoders
• If the errors (that we intend to correct) can be
trapped in the last n-k locations, then it can be
shown that the contents of R is identical to the
error pattern, and therefore correction can be
done in one step.
• So, error trapping decoders can correct the
majority of correctable patterns at a faster rate.
EELE 6338
43
Shortened Cyclic Codes
• Consider an (n,k) cyclic code.
• Select the codewords for which the l leading high-order
information digits are zeros.
• Delete those zero digits. This produces (n-l,k-l) linear
code, but not cyclic.
• A shortened cyclic code has at least the same error-
correcting capability of the original code.
• The same encoder circuit of the original code can be used.
• The same decoder circuit of the original code can be used
with little modification.
EELE 6338
Next Lecture
• Chapter 6 : Binary BCH Codes.
EELE 6338 44