资源描述:
《用matlab模拟FEC和交织两种方式.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、用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);>>x
2、2=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
3、);%产生加罗华域元素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=
4、[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)]
5、;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;%Statesforrand
6、omnumbergenerator
n=7;k=4;%ParametersforHammingcode
msg=randint(k*500,1,2,st1);%Datatoencode
code=encode(msg,n,k,'hamming/binary');%Encodeddata
%Createabursterrorthatwillcorrupttwoadjacentcodewords.
errors=zeros(size(code));errors(n-2:n+3)=[111111];
%WithInterleaving
%------------------
int
7、er=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:');
[