Hamming Code Matlab
Hamming Code Matlab
clear
% ENCODER%
%code(1)= ~code(1);
code(2)= ~code(2);
%code(3)= ~code(3);
%code(5)= ~code(5);
%code(6)= ~code(6);
%code(7)= ~code(7);
% DECODER%
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
correctedcode = recd;
msg_decoded=correctedcode;
msg_decoded=msg_decoded(1:4)