clc;clear;close all;
G=[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];
k=4;n=7;
disp('Generator matrix'); disp(G);
msg_table=dec2bin(0:2^k-1)-48;
disp('Message table');
disp(msg_table);
cw_table=mod(msg_table*G,2);
disp('Codeword table');
disp(cw_table);
msg_tx=[0 1 1 0];
cw_tx=mod(msg_tx*G,2);
disp('Codeword to be transmitted');
disp(cw_tx);
%Reciever side
cw_rx=[0 1 1 0 1 0 1];
disp('Codeword recieved');
disp(cw_rx);
H=[G(:,5:7)' eye(n-k)]; %(all row,5 to 7 column),eye=identity
matrix
disp('Parity check matrix');
disp(H);
error_pattern=[zeros(1,n);eye(n)]; %first row all zeros then
7x7 identity matrix
disp('Error pattern');
disp(error_pattern);
syn_list=[zeros(1,n-k);H']; %syndrome is h transpose,add zeros
at first line to avoid error
disp('Syndrome list');
disp(syn_list);
syndrome=mod(cw_rx*H',2);
disp('Syndrome');
disp(syndrome);
for i=1:n+1
if(syndrome==syn_list(i,:)) %if any row in synlist=syndrome,
then the row number's bit in recieved codeword has error.(if
5th row, then 5th bit error)
break;
end
end
corrected_cw=mod(cw_rx+error_pattern(i,:),2);
disp('Corrected codeword');
disp(corrected_cw);