您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 经营企划 > Matlab仿真程序-Turbo码
%Thisscriptsimulatestheclassicalturboencoding-decodingsystem.%Itsimulatesparallelconcatenatedconvolutionalcodes.%Twocomponentrate1/2RSC(RecursiveSystematicConvolutional)componentencodersareassumed.%Firstencoderisterminatedwithtailsbits.(Info+tail)bitsarescrambledandpassedto%thesecondencoder,whilesecondencoderisleftopenwithouttailbitsofitself.%%Randominformationbitsaremodulatedinto+1/-1,andtransmittedthroughaAWGNchannel.%Interleaversarerandomlygeneratedforeachframe.%%Log-MAPalgorithmwithoutquantizationorapproximationisused.%Bymakinguseofln(e^x+e^y)=max(x,y)+ln(1+e^(-abs(x-y))),%theLog-MAPcanbesimplifiedwithalook-uptableforthecorrectionfunction.%Ifuseapproximationln(e^x+e^y)=max(x,y),itbecomesMAX-Log-MAP.%%CopyrightNov1998,YufeiWu%MPRGlab,VirginiaTech.%foracademicuseonlyclearall%Writedisplaymessagestoatextfilediaryturbo_logmap.txt%Choosedecodingalgorithmdec_alg=input('Pleaseenterthedecodingalgorithm.(0:Log-MAP,1:SOVA)default0');ifisempty(dec_alg)dec_alg=0;end%FramesizeL_total=input('Pleaseentertheframesize(=info+tail,default:400)');ifisempty(L_total)L_total=300;%infomationbitsplustailbitsend%Codegeneratorg=input('Pleaseentercodegenerator:(default:g=[111;101])');ifisempty(g)g=[111;101];end%g=[1101;1111];%g=[11111;10001];[n,K]=size(g);m=K-1;nstates=2^m;%puncture=0,puncturingintorate1/2;%puncture=1,nopuncturingpuncture=input('Pleasechoosepunctured/unpunctured(0/1):default0');ifisempty(puncture)puncture=0;end%Coderaterate=1/(2+puncture);%Fadingamplitude;a=1inAWGNchannela=1;%Numberofiterationsniter=input('Pleaseenternumberofiterationsforeachframe:default5');ifisempty(niter)niter=5;end%Numberofframeerrorstocountasastopcriteriorferrlim=input('Pleaseenternumberofframeerrorstoterminate:default15');ifisempty(ferrlim)ferrlim=15;endEbN0db=input('PleaseenterEb/N0indB:default[2.0]');ifisempty(EbN0db)EbN0db=[2.0];endfprintf('\n\n----------------------------------------------------\n');ifdec_alg==0fprintf('===Log-MAPdecoder===\n');elsefprintf('===SOVAdecoder===\n');endfprintf('Framesize=%6d\n',L_total);fprintf('codegenerator:\n');fori=1:nforj=1:Kfprintf('%6d',g(i,j));endfprintf('\n');endifpuncture==0fprintf('Punctured,coderate=1/2\n');elsefprintf('Unpunctured,coderate=1/3\n');endfprintf('iterationnumber=%6d\n',niter);fprintf('terminateframeerrors=%6d\n',ferrlim);fprintf('Eb/N0(dB)=');fori=1:length(EbN0db)fprintf('%10.2f',EbN0db(i));endfprintf('\n----------------------------------------------------\n\n');fprintf('++++Pleasebepatient.Waitawhiletogettheresult.++++\n');fornEN=1:length(EbN0db)en=10^(EbN0db(nEN)/10);%convertEb/N0fromunitdbtonormalnumbersL_c=4*a*en*rate;%reliabilityvalueofthechannelsigma=1/sqrt(2*rate*en);%standarddeviationofAWGNnoise%Clearbiterrorcounterandframeerrorcountererrs(nEN,1:niter)=zeros(1,niter);nferr(nEN,1:niter)=zeros(1,niter);nframe=0;%clearcounteroftransmittedframeswhilenferr(nEN,niter)ferrlimnframe=nframe+1;x=round(rand(1,L_total-m));%info.bits[temp,alpha]=sort(rand(1,L_total));%randominterleavermappingen_output=encoderm(x,g,alpha,puncture);%encoderoutput(+1/-1)r=en_output+sigma*randn(1,L_total*(2+puncture));%receivedbitsyk=demultiplex(r,alpha,puncture);%demultiplextogetinputfordecoder1and2%Scalethereceivedbitsrec_s=0.5*L_c*yk;%InitializeextrinsicinformationL_e(1:L_total)=zeros(1,L_total);foriter=1:niter%DecoderoneL_a(alpha)=L_e;%aprioriinfo.ifdec_alg==0L_all=logmapo(rec_s(1,:),g,L_a,1);%completeinfo.elseL_all=sova0(rec_s(1,:),g,L_a,1);%completeinfo.endL_e=L_all-2*rec_s(1,1:2:2*L_total)-L_a;%extrinsicinfo.%DecodertwoL_a=L_e(alpha);%aprioriinfo.ifdec_alg==0L_all=logmapo(rec_s(2,:),g,L_a,2);%completeinfo.elseL_all=sova0(rec_s(2,:),g,L_a,2);%completeinfo.endL_e=L_all-2*rec_s(2,1:2:2*L_total)-L_a;%extrinsicinfo.%Estimatetheinfo.bitsxhat(alpha)=(sign(L_all)+1)/2;%Numberofbiterrorsincurrentiterationerr(iter)=length(find(xhat(1:L_total-m)~=x));%Countframeerrorsforthecurrentiterationiferr(iter)0nferr(nEN,iter)=nferr(nEN,iter)+1;endend%iter%Totalnumberofbiterrorsforalliterationserrs(nEN,1:niter)=errs(nEN,1:niter)+err(1:niter);ifrem(nframe,3)==0|nferr(nEN,niter)==ferrlim%Biterrorrateber(nEN,1:niter)=errs(nEN,1:niter)/nframe/(L_total-m);%Frameerrorratefer(nEN,1:niter)=nferr(nEN,1:niter)/nframe;%Displayintermediateresultsinprocessfprintf('**************Eb/N0=%5.2fdb**************\n',EbN0db(nEN));fprintf('Framesize=%d,rate1/%d.\n',L_total,2+puncture);fprintf('%dframestransmitted,%dframesinerror.\n',nframe,nferr(nEN,niter));fprintf('BitErrorRate(fromiteration1toiteration%d):\n',niter);fori=1:niterfprintf('%8.4e',ber(nEN,i));endfprintf('\n');fprintf('FrameErrorRate(fromiteration1toiteration%d):\n',niter);fori=1:niterfprintf('%8.4e',fer(nEN,i));endfprintf('\n');fprintf('***********************************************\n\n');%Saveintermediateresultssaveturbo_sys_demoEbN0dbberferend%iterend%whileend%nENdiaryofffunction[next_out,next_state,last_out,last_state]=trellis(g)%copyrightNov.1998YufeiWu%MPRGlab,VirginiaTech%foracademicuseonly%setupthetrellisgivencodegeneratorg%ggiveninbinarymatrixform.e.g.g=[111;101];%next_o
本文标题:Matlab仿真程序-Turbo码
链接地址:https://www.777doc.com/doc-4234563 .html