📄 linblock.asv
字号:
%%linear block coder%%
clc;
clear all;
%ENCODER SECTION
disp('ENCODER SECTION')
n=input('ENTER THE VALUE FOR CODE LENGTH n ');
k=input('ENTER THE VALUE FOR CODE DIMENSION k ');
q=n-k;
fprintf('\n ORDER OF THE PARITY MATRIX %d x %d\n',k,q)
p=input('ENTER THE PARITY MATRIX P \n');
disp('p=')
disp(p);
disp('THE GENERATOR MATRIX IS:');
G=horzcat(eye(k),p)
fprintf('\n THE NO. OF MESSAGE BITS ARE %d',k);
m=input('\n ENTER THE MESSAGE BITS');
for i=1:1:q
code(1,i)=0;
for j=1:1:k
code(1,i) = rem((code(1,i) + m(1,j)*p(j,i)),2);
end
end
fprintf('\nthe code word is')
c=horzcat(m,code)
%DECODER SECTION
disp('DECODER SECTION')
p1=p';
fprintf('\nthe H matrix is')
h=horzcat(p1,eye(q))
h1=h';
E=input('\nenter the recieved code');
for x=1:1:q
s(1,x)=0;
for y=1:1:n
s(1,x) = rem((s(1,x) + E(1,y)*h1(y,x)),2);
end
fprintf('\n synd%d= %d',x,s(1,x));
end
fprintf('\nthe syndrome in bit error is')
disp(s)
%CALCULATION FOR Dmin
disp('ERROR CORRECTION')
k2=2^k-1;
for d=1:1:k2
u = de2bi(d,k,'left-msb');
for i=1:1:q
co(1,i)=0;
for j=1:1:k
co(1,i)=rem((co(1,i) + u(1,j)*p(j,i)),2);
end
end
w(d)=sum(u)+sum(co);
a1(1,:)=[u co];
w1(d,:)=a1(1,:);
end
disp('the weight of codes for codeword is given as follows')
fprintf('\n\t codeword weight\n')
disp([w1 w'])
Dmin=w(1,1);
for i1=1:1:k2
if w(1,i1)<Dmin
Dmin=w(1,i1)
elseif w(1,i1)>Dmin
Dmin=w(1,1);
end
end
disp('the value of Dmin is:')
disp(Dmin)
disp('number of errors detected:')
a2=Dmin-1;
disp(a2)
disp('min number of errors can be corrected')
disp(floor(a2/2))
%ERROR CORRECTION
s1=bi2de(s,'left-msb');
s2=syndtable(h);
y=s2(s1,:);
disp('the corrected code is:')
xor(y,e)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -