Anda di halaman 1dari 7

L5.

THE HAMMING CODE

5.1 The aim of the laboratory work


In this laboratory you are suppose to realize a coding/decoding using the single error
correcting Hamming code, respectively the single error correcting Hamming code and
detector of double errors.
5.2 The single error correcting Hamming code
The Hamming codes are considered to be the first class of single error correcting
linear bloc codes and they were suggested by R.Hamming in 1950.
The Hamming code is a protector code. By coding we want to adapt the information
source to the transmission channel. In this case, the source has already been coded and
another coding will be done in order to keep the information protected. We accomplish this
by enlarging the redundancy (by enlarging the binary support; we add the control bits to the
information bits). The control bits have the purpose to create connections, relations between
the information bits. The coder uses these relations to calculate the control bits and the
decoder uses these relations to verify the transmissions accuracy.
The Hamming code is an immethodical code (the control symbols are situated on the
power of 2 positions and are inserted between the information symbols).
5.2.1 The coding of the single error correcting Hamming code
The characteristic of the single error correcting linear Hamming code consists in the
shape of the control matrix, H, which has every column structured by the binary
representation of the ordering decimal number of that column. For this reason, the corrector
, decoded from binary to decimal, indicates the
Z, computed with the relation Z=H
ordering decimal number of the wrong bit from the received word.
The minimum distance of this code is:
d 2ec + 1 = 3
where

represents the number of errors that can be corrected.

The following code and the parameters are considered:

n=7, the number of symbols in a word;


m=3, the number of control symbols in a word;
k=4, the number of information symbols in a word.

The information sequence is:


i = i 3i5i 6i 7
and the control sequence:
C = C1C2 C 4

so that the resulting code word would be :


V = C1C2i 3C 4i5i 6i 7
The coding means computing the control symbols
symbols

, ,

and

when the information

are given.

The coding relation:

C1
C
2
0 0 0 1 1 1 1 i3

T
H V = 0 = 0 1 1 0 0 1 1 C 4 = 0
1 0 1 0 1 0 1 i5

i6
i
7

(5.1)

where H represents the control matrix, having the dimension mn.


Or in an explicit manner:
C1 = i3 + i5 + i7
C2 = i3 + i 6 + i 7

(5.2)

C4 = i5 + i 6 + i 7
The sum is made in twos modulus.
1st Example:

For n=7, k=4, m=3 and the information sequence i=1010, find the code word V.
Solution:
We notice that there are 4 information symbols: , , , . The code word V can be
written in literary form: V=

. Therefore we have 7 symbols that form a

code word and 3 control bits. It results that the control matrix H will have 3 lines and 7
columns.
The computing relations of the control bits result from the coding relation (5.1) :
C1 = i3 + i5 + i 7 = 1 + 0 + 0 = 1
C2 = i3 + i 6 + i 7 = 1 + 1 + 0 = 0
C4 = i5 + i 6 + i 7 = 0 + 1 + 0 = 1
The code word results:
V=1011010
5.2.2 The decoding of the single error correcting Hamming code

Having received the word V, composed of 7 symbols:


V ' = C1' C '2i3' C '4i5' i 6' i 7'

we can calculate the corrector of the Hamming code with the relation:
z4
'T
z = H V = z 2
z1

(5.3)

The control matrix:


H[ m,n ] = [ h1 L h i L h n ]
where, in this case, we see that m=3 and n=7. Column

(5.4)

expresses, in natural binary code, the

ordering number of the column with the least significant bit in line m.
From the relation (5.3) it results:
z 4 = C '4 + i5' + i '6 + i 7'
z 2 = C '2 + i3' + i '6 + i '7
'
1

'
3

'
5

z1 = C + i + i + i

(5.5)

'
7

The decimal decoding of the corrector z indicates the errors position, if there is only one
error in the word V. It will be wrong, the symbol with the index r, given by the relation:
r = 4z 4 + 2z 2 + z1

(5.6)

The received word can also be written:


V' = V + ,
Where represents the error word.
Relation (5.3) will become:
T

z = H V ' = H ( V + ) = H T = h r
where the errors position is computed with the relation (5.6).

Remark: In case there are two errors, there is the possibility that no error is corrected and a
third symbol is wrong, resulting three wrong symbols at the reception.
2nd Example:

Decode the received word V=1001001


Solution:
The received code word can be written:
V ' = C1' C '2i3' C '4i5' i '6i '7

V = 1 0 0 1 0 0 1
The relation (5.5) will become:
z 4 = C'4 + i5' + i 6' + i 7' = 1 + 0 + 0 + 1 = 0
z 2 = C'2 + i3' + i '6 + i '7 = 0 + 0 + 0 + 1 = 1
z1 = C1' + i 3' + i5' + i 7' = 1 + 0 + 0 + 1 = 0

Therefore, the error position is:


r = 4z 4 + 2z 2 + z1 = 4 0 + 2 1 + 1 0 = 2

The error word results:


= 0100000
It can be written:
V = V ' + = 1001001 + 0100000 = 1101001
The information sequence results:
i = i3i5i 6i7 = 0001
5.3 The single correcting Hamming code and detector of double errors

