您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 用matlab模拟FEC和交织两种方式
用matlab模拟FEC和交织两种方式FEC(前向纠错方式):交织s1=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56];x1=(reshape(s1,8,7))';x1(2,2)=0;x1(2,3)=0;x1(2,4)=0;x1(2,5)=0;s2=reshape(x1,1,56);x2=reshape(s2,7,8);x2(2,2)=10;x2(2,3)=11;s3=reshape(x2',1,56);a=[s1,s2,s3];plot(s1,s2);x1=123456789000014151617181920212223242526272829303132333435363738394041424344454647484950515253545556L=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('ErrorDetectionRecord');xlabel('o--placederror;x--detectederror;verticalbar:RS-DECOsection.');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('MessageandDecodedSignalComparison');xlabel('o--originalmessage;x--decodedresult.');axis([1,length(MSG),min(min(MSG)),max(max(MSG))]);st1=27221;st2=4831;%Statesforrandomnumbergeneratorn=7;k=4;%ParametersforHammingcodemsg=randint(k*500,1,2,st1);%Datatoencodecode=encode(msg,n,k,'hamming/binary');%Encodeddata%Createabursterrorthatwillcorrupttwoadjacentcodewords.errors=zeros(size(code));errors(n-2:n+3)=[111111];%WithInterleaving%------------------inter=randintrlv(code,st2);%Interleave.inter_err=bitxor(inter,errors);%Includebursterror.deinter=randdeintrlv(inter_err,st2);%Deinterleave.decoded=decode(deinter,n,k,'hamming/binary');%Decode.disp('Numberoferrorsanderrorrate,withinterleaving:');[number_with,rate_with]=biterr(msg,decoded)%Errorstatistics%WithoutInterleaving%---------------------code_err=bitxor(code,errors);%Includebursterror.decoded=decode(code_err,n,k,'hamming/binary');%Decode.disp('Numberoferrorsanderrorrate,withoutinterleaving:');[number_without,rate_without]=biterr(msg,decoded)%ErrorstatisticsNumberoferrorsanderrorrate,withinterleaving:number_with=0rate_with=0Numberoferrorsanderrorrate,withoutinterleaving:number_without=4rate_without=0.0020msg=randint(k*500,1,2,st1);code=encode(msg,n,k,'hamming/binary');errors=zeros(size(code));errors(n-2:n+3)=[111111];inter=randintrlv(code,st2);inter_err=bitxor(inter,errors);deinter=randdeintrlv(inter_err,st2);decoded=decode(deinter,n,k,'hamming/binary');disp('Numberoferrorsanderrorrate,withinterleaving:');Numberoferrorsanderrorrate,withinterleaving:code_err=bitxor(code,errors);decoded=decode(code_err,n,k,'hamming/binary');disp('Numberoferrorsanderrorrate,withoutinterleaving:');Numberoferrorsanderrorrate,withoutinterleaving:[number_without,rate_without]=biterr(msg,decoded);L=1000;M=4;%每个符号的比特数N=2^M-1;%编码后码字长度K=N-4;%信息长度MSG=randint(L,1);%随机产生L比特信号TP=gftuple([-1:N-1]',M);%产生加罗华域元素PG=rsgenpoly(N,K);%产生生成式[CODE,ADDED]=rsenco(MSG,TP,K);%编码R=[0:0.01:1];%错误率forj=1:length(R)%循环修改错误率NOI=rand(length(CODE)/M,1)R(j);%加入R%的噪声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)];%调整长度error=0;%错误码计数初值Q=length(DEC);%码长度fori=1:Q%循环寻找错误码if(MSG(i)~=DEC(i))error=error+1;endendp(j)=error/Q;%误码率
本文标题:用matlab模拟FEC和交织两种方式
链接地址:https://www.777doc.com/doc-4740347 .html