跪求高手利用MATLAB软件进行下列题目的实验仿真程序的编程方法。

2025-01-07 23:51:53
推荐回答(1个)
回答1:

n=15;
k=5;
g=[1 0 1 0 0 1 1 0 1 1 1];
m=mMatrix(k);
for i=0:2^k-1
nkm=[m(i+1,:) zeros(1,n-k)];
[q r]=deconv(nkm,g);
r=mod(r,2);
len_r=length(r);

r=[zeros(1,n-len_r) r];
c(i+1,:)=mod(nkm+r,2)
end;

for i=1:2^k
weight(i)=sum(c(i,:));
end;
minW=weight(2)
for i=3:2^k;
if weight(i) minW=weight(i);
else
end;
end;
c =

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 1 0 0 1 1 0 1 1 1
0 0 0 1 0 1 0 0 1 1 0 1 1 1 0
0 0 0 1 1 1 1 0 1 0 1 1 0 0 1
0 0 1 0 0 0 1 1 1 1 0 1 0 1 1
0 0 1 0 1 0 0 1 1 0 1 1 1 0 0
0 0 1 1 0 1 1 1 0 0 0 0 1 0 1
0 0 1 1 1 1 0 1 0 1 1 0 0 1 0
0 1 0 0 0 1 1 1 1 0 1 0 1 1 0
0 1 0 0 1 1 0 1 1 1 0 0 0 0 1
0 1 0 1 0 0 1 1 0 1 1 1 0 0 0
0 1 0 1 1 0 0 1 0 0 0 1 1 1 1
0 1 1 0 0 1 0 0 0 1 1 1 1 0 1
0 1 1 0 1 1 1 0 0 0 0 1 0 1 0
0 1 1 1 0 0 0 0 1 0 1 0 0 1 1
0 1 1 1 1 0 1 0 1 1 0 0 1 0 0
1 0 0 0 0 1 0 1 0 0 1 1 0 1 1
1 0 0 0 1 1 1 1 0 1 0 1 1 0 0
1 0 0 1 0 0 0 1 1 1 1 0 1 0 1
1 0 0 1 1 0 1 1 1 0 0 0 0 1 0
1 0 1 0 0 1 1 0 1 1 1 0 0 0 0
1 0 1 0 1 1 0 0 1 0 0 0 1 1 1
1 0 1 1 0 0 1 0 0 0 1 1 1 1 0
1 0 1 1 1 0 0 0 0 1 0 1 0 0 1
1 1 0 0 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0 0 0 0];
m(2,:)=[0 0 0 0 1];
for i=2:2^k-1;
t=i;
e=1;
d=2^e;
a=[0 0 0 0 0];
while 1;
if t>d;
e=e+1;
d=2^e;
else
break;
end;
end;
if t<2^e;
e=e-1;
end;
while 1;
if t-2^e==0;
a(k-e)=1;
break;
end;
if t-2^e>0;
a(k-e)=1;
t=t-2^e;
e=e-1;
else
a(k-e)=0;
e=e-1;
end;
end;
m(i+1,:)=a;
a=[0 0 0 0 0];
end;