Code:
clc;
clear all;
close all;
n=input('enter the code digits');
k=input('enter the data digits');
i=eye([k k])
d = de2bi(0:2^k-1,3,'left-msb');
a = input('to generate systematic code press 1 or
any other to generate non systematic code:
');
if(a ==1 )
sprintf('enter parity matrix of size %dX%d',k,n-k)
p =input('parity matrix: ');
g=[i p];
h=[p i];
c=rem(d*g,2)
else
sprintf('enter generator matrix of size %dX%d',k,n)
ns = input('generator
matrix: ');
c1=rem(d*ns,2)
h=ns;
end
trt = syndtable(h); % Produce decoding table.
sprintf('enter received code of size 1X%d',n)
%recd = [1 1 1 0 0 1 ] % Suppose this is the
received vector.
recd = input('received code: ');
syndrome = rem(recd * h',2);
syndrome_de = bi2de(syndrome,'left-msb'); % Convert
to decimal.
disp(['Syndrome = ',num2str(syndrome_de),...
'
(decimal), ',num2str(syndrome),' (binary)'])
corrvect = trt(1+syndrome_de,:) % Correction vector
% Now compute the corrected codeword.
correctedcode = rem(corrvect+recd,2)
%r=input('enter the recive code ');
Output:
enter the code digits 7
enter the data digits 4
to generate systematic code press 1 or any other to
generate non systematic code: 1
enter parity matrix of size 4X3
parity matrix:
[1 1 1; 1 0 1; 1 1 0; 0 1 1]
c =
0 0
0 0 0
0 0
0 0
0 1 0
1 1
0 0
1 0 1
1 0
0 0
1 1 1
0 1
0 1
0 0
1 0 1
0 1
0 1 1
1 0
0 1
1 0 0
1 1
0 1
1 1 0
0 0
1 0
0 0 1
1 1
1 0
0 1 1
0 0
1 0 1
0 0 0
1
1 0
1 1 0
1 0
1 1
0 0 0
1 0
1 1
0 1 0
0 1
1 1
1 0 1
0 0
1 1
1 1 1
1 1
Single-error patterns loaded in decoding table. 8 rows remaining.
2-error patterns loaded. 1 rows remaining.
3-error patterns loaded. 0 rows remaining.
enter received code of size 1X7
received code:
[1 1 1 1 0 0 1]
Syndrome = 1 (decimal), 0 0
0 1 (binary)
corrvect =
0 0 0
0 0 0
1
correctedcode =
1 1
1 1 0
0 0
Syndrome table
0 0
0 0 0
0 0
0 0
0 0 0
0 1
0 0
0 0 0
1 0
1 0
1 0 0
0 0
0 0
0 0 1
0 0
1 1
0 0 0
0 0
1 0
0 1 0
0 0
1 1
0 0 0
1 0
0 0
0 1 0
0 0
0 1
0 0 0
1 0
1 0
0 0 1
0 0
0 1
0 0 0
0 0
1 0
0 0 0
1 0
0 0
1 0 0
0 0
1 0
0 0 0
0 0
1 0
0 0 0
0 1
0 comments:
Post a Comment