天天看點

【polar】協作polar碼和非協作polar碼的誤碼率性能matlab仿真

1.軟體版本

matlab2017b

2.本算法理論知識

《基于Polar碼的協作編碼和分集技術研究》

【polar】協作polar碼和非協作polar碼的誤碼率性能matlab仿真

3.部分源碼

clc;
clear all;
close all;
warning off;
addpath 'functions\'

%資料塊大小
SNR        = [1,2,3,4,4.5];  
rate1      = 0.54;
rate2      = 0.45;

n          = 8;
N          = 2^n;  
[Vals,Inds]= func_rates(n,0.5);

for i=1:length(SNR)

    %設定誤碼率參數
    Bit_err(i)    = 0; 
    Num_err       = 0; 
    %誤碼率累加器
    Numbers       = 0; 
    K1            = round(rate1*N);
    K2            = round(rate2*N);    
    
    frozen_pos1   = Inds(1:N-K1);
    free_pos1     = sort(Inds(N-K1+1:N),'ascend');
    
    frozen_pos2   = Inds(1:N-K2);
    free_pos2     = sort(Inds(N-K2+1:N),'ascend');   
 
    
    z1             = ones(N,1);
    z1(frozen_pos1)= 0;
    z2             = ones(N,1);
    z2(frozen_pos2)= 0;    
    
    sigma         = 1/sqrt(10^(SNR(i)/10));
    
    while Num_err <= 50000  
          fprintf('SNR = %f\n', SNR(i));
          Num_err
          data_in1     = randsrc(K1,1,[0 1]);
          u            = zeros(N,1);
          u(free_pos1) = data_in1; 
          x            = func_encode(u);
          Trans_BPSK   = 2*x-1;
          %S->D 
          %S->D 
          Rec_sd_1               = Trans_BPSK + sigma*randn(N,1);
          Rec_sd                 = Rec_sd_1;
          
          %S->R
          %S->R
          Rec_sr_1               = Trans_BPSK + sigma*randn(N,1);
          Rec_sr                 = Rec_sr_1;
          %中繼點的判決
          %先譯碼
          y1                     = Rec_sr;
          L1                     = exp(-2*y1); 
          v1                     = func_SCdecoder(L1,z1);
          data_out1              = v1(free_pos1);
          
          
          
          u2                     = zeros(N,1);
          u2(free_pos2)          = data_out1(1:K2)'; 
          
          
          x2                     = func_encode(u2);
          Trans_BPSK2            = 2*x2-1;   
          Rec_rd_1               = Trans_BPSK2 + sigma*randn(N,1);
          Rec_rd                 = Rec_rd_1;
          
          %接收端
          y2                     = Rec_sd;
          L2                     = exp(-2*y2); 
          v2                     = func_SCdecoder(L2,z2);
          data_out2              = v2(free_pos2);
          
          
          y3                     = Rec_rd;
          L3                     = exp(-2*y3);           
          v3                     = func_SCdecoder(L3,z2);
          data_out3              = v3(free_pos2);

          nberr1      = length(find(data_out2~=data_in1(1:K2)'));
          nberr2      = length(find(data_out3~=data_in1(1:K2)'));
          
          Num_err     = Num_err+min(nberr1,nberr2);
          Numbers     = Numbers+1;
    end
    Bit_err(i) = Num_err/(length(data_in1)*Numbers);
end


save R3.mat SNR Bit_err      

4.仿真結論

【polar】協作polar碼和非協作polar碼的誤碼率性能matlab仿真

5.參考文獻

繼續閱讀