0% found this document useful (0 votes)
9 views

Hammingcode

hamming code in matlab

Uploaded by

Innovation SRI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Hammingcode

hamming code in matlab

Uploaded by

Innovation SRI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

clc

close all
clear all
Message=input('enter msg bits to be transmitted(binary data only):')
disp(dec2bin(Message)')
if(size(dec2bin(Message)',1))~=1
disp('The entered message is not binary data, please wait for 5 seconds')
pause(5)
HammingCode;
else
disp('The message to be Transmitted is:')
disp(Message)
Message=flip(Message);
disp('The length of the message :')
disp(length(Message))
for k=1:length(Message)
if(power(2,k)-1) >= length(Message)+k
disp('The total number of the Parity bits required are')
disp(k);
break;
end
end
end
disp('The total length of the message with Parity bits is :')
disp(length(Message)+k);
PB=-k:1;
disp('The parity bits to be appended initially are :')
disp(PB);
for s=1:length(Message)+k
for t=0:k
if s==power(2,t)
tx(s)=PB(end-t);
elseif s>power(2,t-1) && s<power(2,t)
tx(s)=Message(s-t);
end
end
end
disp('The Message generated with initially generated parity bits is :')
disp(flip(tx))
txlength=1:length(Message)+k;
dec_num = dec2bin(txlength,k)-'0';
for j=k:-1:1
Parity_bit_positon=find((dec_num(:,j))')
actual_parity_bit_positions=Parity_bit_positon(2:end);
PB(j)=rem(sum(tx(actual_parity_bit_positions)),2)
end
disp('The actual Parity bits to be appended are:')
disp(PB);
for s=1:length(Message)+k
for t=0:k
if s==power(2,t)
tx(s)=PB(end-t);
end
end
end
disp('The actual Message to be transmitted with parity bits is :')
disp(flip(tx))

You might also like