Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Error Control Coding

1Exercise 1 Hamming Distance

Consider the following error control code

MessageCodeword
s1s_1c1=00000c_1 = 00000
s2s_2c2=10011c_2 = 10011
s3s_3c3=11100c_3 = 11100
s4s_4c4=00111c_4 = 00111

Requirements:

1.1Solution

a). compute the minimum Hamming distance and indicate how many errors it can detect and how many errors it can correct, with the nearest neighbor decoding algorithm

The Hamming distance between two codewords is the number of bit differences between them. For example, the Hamming distance between 000 and 110 is dH=2d_H = 2, because the first two bits are different.

The minimum Hamming distance of a code, dHmind_{H_{min}}, is is the smallest Hamming distance between any pair of codewords. It determines the number of errors the code can detect and correct using the nearest neighbor approach.

Therefore, we first have to compute the Hamming distance between all pairs of codewords, and find the minimum value.

dH(c1,c2)=3( the first and last two bits are different)dH(c1,c3)=3dH(c1,c4)=3dH(c2,c3)=4dH(c2,c4)=2dH(c3,c4)=4\begin{align*} d_H(c_1, c_2) &= 3 (\textrm{ the first and last two bits are different}) \\ d_H(c_1, c_3) &= 3 \\ d_H(c_1, c_4) &= 3 \\ d_H(c_2, c_3) &= 4 \\ d_H(c_2, c_4) &= 2 \\ d_H(c_3, c_4) &= 4 \end{align*}

The minimum Hamming distance is dHmin=2d_{H_{min}} = 2, between c2c_2 and c4c_4.

The number of errors the code can detect is:

ed=dHmin1e_d = d_{H_{min}} - 1

so this code can detect 21=12 - 1 = 1 errors.

The number of errors the code can correct is:

ec=dHmin12e_c = \lfloor \frac{d_{H_{min}} - 1}{2} \rfloor

so this code can correct 212=0\lfloor \frac{2 - 1}{2} \rfloor = 0 errors.

b). considering two received codewords, r1=11100\mathbf{r_1} = 11100 and r2=01111\mathbf{r_2} = 01111, perform decoding and say if there are errors, and if so then correct the errors (find the correct codeword and indicate where the errors are located)

The nearest neighbor decoding algorithm works as follows:

  1. To detect if there are errors, we check if the received codeword is one of the codewords or not;if it is not, then there exist errors;

  2. To fix errors, we compute the Hamming distance between the received codeword and all codewords, and select the codeword with the minimum distance. We assume that this should be the correct codeword; the differences from the received codeword are the errors.

Here, we take each received codeword separately.

r1=11100\mathbf{r_1} = 11100 is actual c3c_3, so there are no errors.

r2=01111\mathbf{r_2} = 01111 is not in the table of codewords, so there are errors. We compute the Hamming distance between r2\mathbf{r_2} and all codewords:

dH(r2,c1)=4dH(r2,c2)=3dH(r2,c3)=3dH(r2,c4)=1\begin{align*} d_H(r_2, c_1) &= 4 \\ d_H(r_2, c_2) &= 3 \\ d_H(r_2, c_3) &= 3 \\ d_H(r_2, c_4) &= 1 \end{align*}

The minimum distance is dH(r2,c4)=1d_H(r_2, c_4) = 1, so the correct codeword is c4=00111c_4 = 00111, and the error is in the second bit, which was 0 in the codeword, but was received as 1.

c). Give an example of errors the code cannot detect, and another example of errors it can detect but it cannot correct, using the nearest neighbor decoding algorithm

The code fails to detect errors if and only if the errors transform one codeword into another codeword. For example, when we send c2=10011c_2 = 10011 and there are two errors in the first and third positions, we receiver r=00111\mathbf{r} = 00111, which is actually c4c_4, so the code believes it to be correct.

An example of errors the code can detect but cannot correct properly is when the code detects the errors, but the nearest codeword is not the correct one, or there are two codewords equally close to the received codeword. For example, suppose we send c2=10011c_2 = 10011 and there is an error in the first position, so we receive r=00011\mathbf{r} = 00011. This is not in the codeword table, so the code can detect that errors exist. When computing the nearest codeword, we have two codewords equally close to the received codeword:

