Experiment No.: 2: AIM: To Perform Encoding and Decoding For Hamming Code. APPARATUS: Scilab. Theory

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Experiment No.

: 2

AIM: To perform encoding and decoding for Hamming code.

APPARATUS: Scilab.

THEORY:

Hamming Code Hamming code is a set of error-correction code s that can be used to detect
and correct bit errors that can occur when computer data is moved or stored. Hamming
code is named for R. W. Hamming of Bell Labs.

Like other error-correction codes, Hamming code makes use of the concept of parity and
parity bit s, which are bits that are added to data so that the validity of the data can be
checked when it is read or after it has been received in a data transmission. Using more than
one parity bit, an error-correction code can not only identify a single bit error in the data
unit, but also its location in the data unit.

In data transmission, the ability of a receiving station to correct errors in the received data is
called forward error correction (FEC) and can increase throughput on a data link when there
is a lot of noise present. To enable this, a transmitting station must add extra data (called
error correction bits ) to the transmission. However, the correction may not always
represent a cost saving over that of simply resending the information. Hamming codes make
FEC less expensive to implement through the use of a block parity mechanism.

The structure can be indicated as follows for a (7,4) hamming code :


4 message bits + 3 redundant bits ⇒7 bit Hamming.
ALGORITHM:

a.Generation:

1. Mark all bit positions that are powers of two as parity bits. (positions 1, 2, 4, 8, 16,
32, 64, etc.)
2. All other bit positions are for the data to be encoded. (positions 3, 5, 6, 7, 9, 10, 11,
12, 13, 14, 15, 17, etc.)
3. The position of the parity bit determines the sequence of bits that it alternately
checks and skips.
a. Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc.
(1,3,5,7,9,11,13,15,...)
b. Position 2: check 2 bits, skip 2 bits, check 2 bits, skip 2 bits, etc.
(2,3,6,7,10,11,14,15,...)
c. Position 4: check 4 bits, skip 4 bits, check 4 bits, skip 4 bits, etc.
(4,5,6,7,12,13,14,15,20,21,22,23,...)
d. Position 8: check 8 bits, skip 8 bits, check 8 bits, skip 8 bits, etc. (8-15,24-
31,40-47,...)
4. Set a parity bit to 1 if the total number of ones in the positions it checks is odd.
5. Set a parity bit to 0 if the total number of ones in the positions it checks is even.
b. Error Detection and Correction:

1. At the Receiver’s End, verify each check bit.


2. Write down all the incorrect parity bits.
3. The erroneous bit is identified with the help of the parity bits.
4. Take the complement of the erroneous bit position to correct received data.

CODE:

g=input('Enter The Generator Matrix: ')


disp ('G = ')
disp ('The Order of Linear block Code for given Generator Matrix is:')
[n,k] = size(transpose(g))
for i = 1:2^k
for j = k:-1:1
if rem(i-1,2^(-j+k+1))>=2^(-j+k)
u(i,j)=1;
else
u(i,j)=0;
end
end
end
u;
disp('The Possible Code words are :')
c = rem(u*g,2)
disp('The Minimum Hamming Distance dmin for given Block Code is= ')
d_min = min(sum((c(2:2^k,:))'))
r = input('Enter the Received Code Word:')
p = [g(:,n-k+2:n)];
h = [transpose(p),eye(n-k)];
disp('Hamming Code')
ht = transpose(h)
disp('Syndrome of a Given Code word is :')
s = rem(r*ht,2)
for i = 1:1:size(ht)
if(ht(i,1:3)==s)
r(i) = 1-r(i);
break;
end
end
disp('The Error is in bit:')
i
disp('The Corrected Code word is :')

SIMULATION:

Enter The Generator Matrix: [1 0 0 0 1 0 1;0 1 0 0 1 1 1;0 0 1 0 1 1 0;0 0 0 1 0 1 1]


g =1 0 0 0 1 0 1
0100111
0010110
0001011
G = The Order of Linear block Code for given Generator Matrix is:
n =7
k =4
The Possible Code words are :
c =0 0 0 0 0 0 0
0001011
0010110
0011101
0100111
0101100
0110001
0111010
1000101
1001110
1010011
1011000
1100010
1101001
1110100
1111111
The Minimum Hamming Distance dmin for given Block Code is= d_min =3
Enter the Received Code Word:[1 0 0 0 1 0 0]
r =1 0 0 0 1 0 0
Hamming Code
ht =1 0 1
111
110
011
100
010
001
Syndrome of a Given Code word is :
s =0 0 1
The Error is in bit:
i =7
The Corrected Code word is :
r =1 0 0 0 1 0 1

CONCLUSION:

Thus we have studied hamming code and performed it successfully.

You might also like