linblknew.m

来自「it is the code for linear block code」· M 代码 · 共 51 行

M
51
字号
                %MATLAB PROGRAM FOR LINEAR BLOCK CODE%
                %Genarating the possible Code words & Parity Check Matrix%
                %Caliculation of dmin  %
                %Syndrome for the received code word for Eror Dection and Correction%

clc
clear all

G=input('Enter the generator matrix')
[k,n]=size(G);

disp('The possible code words are');
for i=1:2^k
for j=k:-1:1
if rem(i-1,2^(-j+k+1))>=2^(-j+k)
u(i,j)=1;
else
u(i,j)=0;
end
end
end
c=rem(u*G,2)

disp('The minimum Hamming distance is');
dmin=min(sum((c(2:2^k,:))'))

disp('The parity matrix is');
P=G(1:k,(k+1):n)

I=eye(n-k,n-k);
HT=vertcat(P,I);

disp('The parity-check matrix is')
H=HT'

R=input('Enter received code word');

disp('The syndrome for the received code word is')
S =rem(R*HT,2)

for i=1:n
if S==HT(i,1:(n-k))
x=i;
end
end
disp('The error is in bit ');
x
disp('The corrected code word is ');
R(1,x) = 1 - R(1,x);
R

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?