dH(r,c1)=2dH(r,c2)=1dH(r,c3)=5dH(r,c4)=1\begin{align*} d_H(r, c_1) &= 2 \\ d_H(r, c_2) &= 1 \\ d_H(r, c_3) &= 5 \\ d_H(r, c_4) &= 1 \end{align*}

The code will choose either c2c_2 or c4c_4 as the nearest codeword, but it cannot know which one is the correct one, so sometimes it will choose the wrong one and fail.

2Exercise 2 Hamming Distance

a). Design a block code consisting of 4 codewords, with minimum codeword length, which is able to detect 3 errors in a codeword.

b). Design a block code consisting of 4 codewords, with minimum codeword length, which is able to correct 2 errors in a codeword.

2.1Solution

a). Design a block code consisting of 4 codewords, with minimum codeword length, which is able to detect 3 errors in a codeword

To detect 3 errors in a codeword, we need the minimum Hamming distance to be at least 4. Therefore we need to come up with 4 codewords, such that the Hamming distance between any pair of them is at least 4. There is no rule here, we just use our imagination, and if we can’t find a solution, we can try to increase the codeword length.

One example:

MessageCodeword
s1s_1c1=000000c_1 = 000000
s2s_2c2=111100c_2 = 111100
s3s_3c3=110011c_3 = 110011
s4s_4c4=001111c_4 = 001111

b). Design a block code consisting of 4 codewords, with minimum codeword length, which is able to correct 2 errors in a codeword

To correct 2 errors in a codeword, we need the minimum Hamming distance to be at least 5, since 512=2\lfloor \frac{5 - 1}{2} \rfloor = 2.

Therefore we need to come up with 4 codewords, such that the Hamming distance between any pair of them is at least 5. One example:

MessageCodeword
s1s_1c1=00000000c_1 = 00000000
s2s_2c2=11111100c_2 = 11111100
s3s_3c3=00011111c_3 = 00011111
s4s_4c4=11100011c_4 = 11100011

3Exercise 3 Linear Block Codes

Consider a systematic code with generator matrix

[G]=[1000110010011100101010001011][G] = \begin{bmatrix} 1 & 0 & 0 & 0 & 1 & 1 & 0 \\ 0 & 1 & 0 & 0 & 1 & 1 & 1 \\ 0 & 0 & 1 & 0 & 1 & 0 & 1 \\ 0 & 0 & 0 & 1 & 0 & 1 & 1 \\ \end{bmatrix}

3.1Solution

a). Compute the codeword for sending the information bits i2=[1011]\mathbf{i_2} = [1 0 1 1]

When using a generator matrix [G][G], we compute the codeword by multiplying the information word with the generator matrix:

Computing the codeword by multiplying with [G]

Figure 1:Computing the codeword by multiplying with [G][G]

Note how the first part of GG is the identity matrix, and this makes the first 4 bits of the codeword the same as the information word.

b). Compute the control matrix [H][H]

When the generator matrix is in the form:

[G]=[IkQ][G] = \begin{bmatrix} I_k & Q \end{bmatrix}

then the control matrix is given by:

[H]=[QTInk][H] = \begin{bmatrix} Q^T & I_{n-k} \end{bmatrix}

where IkI_k is the identity matrix of size kk, QQ is the other part of the generator matrix, QTQ^T is Q transposed, and InkI_{n-k} is the identity matrix of size nkn-k.

In our case, we have:

Computing the control matrix [H] from the generator matrix [G] of a systematic code

Figure 2:Computing the control matrix [H][H] from the generator matrix [G][G] of a systematic code

c). We receive a sequence r=1010111\mathbf{r} = 1010111, which was encoded with this code. Find if there are errors in the received data, and, if yes, perform correction and retrieve the transmitted information bits

We first compute the syndrome z=[H]rT\mathbf{z} = [H] \cdot \mathbf{r}^T:

z=[111010011010100111001][1010111]=[100]\mathbf{z} = \begin{bmatrix} 1 & 1 & 1 & 0 & 1 & 0 & 0 \\ 1 & 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 & 0 & 1 \\ \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 0 \\ 1 \\ 0 \\ 1 \\ 1 \\ 1 \\ \end{bmatrix} = \begin{bmatrix} 1 \\ 0 \\ 0 \\ \end{bmatrix}

If z=0\mathbf{z} = 0, then there are no errors. Here, z0\mathbf{z} \neq 0, so there are errors detected.