The necessary and sufficient condition for this code to be able to simultaneously
correct maximum t errors and detect maximum e errors is that the minimum distance of the
code to be:
d t + e + 1 = 1 + 2 + 1 = 4,

e>t

5.3.1 The coding of the single correcting Hamming code and detector of double errors

In order to exclude the single correcting Hamming codes disadvantage (to have
additional errors at the exceeding of the correction codes capacity, t>1 ) and to make it more
useful in practical applications, the code was modified in the sense of increasing the
minimum distance from d=3 to d=4, which permits double errors detection.
The increasing of the code distance from 3 to 4 was made by adding a supplementary
control symbol named parity control symbol and the code words structure becomes:
V = C0 C1C2i3C 4i5i6i7
The control matrix modifies and has the structure:
0

0 H 0
'
H =
=
1 1 0

0
0
1
1

0
1
0
1

0
1
1
1

1
0
0
1

1
0
1
1

1
1
0
1

1
1
1

The coding relation will be:

0
0
H' VT =
0

Or in explicit form:

0 0 0 1 1 1
0 1 1 0 0 1
1 0 1 0 1 0
1 1 1 1 1 1

C0
C
1
1 C2

1 i3

=0
1 C4

1 i5
i
6
i 7

(5.7)

C1 = i3 + i5 + i7
C2 = i3 + i 6 + i 7

(5.8)

C4 = i5 + i 6 + i 7
C0 = C1 + C2 + i3 + C 4 + i5 + i 6 + i 7
3rd Example:

Consider the following information sequence i=1010, find the code word V.
Solution:
We notice that there are 4 information symbols: , , , . The code word V can be written
in literary form: V=

. Therefore we have 8 symbols that compose a code

word and 4 control bits. It results that the control matrix H will have 4 lines and 8 columns.
The control bits computing relations result from the coding relation (5.8):
C1 = i3 + i5 + i 7 = 1 + 0 + 0 = 1
C2 = i3 + i 6 + i 7 = 1 + 1 + 0 = 0
C4 = i5 + i 6 + i 7 = 0 + 1 + 0 = 1
C0 = C1 + C2 + i3 + C4 + i5 + i6 + i 7 = 1 + 0 + 1 + 1 + 0 + 1 + 0 = 0
The code word results:
V=01011010
5.3.2 The decoding of the single error correcting Hamming code and detector of double
errors

Having the received word V composed of 8 symbols:


V ' = C '0 C1' C'2i 3' C '4i5' i '6i '7
We can compute the codes corrector with the relation:

z4

T
z z
Z = H' V' = = 2
z 0 z1

z 0

(5.9)

Where:

z represents the corrector of the single code correcting Hamming code;


represents the binary symbol 0 or 1, which helps us detect even errors ( =0).

There are four cases:


1st Case:

z = 0

z0 = 0
there are no errors or there are no code detectable errors.

2nd Case:
z 0

z0 = 0
we detect the double errors.

3rd Case:

z = 0

z 0 = 1
the symbol

is wrong.

4th Case:

z 0

z 0 = 1
there is a correctable error.
The symbol with the index r-1 will be wrong and r is given by the relation:
r = 4z 4 + 2z 2 + z1 + z 0

4th Example:

Decode the received word V=01001010


Solution:
The received code word can be written:
V ' = C '0 C1' C'2i 3' C '4i5' i '6i '7

V = 0 1 0 0 1 0 1 0
The relation (5.5) will become:
z 4 = C'4 + i5' + i '6 + i '7 = 1 + 0 + 1 + 0 = 0
z 2 = C'2 + i3' + i '6 + i '7 = 0 + 0 + 1 + 0 = 1
z1 = C1' + i 3' + i5' + i 7' = 1 + 0 + 0 + 0 = 1
z 0 = C '0 + C1' + C 2' + i3' + C '4 + i 5' + i 6' + i 7' = 0 + 1 + 0 + 0 + 1 + 0 + 1 + 0 = 1

It results that we are in the 4th case and we have a correctable error.
Therefore it results that r:
r = 4z 4 + 2z 2 + z1 + z 0 = 4 0 + 2 1 + 11 + 1 = 4
So the symbol with the index r-1 will be wrong, meaning 4-1=3, .
The error word results:
=00010000

(5.10)

We can write:
V = V ' + = 01001010 + 00010000 = 01011010
The information sequence results:
i = i3i5i 6i7 = 1010
5.4 Practical work
5.4.1 Launch the executable Hamming.exe from the Hamming directory and afterwards type
the password TTI. Run the program by selecting the option Demonstratie for all the four
cases presented.
5.4.2 Verify with this program all the examples seen and selecting one by one the codes
presented.
5.4.3 For each code choose a coding or a decoding example that are similar with the ones in
the paper, with the remark that the information sequence, at coding, has to contain 11 bits
and the received word, at decoding, has to contain 15/16 bits. We carry out the
coding/decoding and after that we verify the results using the program.
5.4.4 At the end you will give a test on your accumulated knowledge during this laboratory.
The result of the test will be described by a mark computed by the computer.

Anda mungkin juga menyukai