clear;clc;
N=10000;%测试10000个数据
%信息数据
Msg=unidrnd(16,1,N*11)-1;%生成0~15的随机数
RsCode0=zeros(1,N*15);
%编码
for i=1:N
RsCode0(i*15-14:i*15)=RsEncode(Msg(i*11-10:i*11));
end
RsCode=zeros(1,length(RsCode0)*4);
list=zeros(16,4);%0~16对应二进制码表
for i=1:15
list(i+1,4)=xor(list(i+1,4),4);
if(list(i+1,4)==0)
list(i+1,3)=xor(list(i+1,3),1);
if(list(i+1,3)==0)
list(i+1,2)=xor(list(i+1,2),1);
if(list(i+1,2)==0)
list(i+1,1)=xor(list(i+1,1),1);
end
end
end
if(i~=15)
list(i+2,:)=list(i+1,:);
end
end%这里只是为了方便后面做十进制到二进制的转换
for i=(1:length(RsCode0))
RsCode(4*(i-1)+1:4*(i-1)+4)=list(RsCode0(i)+1,:);
end%十进制转二进制
RsCode=1-2*RsCode;%(0,1)变(1,-1);
%调制(BPSK)
RsCode1=upsample(RsCode,8);%八倍过采样
n=(1:1:161);
SSinc=sinc((n-81)/80*10);%sinc函数卷积
y=conv(RsCode1,SSinc);
y=y(81:length(y)-80);%去掉两边多余的卷积数
%模拟高斯白噪声信道信道
EbN0=(0:15);%测试信噪比从0~15dB
rate_s=zeros(1,length(EbN0));
rate_f=zeros(1,length(EbN0));%计算误码率和误帧率
for x=EbN0
y_n=awgn(y,x,'measured');%叠加噪声
%接收信号
y_receive=zeros(1,N*15*4);
for i=(0:length(y_receive)-1)
if(y_n(i*8+1)>0)
y_receive(i+1)=0;
else
y_receive(i+1)=1;
end
end%判决
%解调
y_code=zeros(1,N*15);
for i=1:N*15
for j=1:16
if(y_receive(i*4-3:i*4)==list(j,:))
y_code(i)=j-1;
end
end
end%二进制转十进制
y_decode=zeros(1,length(y_code));
%解码
for i=1:N%一个码字一个码字进行解码
RsCodeWithNoise=y_code(i*15-14:i*15);
SyndromCalc = RsDecodeCalcSynd(RsCodeWithNoise);%计算伴随式
[ErrorPosPolyCalc, SigmaCalc] = RsDecodeIterate(SyndromCalc);%计算错误位置多项式
[RootCalc] = RsDecodeRoot(ErrorPosPolyCalc);%错误位置多项式求根
[ErrorValueCalc, ErrorPositionCalc] = RsDecodeForney(SyndromCalc, ErrorPosPolyCalc, RootCalc);%计算错误位置和错误数据
for j=(1:length(ErrorPositionCalc))
RsCodeWithNoise(ErrorPositionCalc(j)+1)=RsSymbolAdd(RsCodeWithNoise(ErrorPositionCalc(j)+1),ErrorValueCalc(j));
end%根据错误数据修改码字
y_decode(i*15-14:i*15)=RsCodeWithNoise;
end
error_s=0;error_f=0;%记录错误数量
for i=(1:N)
error_temp=error_s;
for j=(1:15)
if(y_decode(i*15-15+j)~=RsCode0(i*15-15+j))
error_s=error_s+1;
end
end
if(error_s~=error_temp)
error_f=error_f+1;
end%如果一帧中任意一个错了,就算这帧是错的
end
rate_s(x+1)=error_s/(N*15);
rate_f(x+1)=error_f/N;
end
semilogy(EbN0,rate_s,'-b*',EbN0,rate_f,'-r^');
legend('Error Symbol Ratio','Error Frame Ratio');
grid on;
title('Rs Code Performance');
xlabel('Eb/N0');
%画图显示误码率、误帧率随信噪比的变化曲线
评论1