function a = ami_code(s) %s=[1101000000010010000001] sn=length(s); sg=1; a=s; for i=1:sn if a(i)==1 if mod(sg,2)==0 a(i)=-1; end sg=sg+1; end end n=20; y=zeros(1,n); x1=[ones(1,n/2) zeros(1,n/2)]; x0=zeros(1,n); x2=[-ones(1,n/2) zeros(1,n/2)]; z=zeros(size(1,n*sn)); for i=1:sn switch a(i) case 1 y=x1; case -1 y=x2; case 0 y=x0; end z(1,[(i-1)*n+1:i*n])=y; end ii=(1:n*sn)/n; plot(ii,z);grid on;ylabel('AMI编码'); 写出上述AMI码对应的解码代码及调用代码
时间: 2023-12-20 12:04:19 浏览: 84
解码代码如下:
function s = ami_decode(a)
sn = length(a);
s = zeros(1, sn);
sg = 1;
for i = 1:sn
if a(i) ~= 0
if mod(sg, 2) == 0
s(i) = 0;
else
s(i) = a(i);
end
sg = sg + 1;
end
end
调用代码如下:
s = [1 1 0 1 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1];
a = ami_code(s);
s_decode = ami_decode(a);
阅读全文