To correct the errors, we need to find the error pattern e\mathbf{e} such that z=[H]eT\mathbf{z} = [H] \cdot \mathbf{e}^T. For example, if there would be an error in the first bit, then we have:

[111010011010100111001][1000000]=[110]\begin{bmatrix} 1 & 1 & 1 & 0 & 1 & 0 & 0 \\ 1 & 1 & 0 & 1 & 0 & 1 & 0 \\ 0 & 1 & 1 & 1 & 0 & 0 & 1 \\ \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \\ 0 \\ \end{bmatrix}

This is not equal to our z\mathbf{z}, so the error is not in the first bit. We go on and try an error in the second bit, and so on. We can store the results in a look-up table, until we find the error pattern that matches the syndrome z\mathbf{z}:

Error patternSyndrome
[1000000][1 0 0 0 0 0 0][110][1 1 0]
[0100000][0 1 0 0 0 0 0][111][1 1 1]
[0010000][0 0 1 0 0 0 0][101][1 0 1]
[0001000][0 0 0 1 0 0 0][011][0 1 1]
[0000100][0 0 0 0 1 0 0][100][1 0 0]

It is easy to see that for one error bit on the kk-th position the result is the kk-th column [H][H]. Thus, since our syndrome z=[100]T\mathbf{z} = [1 0 0]^T is the 5th column of [H][H], the error is in the 5th position, so we have e=[0000100]\mathbf{e} = [0 0 0 0 1 0 0].

Therefore the error is on the 5th position, we change that bit and find the correct codeword:

c=re=[1010011]\mathbf{c} = \mathbf{r} \oplus \mathbf{e} = [1 0 1 0 0 1 1]

Remembering from a). that the first 4 bits of the codeword are the information bits, we find the transmitted information bits are:

i=[1010]\mathbf{i} = [1 0 1 0]

d). Find out how many errors this code can detect, and how many it can correct

This is from the theory of linear block codes.

A code can detect up to ede_d errors if and only if the sum of any ede_d or fewer columns from [H][H] is not equal to the zero vector. Here, we have:

So, our code can detect up to ed=2e_d = 2 errors.

A code can correct up to ece_c errors if and only if the sum of any ece_c or fewer columns is always unique (not equal to the sum of any other ece_c or fewer columns).

Here, we have:

So, our code can correct up to ec=1e_c = 1 error.

4Exercise 4 Hamming Codes - encoding

Compute the codewords for transmitting the information words i1=[1001]\mathbf{i_1} = [1 0 0 1] with the Hamming (7,4) code, and i2=[1110]\mathbf{i_2} = [1 1 1 0] with the Hamming (8,4) SECDED code.

4.1Solution

Hamming codes are linear block codes, but we won’t use the generator matrix because it is hard to remember. Instead, for the Hamming code, we need to know (from the theory) the control matrix [H][H] and the structure of the codeword.

a). Hamming (7,4) code

The [H][H] matrix of a Hamming code contains all the numbers from 1 to nn in binary, written as columns, from [0...01][0 ... 0 1] to [11...1][1 1 ... 1].

For the Hamming (7,4) code, we have all the numbers from 1 to 7 in binary, written on 3 bits, as columns:

The control matrix [H] of the Hamming (7,4) code and the structure of the codeword

Figure 3:The control matrix [H][H] of the Hamming (7,4) code and the structure of the codeword

The codeword has the same length as [H][H], and the bits corresponding to the columns with a single 1 in the column are the control bits, and the others are information bits. Thus, for the Hamming (7,4) code, bits 1, 2, and 4 are control bits, and bits 3, 5, 6, and 7 are information bits.

We can write the codeword as:

c=[c1c2i3c4i5i6i7]\mathbf{c} = [c_1 c_2 i_3 c_4 i_5 i_6 i_7]

where ii or cc means information or control bit, and the index is the position in the codeword.

To find the codeword, we replace the information bits in the codeword with the actual values, and we put the condition that the syndrome z=[H]cT\mathbf{z} = [H] \cdot \mathbf{c}^T is zero, since this is the condition for a valid codeword.

Computing the codeword for the Hamming (7,4) code

Figure 4:Computing the codeword for the Hamming (7,4) code

Writing the equations, we have:

