You are on page 1of 24

Hamming code

by
Noor Dheyaa
Hamming code
 Hamming code : can detect up to two bit errors or correct one bit error.
 invented by Richard Hamming in 1950.
 In the code word, there are k data bits and 𝑟=𝑛−𝑘 redundant (check)
bits, giving a total of n code word bits. 𝑛=𝑘+𝑟
 Hamming Code Algorithm:
 1. r parity bits are added to an k - bit data word, forming a code word of n bits.
 2. The bit positions are numbered in sequence from 1 to n.
 3. Those positions are numbered with powers of two, reserved for the parity
bits and the remaining bits are the data bits.
 4. Parity bits are calculated by XOR operation of some combination of data
bits.
hamming code Method

1- Equations Method:

Example: Hamming(7,4)

(In sender) It can be calculate the parity bits from the


following equations:
 At the receiver, the first step in error correction, is to calculate the
syndrome bits which indicate the position of the error are given by:

 Also, the value of syndrome determine the position detecting using


syndrome bits = CBA.
Hamming Code Position

P1= XOR of bit position (1, 3, 5, 7, 9, 11, 13…)


P2= XOR of bit position (2, 3, 6, 7, 10, 11…)
P4= XOR of bit position (4, 5, 6, 7, 13…)
P8= XOR of bit position (8, 9, 10, 11, 12, 13…)
Hamming Code Position
The bit position covered by each parity bit can be calculated by writing each bit
position as a sum of the powers of 2:
1=1
2=2
3=1+2
4=4
5=1+4
6=2+4
7=1+2+4
8=8
9=1+8
10 = 2 + 8
:Hamming matrices-2
 two Hamming matrices can be defined: the code generator matrix G and
the parity-check matrix H

H=rxn
G=nxk

Code word = G * M
Syndrome = H* R
:Example
 A: Using equations method for hamming code of (7, 4),

 1- Determine the code word of the following message: m1= 1100 and
m2= 0110.

 2- Calculate the syndrome, if the error occurs at the sixth bit of each
received code word.
A- For first message =1100

7 6 5 4 3 2 1 Bit position
d4 d3 d2 p3 d1 p2 p1 Bit name
0 0 1 1 1 1 0 Code ward

For second message = 0110

7 6 5 4 3 2 1 Bit position
d4 d3 d2 p3 d1 P2 p1 Bit name
0 1 1 0 0 1 1 Code ward
 The received code word: R1 = 0111110, Now calculate the
syndrome:

 So that CBA = 110 which indicate that an error in the sixth


bit.
The received code word: R2= 1100100,now calculate the
:syndrome

So that CBA = 110 which indicate that an error in the sixth bit.
B) Using matrices method for Hamming code of (7, 4),

1- Determine the code word of the fallowing messages: m1= 0011 and
m2= 1001.

2- Calculate the syndrome, if the error occurs at the fifth bit of each
received code word.
2- Now for an error in bit 5 occurs, then R1=[1000111] and

R2=[0011101].
Using the syndrome equation S=[H] * R where R is the received vector
and the parity check matrix is given by:
Example 2
Thank you

You might also like