1.软件版本
MATLAB2021a
2.核心代码
登录后复制
%% Turbo Code % Encoder: RSC (Recursive Systematic Convolution)% Decoder: BCJR iterative decoder%% Parameter declarationclose all;clear all;clc;N=1e4; %Block lengthX=floor(2*rand(1,N)); %Information bit generationInterleaver=randperm(N); %Interleaver(random permutation of first N integers)SNRdB=0:0.5:9; %SNR in dBSNR=10.^(SNRdB/10); %SNR in linear scaleIteration=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-0C1=zeros(1,N); %Code Bit for encoder RSC-1for i=1:N k = i; while (k >= 1) C0(i) = xor ( C0(i),X(k) ); C1(i) = xor ( C1(i),X_pi(k) ); k=k-2; endendP0 = 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 respectivelyParity_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 Modulationmod_code_bit1=2*P0-1;mod_code_bit2=2*P1-1;fprintf('Encoding completed...\n');%% Decodingfor k=1:length(SNR) %Simulation starts here R0=sqrt(SNR(k))*mod_code_bit0+randn(1,N); % Received Codebits Corresponding to input bits R1=sqrt(SNR(k))*mod_code_bit1+randn(1,N); % Received Codebits Corresponding to parity bits of RSC-0 R2=sqrt(SNR(k))*mod_code_bit2+randn(1,N); % Received Codebits Corresponding to parity bits of RSC-1 R0_pi(1:N)=R0(Interleaver(1:N)); %Interleaving received codebits corresponding to input bits to be used by RSC-1 BCJR=0; %First iteration will be done by BCJR-0 Apriori=ones(2,N); %First row for prob. of i/p 0 and second row for prob. of i/p 1 Apriori=Apriori*0.5; %Initializing all apriori to 1/2 for iter=1:Iteration %Iterative process starts here if BCJR==0 %If BCJR is 0 then pass R0 and R1 to calculate GAMMA GAMMA=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 GAMMA GAMMA=gamma_1(Apriori,N,Input_matrix,Parity_bit_matrix,R0_pi,R2,SNR(k)); end ALPHA=alpha_1(GAMMA,N); %Calculation of ALPHA at each stage using GAMMA and ALPHA of previous stage BETA=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 values if BCJR==0 %If the decoder is BCJR-0 then ber(k,iter)=sum(abs((decoded_bits-X))); %calculate BER using input X lappr_2(1:N)=LAPPR_1(Interleaver(1:N)); %Interleave the LAPPR values and pass to BCJR-1 else %If the decoder is BCJR-1 then ber(k,iter)=sum(abs((decoded_bits-X_pi))); %calculate BER using input X_pi lappr_2(Interleaver(1:N))=LAPPR_1(1:N); %Re-interleave the LAPPR values and pass to BCJR-0 end LAPPR_1=lappr_2; ber(ber==1)=0; %Ignoring 1 bit error Apriori(1,1:N)=1./(1+exp(LAPPR_1)); %Apriori corresponding to input 0 Apriori(2,1:N)=exp(LAPPR_1)./(1+exp(LAPPR_1)); %Apriori corresponding to input 1 BCJR=~BCJR; %Changing the state of the decoder for the next iteration end %One iteration ends here u = k/length(SNR) * 100; string = [num2str(round(u)) , '% decoding completed ...']; disp(string);endber=ber/N;figure;%% Plots for simulated BERsemilogy(SNRdB,ber(:,1),'k--','linewidth',2.0);hold onsemilogy(SNRdB,ber(:,2),'m-o','linewidth',2.0);hold onsemilogy(SNRdB,ber(:,3),'b-<','linewidth',2.0);hold onsemilogy(SNRdB,ber(:,4),'r-<','linewidth',2.0);%% Theoretical expression for BER for corresponding convolution codeBER=zeros(1,length(SNR));for j=1:10 BER=BER+(2^j)*(j)*qfunc(sqrt((j+4)*SNR));endsemilogy(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 onaxis tight1.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.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.87.88.89.90.91.92.93.94.95.96.97.98.99.100.101.102.103.104.105.106.107.108.109.
3.操作步骤与仿真结论
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删