c3001=0=>c3=1c2101=0=>c2=0c1101=0=>c1=0\begin{align*} c_3 \oplus 0 \oplus 0 \oplus 1 &= 0 => c_3 = 1 \\ c_2 \oplus 1 \oplus 0 \oplus 1 &= 0 => c_2 = 0 \\ c_1 \oplus 1 \oplus 0 \oplus 1 &= 0 => c_1 = 0 \\ \end{align*}

So the codeword is:

c=[0011001]\mathbf{c} = [0 0 1 1 0 0 1]

b). Hamming (8,4) SECDED code

The SECDED code is an extension of the Hamming code, which adds an extra control bit c0c_0 in front, which is the parity bit of the whole codeword.

Therefore, we can compute the codeword for the Hamming (7,4) and then add the parity bit in front.

Computing another codeword for the Hamming (7,4) code

Figure 5:Computing another codeword for the Hamming (7,4) code

c3110=0=>c3=0c2110=0=>c2=0c1110=0=>c1=0\begin{align*} c_3 \oplus 1 \oplus 1 \oplus 0 &= 0 => c_3 = 0 \\ c_2 \oplus 1 \oplus 1 \oplus 0 &= 0 => c_2 = 0 \\ c_1 \oplus 1 \oplus 1 \oplus 0 &= 0 => c_1 = 0 \\ \end{align*}

So the Hamming (7,4) codeword is c=[0010110]\mathbf{c} = [0 0 1 0 1 1 0]

For the Hamming (8,4) SECDED code, we compute the parity bit of the above sequence, which is 1 in this case, and we add it in front as a new control bit c0c_0:

c=[10010110]\mathbf{c} = [1 0 0 1 0 1 1 0]

5Exercise 5 Hamming Codes - decoding

We receive a sequence r=1010111\mathbf{r} = 1010111, which was encoded with the Hamming (7,4) code. Find if there are errors in the received data, and, if yes, perform correction and retrieve the transmitted information bits.

5.1Solution

We need to know the control matrix [H][H] of the Hamming (7,4) code, and the structure of the codeword, as in the previous exercise.

To check if there are errors, we compute the syndrome z=[H]rT\mathbf{z} = [H] \cdot \mathbf{r}^T, and we check if z=0\mathbf{z} = 0 or not.

z=[000111101100111010101][1010111]=[110]\mathbf{z} = \begin{bmatrix} 0 & 0 & 0 & 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ 1 & 0 & 1 & 0 & 1 & 0 & 1 \\ \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 0 \\ 1 \\ 0 \\ 1 \\ 1 \\ 1 \\ \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \\ 0 \\ \end{bmatrix}

Since z0\mathbf{z} \neq 0, there are errors in the received data.

To fix the errors, the syndrome gives the position of the error bit, in binary. Here, we have z=[110]T\mathbf{z} = [1 1 0]^T, which is the binary representation of the number 6. The error in on the 6th position, so we have e=[0000010]\mathbf{e} = [0 0 0 0 0 1 0].

The correct codeword is found by toggling back the 6th bit of the received codeword:

c=re=[1010101]\mathbf{c} = \mathbf{r} \oplus \mathbf{e} = [1 0 1 0 1 0 1]

For Hamming(7,4) the information bits are the bits in the positions 3, 5, 6, and 7, so we have:

i=[1101]\mathbf{i} = [1 1 0 1]

6Exercise 6 Hamming SECDED Codes - decoding

We receive a sequence r=10101011\mathbf{r} = 10101011, which was encoded with the Hamming (8,4) SECDED code. Find if there are errors in the received data, and, if yes, perform correction and retrieve the transmitted information bits.

6.1Solution

We need to know the control matrix [H][H] of the Hamming (8,4) SECDED code, and the structure of the codeword.

The control matrix [H~][\tilde{H}] of the SECDED code is the [H][H] for the normal Hamming code, but with an extra row of 1s at the top, and an extra column of 0s in front.

The control matrix [\tilde{H}] of the Hamming (8,4) SECDED code

Figure 6:The control matrix [H~][\tilde{H}] of the Hamming (8,4) SECDED code

The codeword is the normal Hamming codeword, but with an extra control bit c0c_0 in front:

c=[c0c1c2i3c4i5i6i7]\mathbf{c} = [c_0 c_1 c_2 i_3 c_4 i_5 i_6 i_7]

