差错控制编码解决加性噪声 第11页
error=abs(error);
errorrate=sum(error)/100
infor=randsrc(1,100,[0,1]); %产生信息infor(序列)
for n=1:100 %将infor改为波形singl
for m=1:10
i=(n-1)*10+m;
singl(i)=infor(n);
end
end
subplot(3,1,1);plot(0:0.01:9.99,singl),title('输入信号') %画出singl的波形
axis([0 1 -1 2]);
noise=randn(1,1000)*0.3 %产生噪声noise,幅度为0.3
noisesingl=singl+noise; %将噪声加入信号
subplot(3,1,2);plot(0:0.01:9.99,noisesingl),title('加入噪声的输出信号') %画出noisesingl的波形
axis([0 1 -1 2]);
for n=1:100 %对noisesingl进行采样,判决(门限为0.5)
for m=1:10
i=(n-1)*10+m;
result(n)=noisesingl(i);
if result(n)>0.5
result(n)=1;
else result(n)=0
end
end
end
for n=1:100 %将判决结果result(序列)改为波形out
for m=1:10
i=(n-1)*10+m;
out(i)=result(n);
end
end
subplot(3,1,3);plot(0:0.01:9.99,out),title('输出信号'),xlabel('时间') %画出的out波形
axis([0 1 -1 2]);
error=infor-result; %计算误码率
error=abs(error);
errorrate=sum(error)/100
clear
infor=randsrc(1,100,[0,1]); %产生信息infor(序列)
for n=1:100 %将infor改为波形singl
for m=1:10
i=(n-1)*10+m;
singl(i)=infor(n);
end
end
figure(1);subplot(3,1,1);plot(0:0.01:9.99,singl),title('输入信号') %画出singl的波形
axis([0 1 -1 2]);
noise=randn(1,1000)*0.3 %产生噪声noise,幅度为0.3
noisesingl=singl+noise; %将噪声加入信号
figure(2);subplot(3,1,1);plot(0:0.01:9.99,noisesingl),title('加入噪声的输出信号') %画出noisesingl的波形
axis([0 1 -1 2]);
for n=1:100 %对noisesingl进行采样,判决(门限为0.5)
for m=1:10
i=(n-1)*10+m;
result(n)=noisesingl(i);
if result(n)>0.5
result(n)=1;
else result(n)=0
end
end
end
for n=1:100 %将判决结果result(序列)改为波形out
for m=1:10
i=(n-1)*10+m;
out(i)=result(n);
end
end
figure(1);subplot(3,1,2);plot(0:0.01:9.99,out),title('没有编码的输出信号'); %画出的out波形
axis([0 1 -1 2]);
error=infor-result; %计算误码率
error=abs(error);
%加入“7,4汉明”编码后的情况
x=encode(infor,7,4,'hamming');x=x' %对infor进行“7,4汉明”编码
for n=1:175 %将编码结果x(序列)改为波形codesingl
for m=1:10
i=(n-1)*10+m;
codesingl(i)=x(n);
end
end
figure(2);subplot(3,1,2);plot(0:0.01:17.49,codesingl),title('汉明码波形') %画出codesingl的波形
axis([0 1 -1 2]);
noise1=randn(1,1750)*0.3 %产生噪声noise,幅度为0.3
noisesingl1=codesingl+noise1; %将噪声加入信号
figure(2);subplot(3,1,3);plot(0:0.01:17.49,noisesingl1),title('有噪声的汉明码波形'),xlabel('时间'); %画出noisesingl1的波形
for n=1:175 %对noisesingl进行采样,判决(门限为0.5)
for m=1:10
i=(n-1)*10+m;
result1(n)=noisesingl1(i);
if result1(n)>0.5
result1(n)=1;
else result1(n)=0
end
end
end
y=decode(result1,7,4,'hamming');y=y' %将判决结果result(序列)进行解码
for n=1:100 %将解码结果y(序列)改为波形out1
for m=1:10
i=(n-1)*10+m;
out1(i)=y(n);
end
end
figure(1);subplot(3,1,3);plot(0:0.01:9.99,out1),title('有hamming码的输出信号'),xlabel('时间') %画出的out1波形
axis([0 1 -1 2]);
error1=infor-y; %计算误码率
error1=abs(error1);
errorrate=sum(error)/100 %有噪声,无编码的误码率
errorrate1=sum(error1)/100 %有噪声,有hamming(7,4)编码的误码率
clear
infor=randsrc(1,100,[0,1]); %产生信息infor(序列)
for n=1:100 %将infor改为波形singl
for m=1:10
i=(n-1)*10+m;
singl(i)=infor(n);
end
end
figure(1);subplot(3,1,1);plot(0:0.01:9.99,singl),title('输入信号') %画出singl的波形
axis([0 1 -1 2]);
noise=randn(1,1000)*0.3 %产生噪声noise,幅度为0.3
noisesingl=singl+noise; %将噪声加入信号
figure(2);subplot(3,1,1);plot(0:0.01:9.99,noisesingl),title('加入噪声的输出信号') %画出noisesingl的波形
axis([0 1 -1 2]);
for n=1:100 %对noisesingl进行采样,判决(门限为0.5)
for m=1:10
for m=1:10
i=(n-1)*10+m;
out(i)=result(n);
end
<< 上一页 [11] [12] [13] [14] [15] 下一页