0% found this document useful (1 vote)
604 views

Hamming Code Matlab

This document summarizes how to implement Hamming code error correction using Matlab. It defines the number of codeword and message bits, generates the generator and parity check matrices, encodes a sample message, introduces an error into the encoded codeword, decodes the received codeword to find and correct the error location, and strips off the parity bits to retrieve the original message. The decoding process finds the syndrome, iterates through each codeword bit position to determine which one when flipped matches the syndrome, identifies the error location index, and flips that bit to correct the codeword.

Uploaded by

Gunasekaran P
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
604 views

Hamming Code Matlab

This document summarizes how to implement Hamming code error correction using Matlab. It defines the number of codeword and message bits, generates the generator and parity check matrices, encodes a sample message, introduces an error into the encoded codeword, decodes the received codeword to find and correct the error location, and strips off the parity bits to retrieve the original message. The decoding process finds the syndrome, iterates through each codeword bit position to determine which one when flipped matches the syndrome, identifies the error location index, and flips that bit to correct the codeword.

Uploaded by

Gunasekaran P
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

3.

Hamming Code using Matlab:

clear

n = 7 %# of codeword bits per block

k = 4 %# of message bits per block

A = [ 1 1 1;1 1 0;1 0 1;0 1 1 ]; %Parity submatrix-Need binary

G = [ eye(k) A ] %Generator matrix

H = [ A' eye(n-k) ] %Parity-check matrix

% ENCODER%

msg = [ 1 1 1 1 ] %Message block vector-change to any 4 bit sequence

code = mod(msg*G,2) %Encode message

% CHANNEL ERROR(add one error to code)%

%code(1)= ~code(1);

code(2)= ~code(2);

%code(3)= ~code(3);

%code(4)= ~code(4); %Pick one, comment out others

%code(5)= ~code(5);

%code(6)= ~code(6);

%code(7)= ~code(7);

recd = code %Received codeword with error

% DECODER%

syndrome = mod(recd * H',2)

%Find position of the error in codeword (index)

find = 0;

for ii = 1:n

if ~find

errvect = zeros(1,n);

errvect(ii) = 1;
search = mod(errvect * H',2);

if search == syndrome

find = 1;

index = ii;

end

end

end

disp(['Position of error in codeword=',num2str(index)]);

correctedcode = recd;

correctedcode(index) = mod(recd(index)+1,2)%Corrected codeword

%Strip off parity bits

msg_decoded=correctedcode;

msg_decoded=msg_decoded(1:4)

You might also like