We compute the syndrome in the same way as before, but note that it has one more bit now:

z=[H~]rT=[11111111000011110011001101010101][10101011]=[1111]\mathbf{z} = [\tilde{H}] \cdot \mathbf{r}^T = \begin{bmatrix} 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\ 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1\\ \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 0 \\ 1 \\ 0 \\ 1 \\ 0 \\ 1 \\ 1 \\ \end{bmatrix} = \begin{bmatrix} 1 \\ 1 \\ 1 \\ 1 \\ \end{bmatrix}

The decoding algorithm is:

  1. If z=0\mathbf{z} = 0, then there are no errors;

  2. If z0\mathbf{z} \neq 0, then there are errors

    1. If the first bit of z\mathbf{z} is 1, then there is a single error, and its position is given by the other three bits in z\mathbf{z}, just like in normal Hamming codes; (position goes from 0 to 7 now, 0 = first bit, 7 = last bit).

    2. If the first bit of z\mathbf{z} is 0, then there are two errors, and we cannot correct them, so we don’t do anything.

Here, the first bit of z\mathbf{z} is 1, so there is a single error, on position 111=7111 = 7, which means the last bit. The correct codeword is:

c=re=[10101011][00000001]=[10101010]\mathbf{c} = \mathbf{r} \oplus \mathbf{e} = [1 0 1 0 1 0 1 1] \oplus [0 0 0 0 0 0 0 1] = [1 0 1 0 1 0 1 0]

The four information bits are i3,i5,i6,i7i_3, i_5, i_6, i_7, so we have:

i=[0010]\mathbf{i} = [0 0 1 0]

(remember that the first bit is c0c_0 now, so i3i_3 is the fourth bit etc.).

7Exercise 7 Hamming Codes - errors

Give an example of errors which the Hamming (15, 11) is not able to detect. Give another example of errors which the Hamming (15, 11) is able to detect, but is not able to fix them correctly.

7.1Solution

The control matrix [H][H] of the Hamming (15, 11) code contains numbers from 1 to nn written on 4 bits, so they go from 1 to 15:

[H]=[000000011111111000111100001111011001100110011101010101010101][H] = \begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\ \end{bmatrix}

Hamming codes are linear block codes, so the same rules apply as for linear block codes. An error pattern goes undetected if the sum of the corresponding columns of [H][H] is equal to the zero vector. For example, if we have three errors, on the first three bits, then the error pattern is:

e=[111000000000000]\mathbf{e} = [1 1 1 0 0 0 0 0 0 0 0 0 0 0 0]

The syndrome is:

z=[H]eT=[000000011111111000111100001111011001100110011101010101010101][111000000000000]=[000]\mathbf{z} = [H] \cdot \mathbf{e}^T = \begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\ \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 1 \\ 1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} 0 \\ 0 \\ 0 \\ \end{bmatrix}

and the decoder believes that there are no errors.

The code is not able to fix errors correctly if the syndrome corresponds to a single error which is not the true one. For example, if we have two errors on the first and second bits, then the error pattern is:

e=[110000000000000]\mathbf{e} = [1 1 0 0 0 0 0 0 0 0 0 0 0 0 0]
z=[H]eT=[000000011111111000111100001111011001100110011101010101010101][110000000000000]=[011]\mathbf{z} = [H] \cdot \mathbf{e}^T = \begin{bmatrix} 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 1 & 1 & 1 & 1 \\ 0 & 0 & 0 & 1 & 1 & 1 & 1 & 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 \\ 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 & 0 & 0 & 1 & 1 \\ 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 & 0 & 1 \\ \end{bmatrix} \cdot \begin{bmatrix} 1 \\ 1 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ \end{bmatrix} = \begin{bmatrix} 0 \\ 1 \\ 1 \\ \end{bmatrix}

The syndrome z=[011]T\mathbf{z} = [0 1 1]^T corresponds to the error on the 3rd position, so the decoder will believe that the error is on the 3rd position, which is not true.

8Exercise 8 Cyclic Codes - encoding

Find the non-systematic and then the systematic cyclic codeword for the sequence i=[1010001100]\mathbf{i} = [1 0 1 0 0 0 1 1 0 0] (first bit is LSB), considering a cyclic code with generator polynomial g(x)=1xx3g(x) = 1\oplus x \oplus x^3.

8.1Solution

