输入以下是AMI码的解码代码和波形绘制代码: 解码代码: function s = ami_decode(a) n = length(a); s = zeros(1,n); sg = 1; for i = 1:n if a(i) == 0 s(i) = 0; elseif a(i) == 1 if mod(sg,2) == 0 s(i) = 0; else s(i) = 1; sg = sg + 1; end elseif a(i) == -1 if mod(sg,2) == 0 s(i) = 0; else s(i) = -1; sg = sg + 1; end end 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,nsn)); 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:in]) = y; end ii = (1:nsn)/n; plot(ii,z); grid on;时,MATLAB中只显示AMI编码的波形 AMI解码波形为空,应如何修改
时间: 2023-12-03 11:04:43 浏览: 116
基于MATLAB的AM调制解调,MATLAB代码
5星 · 资源好评率100%
根据提供的代码,AMI解码波形为空可能是因为解码代码中的s向量没有被正确赋值。可以尝试在解码代码中加入以下语句,以确保解码后的s向量被正确赋值:
```
s(i) = s(i-1);
```
修改后的解码代码如下:
```
function s = ami_decode(a)
n = length(a);
s = zeros(1,n);
sg = 1;
for i = 1:n
if a(i) == 0
s(i) = 0;
elseif a(i) == 1
if mod(sg,2) == 0
s(i) = 0;
else
s(i) = 1;
sg = sg + 1;
end
elseif a(i) == -1
if mod(sg,2) == 0
s(i) = 0;
else
s(i) = -1;
sg = sg + 1;
end
end
s(i) = s(i-1);
end
end
```
加入这个语句后,解码后的s向量就能正确赋值,AMI解码波形也能正确显示。
阅读全文