作者在 2008-07-29 23:57:45 发布以下内容
RS编码的matlab仿真(m文件仿真)
对加入突发噪声信道的RS(15,11)编码进行的仿真:代码如下:
L=1000;
M=4;%每个符号的比特数
N=2^M-1;%编码后码字长度
K=N-4;%信息长度
MSG=randint(L,1);%随机产生L比特信号
TP=gftuple([-1:N-1]',M);%产生加罗华域元素
PG=rspoly(N,K);%产生生成式
[CODE,ADDED]=rsenco(MSG,TP,K);%编码
NOI=rand(length(CODE)/M,1)<.03;%加入3%的噪声
NOI=(NOI*ones(1,M))';%产生突发错误
NOI=NOI(:);
CODE_NOI=rem(CODE+NOI,2);%噪声加入信号
[DEC,ERR,CCODE,ERR_C]=rsdeco(CODE_NOI,TP,K);%译码
MSG=[MSG;zeros(ADDED,1)];%调整长度
max(abs(DEC-MSG));%比较
X=[1:length(NOI)];
Z=[1:M*N:length(NOI)];
Y=zeros(1,length(Z));
Z=[Z;Z];
Y=[Y+min(ERR_C);Y+max(ERR_C)];
subplot(211);
plot(X,NOI,'yo',X,ERR_C,'rx',Z,Y,'g-');
title('Error Detection Record');
xlabel('o--placed error;x--detected error;vertical bar: RS-DECO section.');
axis([1,length(NOI),min(ERR_C),max(ERR_C)]);
X=[1:length(MSG)];
Z=[1:M*K:length(MSG)];
Y=zeros(1,length(Z));
Z=[Z;Z];
Y=[Y;Y+max(MSG)];
subplot(212);
plot(X,MSG,'yo',X,DEC,'rx',Z,Y,'g-');
title('Message and Decoded Signal Comparison');
xlabel('o--original message;x--decoded result.');
axis([1,length(MSG),min(min(MSG)),max(max(MSG))]);
对加入突发噪声信道的RS(15,11)编码进行的仿真:代码如下:
L=1000;
M=4;%每个符号的比特数
N=2^M-1;%编码后码字长度
K=N-4;%信息长度
MSG=randint(L,1);%随机产生L比特信号
TP=gftuple([-1:N-1]',M);%产生加罗华域元素
PG=rspoly(N,K);%产生生成式
[CODE,ADDED]=rsenco(MSG,TP,K);%编码
NOI=rand(length(CODE)/M,1)<.03;%加入3%的噪声
NOI=(NOI*ones(1,M))';%产生突发错误
NOI=NOI(:);
CODE_NOI=rem(CODE+NOI,2);%噪声加入信号
[DEC,ERR,CCODE,ERR_C]=rsdeco(CODE_NOI,TP,K);%译码
MSG=[MSG;zeros(ADDED,1)];%调整长度
max(abs(DEC-MSG));%比较
X=[1:length(NOI)];
Z=[1:M*N:length(NOI)];
Y=zeros(1,length(Z));
Z=[Z;Z];
Y=[Y+min(ERR_C);Y+max(ERR_C)];
subplot(211);
plot(X,NOI,'yo',X,ERR_C,'rx',Z,Y,'g-');
title('Error Detection Record');
xlabel('o--placed error;x--detected error;vertical bar: RS-DECO section.');
axis([1,length(NOI),min(ERR_C),max(ERR_C)]);
X=[1:length(MSG)];
Z=[1:M*K:length(MSG)];
Y=zeros(1,length(Z));
Z=[Z;Z];
Y=[Y;Y+max(MSG)];
subplot(212);
plot(X,MSG,'yo',X,DEC,'rx',Z,Y,'g-');
title('Message and Decoded Signal Comparison');
xlabel('o--original message;x--decoded result.');
axis([1,length(MSG),min(min(MSG)),max(max(MSG))]);