a). “the mathematical way” (with polynomials)

We first convert the binary sequence into a polynomial. The LSB corresponds to x0x^0, and the MSB corresponds to the highest degree.

i=[1010001100]i(x)=1x2x6x7\begin{align*} \mathbf{i} = [1 0 1 0 0 0 1 1 0 0] &\Rightarrow i(x) = 1 \oplus x^2 \oplus x^6 \oplus x^7 \\ \end{align*}

Also, we note that the generator polynomial has degree 3, which means that the codeword is 3 bits longer than the information word. Since the information word given length k=10k = 10, the codeword will have n=k+3=13n = k + 3 = 13 bits.

Non-systematic codeword

The non-systematic codeword is computed by multiplying i(x)i(x) with g(x)g(x):

c(x)=i(x)g(x)=(1x2x6x7)(1xx3)=1xx3x2x3x5x6x7x9x7x8x10=1xx2x5x6x8x9x10\begin{align*} c(x) &= i(x) \cdot g(x) \\ &= (1 \oplus x^2 \oplus x^6 \oplus x^7) \cdot (1 \oplus x \oplus x^3) \\ &= 1 \oplus x \oplus x^3 \oplus x^2 \oplus x^3 \oplus x^5 \oplus x^6 \oplus x^7 \oplus x^9 \oplus x^7 \oplus x^8 \oplus x^{10} \\ &= 1 \oplus x \oplus x^2 \oplus x^5 \oplus x^6 \oplus x^8 \oplus x^9 \oplus x^{10} \\ \end{align*}

Note that equal terms cancel out (i.e. x3x3=0x^3 \oplus x^3 = 0).

We now convert back the polynomial into a binary sequence, by listing the coefficients. However, we only have 11 coefficients (from x0x^0 to x10x^{10}), but we know we need a codeword of length n=13n = 13, so we add two zeros at the end, to make it of length n=13n = 13. These correspond to missing terms 0x11+0x120 x^{11} + 0 x^{12}, which could have appeared in the polynomial, but happened to be zero.

c=[1110011011100]\mathbf{c} = [1 1 1 0 0 1 1 0 1 1 1 0 0]

Systematic codeword

The systematic codeword is computed as:

c(x)=xnki(x)+b(x)c(x) = x^{n-k} \cdot i(x) + b(x)

where nkn-k is the degree of g(x)g(x) (nk=3n-k = 3 in our case), and b(x)b(x) is the remainder of the division of xnki(x)x^{n-k} \cdot i(x) by g(x)g(x).

In our case, we have:

xnki(x)=x3(1x2x6x7)=x3x5x9x10x^{n-k} \cdot i(x) = x^3 \cdot (1 \oplus x^2 \oplus x^6 \oplus x^7) = x^3 \oplus x^5 \oplus x^9 \oplus x^{10}

We divide this to g(x)g(x) to find the remainder. Note that the polynomial division requires writing the polynomials in descending order.

Computing the remainder of the division of x^{n-k} \cdot i(x) by g(x)

Figure 7:Computing the remainder of the division of xnki(x)x^{n-k} \cdot i(x) by g(x)g(x)

The remainder is 1x1 \oplus x. We add the remainder to xnki(x)x^{n-k} \cdot i(x) to find the systematic codeword polynomial:

c(x)=1xx3x5x9x10c(x) = 1 \oplus x \oplus x^3 \oplus x^5 \oplus x^9 \oplus x^{10}

We read out the coefficients of the polynomial to get the codeword in binary, appending two zeros at the end to obtain the prescribed length n=13n = 13:

Final systematic codeword

Figure 8:Final systematic codeword

b). “the programming way” (XOR-ing bit sequences)

We use this only for the systematic codeword. This method is equivalent to the mathematical way, but it is easier to implement as an algorithm on binary sequences.

We start from the information word and the generator polynomial written in binary, from MSB to LSB, so in our case in reverse order.

i=[0011000101]g=[1011]\begin{align*} \mathbf{i} &= [0 0 1 1 0 0 0 1 0 1] \\ \mathbf{g} &= [1 0 1 1] \\ \end{align*}

We extend the information word with nk=3n-k = 3 zeros at the end, initialized with 0, to make it of length n=13n = 13, as illustrated in the image below.

