Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
CYCLIC CODES
Dr. Musbah Shaat EELE 6338 08/10/2012
Outline
EELE 6338 2
Definition
• An (n,k) linear code C is cyclic if every cyclic
shift of a codeword in C is also a codeword in
C.
If c c c …. c c is a codeword, thenIf 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.
3
Example
• The (7,4) Hamming code discussed before is cyclic:
1010001 1110010 0000000 1111111
1101000 01110011101000 0111001
0110100 1011100
0011010 0101110
0001101 0010111
1000110 1001011
0100011 1100101
4
Code Polynomial
• Let c = c0 c1 c2 …. cn-1.
The code polynomial of c:c(X) = c0 + c1X+ c2 X
2 + …. + cn-1 X
n-1
where the power of X corresponds to the bit
position, and the coefficients are 0’s and 1’s.position, and the coefficients are 0’s and 1’s.
• 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.
5
deg[ ]c(X) ≤ −n 1
Implementing the Shift
Let c = c0 c1 c2 …. cn-1
and c(i) = cn-i cn-i+1 … c
n-1 c0 …. cn-i-1 (i shifts to the right)
Then, c(X) = c0 + c1X+ c2 X2 + …. + c
n-1 Xn-1 , and
c (i)(X) = c + c X + …. + c Xi-1 + c Xi +…. +c Xn-1c (i)(X) = cn-i + c
n-i+1 X + …. + cn-1 X
i-1 + c0Xi +…. +cn-i-1 X
n-1
What is the relation between c(X) and c (i)(X)?
Apparently, shifting a bit one place to the right is equivalent
to multiplying the term by X. For i shifts:
Xic(X)= c0Xi +c1X i+1 + ….+ cn-i-1 X
n-1 + cn-i X
n ….+ cn-1 X
n+i-1
6
Implementing the Shift (�)
Rearranging,
Xic(X) = cn-i X
n +…+ cn-1 X
n+i-1 + c0Xi + c1X i+1 + …+ cn-i-1 X
n-1
Add to the polynomial the zero-valued sequence:
(cn-i + c
n-i ) + (cn-i+1 + c
n-i+1 )X + …. + (cn-1 + c
n-1 )Xi-1(c
n-i + cn-i ) + (c
n-i+1 + cn-i+1 )X + …. + (c
n-1 + cn-1 )X
i-1
Xic(X) = cn-i (X
n +1) + cn-i+1 X (Xn +1) +…. + c
n-1 Xi-1 (Xn +1) +
cn-i + c
n-i+1 X +…. + cn-1 X
i-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 + c
n-i+1 X +…. + cn-1 X
i-1
7
Implementing the Shift (�)
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 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
8
The Code Polynomial of Minimum Degree
• TH 5.1: The nonzero code polynomial of minimum degree
in a cyclic code C is unique.(If not, the sum of the two polynomials will be a code polynomial of
degree less than the minimum. Contradiction)
• TH 5.2: Let g(X) = g + g X +….+ g Xr-1 +Xr be the nonzero • 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.(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)
• For the (7,4) code given in the Table 5.1, the nonzero code
polynomial of minimum degree is g(X) = 1 + X + X3
9
EELE 6338 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) are code
polynomials in C. (Note that deg[Xn-r-1g(X)] = n-1).
• Since the code is linear: Since the code is linear:
(a0 + a1X + …. + an-r-1 X
n-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).(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. Contradiction)
11
Generator Polynomial (�)
• 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 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.
12
• TH 5.4:
In an (n,k) cyclic code, there exists one and
only one code polynomial of degree n-k,
1+ g1X + g
2X2 + …+ g
n-k-1Xn-k-1 +Xn-k1+ g
1X + g
2X2 + …+ g
n-k-1Xn-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.
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)0100 0110100 X + X + X = 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
(7,4) Code Generated by 1+X+X3 (�)
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)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)
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. of X +1, then it generates an (n,k) cyclic code.
16
Constructing g(X)
(1) To construct a cyclic code of length n, 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.cyclic code of length n does not exist for every k.
(3) 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?
Rembember r=n-k � k=n-r.
X7+1 = (1 + X)(1 + X + X3)(1 + X2 + X3)X +1 = (1 + X)(1 + X + X )(1 + X + X )
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
Systematic: b0 b1 b2 …. bn-k-1 u0 u1 u2 …. u
k-1
b(X) = b0 + b1X+….+bn-k-1Xn-k-1, u(X) = u0+u1X+ ….+u
k-1Xk-1
then 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)Xn-k u(X)= a(X)g(X) + b(X)
Or b(X) = Rem[Xn-k u(X)/g(X)]
Encoding Procedure:
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.
19
Encoding of Systematic Cyclic Codes (�)
Example
Consider the (7,4) cyclic code generated by g(X) = 1 + X + X3.
Find the systematic codeword for the message 1001.
u(X) = 1 + X3u(X) = 1 + X3
X3u(X) = X3 + X6
b(X) = Rem[X3u(x)/g(X)] = X + X2
Therefore, c = 0111001
20
Generator Matrix of Cyclic Codes
• The generator matrix of a cyclic code can be
formed as follows:
1st row: Coefficients of g(X) followed by k-1
zeroszeros
Other rows are the k-1 cyclic shifts of first row
• The matrix can be arranged in systematic form
by row operations.
21
Generator Matrix of Cyclic Codes (�)
EELE 6338 22
Generator Matrix in Systematic form
EELE 6338 23
Example 5.4
EELE 6338 24
Encoder Circuit
g2
g1
++ + +
Gate
gr-1
• 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.
25
(7,4) Encoder Based on 1 + X + X3
+ +
Gate
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
26
Decoding of Cyclic Codes
• STEPS:
(1) Syndrome computation
(2) Associating the syndrome to the error pattern(2) Associating the syndrome to the error pattern
(3) Error correction
27
Syndrome Computation
• Received word: 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).
• deg[s(X)] ≤ n-k-1.
• s(X) is called the syndrome polynomial.• s(X) is called the syndrome polynomial.
• s(X) = Rem[r(X)/g(X)] = Rem[ {a(X)g(X) + e(X)}/g(X)] =
Rem[e(X)/g(X)]
• The syndrome polynomial depends on the error pattern
only.
• s(X) is obtained by shifting r(X) into a divider-by-g(X) circuit.
The register contents are the syndrome bits.
28
Syndrome Circuit
EELE 6338 29
Circuit for Syndrome Computation
++
Gate
r = 0010110
Shift Input Register contents
30
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)
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: r(X) = r0 + r1X +….+ rn-1Xn-1
r(1)(X) = rn-1 + r0X +….+ r
n-2Xn-1 = rn-1 + Xr(X) + r
n-1Xnr(1)(X) = rn-1 + r0X +….+ r
n-2Xn-1 = rn-1 + Xr(X) + r
n-1Xn
= 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)]. Q.E.D.
31
More on Syndrome Computation (�)
• Note: for simplicity of notation, let Rem[Xs(X)/g(X)] be denoted 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
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.
• It follows from TH 5.8 that, in general, the remainder s(i)(X) resulting from dividing Xis(X) by g(X) is the syndrome of r(i)(X).
32
More on Syndrome Computation
(�)
Shift Input Register contents
++
Gate
Gate
r = 0010110
33
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)
)
General Decoding Circuit
34
Meggit Decoder
1. Shift r(X) into the buffer B and the syndrome register R simultaneously. Once r(X) is completely shifted in B, R will contain s(X), the syndrome of r(X).
2. Based on the contents of R, the detection circuit yields the output e (0 or 1). the output e (0 or 1).
3. During the next clock cycle:
(a) Add e to the rightmost bit of B while shifting the contents of B. (The rightmost bit of B may be read out). Call the modified content of B: r1
(1)(X).
35
Meggit Decoder (�)
(b) Add e to the left of R while shifting the contents of R.
The modified content of R is s1(1)(X), the syndrome of r1
(1)(X)
[will be shown soon].
4. Repeat steps 2-3 n times.
36
More on Syndrome ComputationLet r(X) = r0 + r1X +….+ r
n-1Xn-1 has the syndrome s(X). Then
r(1)(X) = rn-1 + r0 X + ….+ r
n-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):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 of the erroneous digit on the syndrome
37
Worked Example
Consider the (7,4) Hamming code generated by 1+X+X3.
Error pattern Syndrome polynomial. Syndrome vector
X6
1 + X2
1 0 1
X5
1 + X + X2
1 1 1
X4
X + X2
0 1 1
Let c = 1 0 0 1 0 1 1 and r = 1 0 1 1 0 1 1
38
X4
X + X2
0 1 1
X3
1 + X 1 1 0
X2
X2
0 0 1
X1
X 0 1 0
X0
1 1 0 0
Cyclic Decoding of the (7,4) Code
39
40