【Turbo】基于MATLAB的turbo编译码算法的仿真
生活随笔
收集整理的這篇文章主要介紹了
【Turbo】基于MATLAB的turbo编译码算法的仿真
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.軟件版本
MATLAB2021a
2.核心代碼
%% Turbo Code % Encoder: RSC (Recursive Systematic Convolution) % Decoder: BCJR iterative decoder%% Parameter declaration close all;clear all;clc; N=1e4; %Block length X=floor(2*rand(1,N)); %Information bit generation Interleaver=randperm(N); %Interleaver(random permutation of first N integers) SNRdB=0:0.5:9; %SNR in dB SNR=10.^(SNRdB/10); %SNR in linear scale Iteration=4; ber=zeros(length(SNR),Iteration); %Simulated BER(Each column corresponds to one iteration) %% Encoding X_pi(1:N)=X(Interleaver(1:N)); %Interleaving input bits for RSC-1 encoderC0=zeros(1,N); %Code Bit for encoder RSC-0 C1=zeros(1,N); %Code Bit for encoder RSC-1 for i=1:Nk = i;while (k >= 1)C0(i) = xor ( C0(i),X(k) );C1(i) = xor ( C1(i),X_pi(k) );k=k-2;end end P0 = xor (X,[0,C0(1:end-1)]); P1 = xor (X_pi,[0,C1(1:end-1)]);Input_matrix=2*[0,1;0,1;0,1;0,1]-1; %First column represents input=0 and second column represents input=1 %Each row represents state 00,10,01 and 11 respectively Parity_bit_matrix=2*[0,1;1,0;0,1;1,0]-1; %Parity bits corresponding to inputs of above matrixmod_code_bit0=2*X-1; %Modulating Code Bits using BPSK Modulation mod_code_bit1=2*P0-1; mod_code_bit2=2*P1-1; fprintf('Encoding completed...\n');%% Decoding for k=1:length(SNR) %Simulation starts hereR0=sqrt(SNR(k))*mod_code_bit0+randn(1,N); % Received Codebits Corresponding to input bitsR1=sqrt(SNR(k))*mod_code_bit1+randn(1,N); % Received Codebits Corresponding to parity bits of RSC-0R2=sqrt(SNR(k))*mod_code_bit2+randn(1,N); % Received Codebits Corresponding to parity bits of RSC-1R0_pi(1:N)=R0(Interleaver(1:N)); %Interleaving received codebits corresponding to input bits to be used by RSC-1BCJR=0; %First iteration will be done by BCJR-0Apriori=ones(2,N); %First row for prob. of i/p 0 and second row for prob. of i/p 1Apriori=Apriori*0.5; %Initializing all apriori to 1/2for iter=1:Iteration %Iterative process starts hereif BCJR==0 %If BCJR is 0 then pass R0 and R1 to calculate GAMMAGAMMA=gamma_1(Apriori,N,Input_matrix,Parity_bit_matrix,R0,R1,SNR(k));else %If BCJR is 1 then pass R0_pi and R2 to calculate GAMMAGAMMA=gamma_1(Apriori,N,Input_matrix,Parity_bit_matrix,R0_pi,R2,SNR(k));endALPHA=alpha_1(GAMMA,N); %Calculation of ALPHA at each stage using GAMMA and ALPHA of previous stageBETA=beta_1(GAMMA,N); %Calculation of BETA at each stage using GAMMA and BETA of next stage%Calculating LAPPR using ALPHA,BETA and GAMMA[~,~,LAPPR_1]=lappr(ALPHA,BETA,GAMMA,N);decoded_bits=zeros(1,N);decoded_bits(LAPPR_1>0)=1; %Decoding is done using LAPPR valuesif BCJR==0 %If the decoder is BCJR-0 thenber(k,iter)=sum(abs((decoded_bits-X))); %calculate BER using input Xlappr_2(1:N)=LAPPR_1(Interleaver(1:N)); %Interleave the LAPPR values and pass to BCJR-1else %If the decoder is BCJR-1 thenber(k,iter)=sum(abs((decoded_bits-X_pi))); %calculate BER using input X_pilappr_2(Interleaver(1:N))=LAPPR_1(1:N); %Re-interleave the LAPPR values and pass to BCJR-0endLAPPR_1=lappr_2;ber(ber==1)=0; %Ignoring 1 bit errorApriori(1,1:N)=1./(1+exp(LAPPR_1)); %Apriori corresponding to input 0Apriori(2,1:N)=exp(LAPPR_1)./(1+exp(LAPPR_1)); %Apriori corresponding to input 1BCJR=~BCJR; %Changing the state of the decoder for the next iterationend %One iteration ends hereu = k/length(SNR) * 100;string = [num2str(round(u)) , '% decoding completed ...'];disp(string); end ber=ber/N; figure; %% Plots for simulated BER semilogy(SNRdB,ber(:,1),'k--','linewidth',2.0); hold on semilogy(SNRdB,ber(:,2),'m-o','linewidth',2.0); hold on semilogy(SNRdB,ber(:,3),'b-<','linewidth',2.0); hold on semilogy(SNRdB,ber(:,4),'r-<','linewidth',2.0); %% Theoretical expression for BER for corresponding convolution code BER=zeros(1,length(SNR)); for j=1:10BER=BER+(2^j)*(j)*qfunc(sqrt((j+4)*SNR)); end semilogy(SNRdB,BER,'c-','linewidth',2.0) title('Turbo decoder performance over AWGN channel for BPSK modulated symbols'); xlabel('SNR(dB)');ylabel('BER'); legend('1st Iteration','2nd Iteration','3rd Iteration','4th Iteration','Theoretical Bound'); grid on axis tight3.操作步驟與仿真結論
4.參考文獻
[1] Berrou C . Near Shannon limit error-correcting coding and decoding : Turbo-codes[J]. Proc. ICC93, 1993.
D219
5.完整源碼獲得方式
方式1:微信或者QQ聯(lián)系博主
方式2:訂閱MATLAB/FPGA教程,免費獲得教程案例以及任意2份完整源碼
總結
以上是生活随笔為你收集整理的【Turbo】基于MATLAB的turbo编译码算法的仿真的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kettle(Pentaho Data
- 下一篇: AB罗克韦尔-pid教程