The procedure is as follows:

  1. Locate the first 1 in i\mathbf{i}

  2. Under it write the generator sequence g\mathbf{g}

  3. Add the two sequences using XOR. Note that the first 1 is cancelled out.

  4. Locate the next 1 in the resulting sequence, and repeat.

Final systematic codeword

Figure 9:Final systematic codeword

We stop when we reached the end of the information word. The three bits obtained at the end are control bits (i.e. the CRC, the remainder of the division).

Append the control bits at the LSB side of the information word to get the systematic codeword.

We revert the sequence afterwards, to get the final codeword in the original order (here, from LSB to MSB).

9Exercise 9 Cyclic Codes - decoding

We receive a sequence r=101011100101\mathbf{r} = 101011100101 (first bit is the LSB), which was encoded with a systematic cyclic code with generator polynomial g(x)=1x2x3g(x) = 1 \oplus x^2 \oplus x^3. Find if there are errors in the received data, and, if yes, perform correction and retrieve the transmitted information bits.

9.1Solution

a). “the mathematical way” (with polynomials)

We convert the received sequence into a polynomial, as before:

r=[101011100101]r(x)=1x2x4x5x6x9x11\mathbf{r} = [1 0 1 0 1 1 1 0 0 1 0 1] \Rightarrow r(x) = 1 \oplus x^2 \oplus x^4 \oplus x^5 \oplus x^6 \oplus x^9 \oplus x^{11}

To check for errors, we divide r(x)r(x) by g(x)g(x), and we check the remainder. If it is zero, then there are no errors. If not, then there are errors. Remember to arrange the polynomials in descending order of powers (MSB to LSB)

Polynomial division at decoding

Figure 11:Polynomial division at decoding

In our case we have the remainder b(x)=x2b(x) = x^2, so there are errors.

To correct the errors, we need to find the error pattern e\mathbf{e} which produces the same remainder when divided by g(x)g(x).

As for linear block codes, we try all possible error patterns with 1 error, then with 2 errors, and so on, until we find the one that produces the same remainder.

The error patterns with 1 error are 1, xx, x2x^2, x3x^3 ... x11x^{11}, so we take each one and we divide it by g(x)g(x) to find the remainder, until the remainder is equal to b(x)=x2b(x) = x^2.

Error patternRemainder
[100000000000]=1[1 0 0 0 0 0 0 0 0 0 0 0] = 1[100]=1[1 0 0] = 1
[010000000000]=x[0 1 0 0 0 0 0 0 0 0 0 0] = x[010]=x[0 1 0] = x
[001000000000]=x2[0 0 1 0 0 0 0 0 0 0 0 0] = x^2[001]=x2[0 0 1] = x^2

The third error pattern matches, so we have e=[001000000000]\mathbf{e} = [0 0 1 0 0 0 0 0 0 0 0 0], the error being on the third bit.

The correct codeword is:

c=re=[101011100101][001000000000]=[100011100101]\mathbf{c} = \mathbf{r} \oplus \mathbf{e} = [1 0 1 0 1 1 1 0 0 1 0 1] \oplus [0 0 1 0 0 0 0 0 0 0 0 0] = [1 0 0 0 1 1 1 0 0 1 0 1]

We know that the first 3 bits on the LSB side are the CRC, so the other bits are the information bits:

i=[011100101]\mathbf{i} = [0 1 1 1 0 0 1 0 1]

b). “the programming way” (XOR-ing bit sequences)

We can use the binary algorithm instead of the division, in the same way as we did before.

10Exercise 7 Cyclic Codes - general

We do cyclic coding on information words of length k=8k = 8 bits. We want the coding rate RR to be at most 0.6. What degree must the generator polynomial g(x)g(x) have?

10.1Solution

The coding rate RR is:

R=knR = \frac{k}{n}

where kk is the length of the information word, and nn is the length of the codeword.

If k=8k = 8 and R0.6R \leq 0.6, this implies a lower limit of nn:

8n0.6    n80.613.33\frac{8}{n} \leq 0.6 \implies n \geq \frac{8}{0.6} \approx 13.33

The degree of the generator polynomial g(x)g(x) is nkn - k, so we have:

degree(g(x))=nk13.338=5.33\text{degree}(g(x)) = n - k \geq 13.33 - 8 = 5.33

Since the degree must be an integer, we round it up to the next integer. Therefore, the degree of the generator polynomial must be at least 6.