⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dem_dfusc_2x2_stbc_convcode.m

📁 该文件夹为空时块码-卷积码级联系统的仿真程序
💻 M
字号:
function [ber,mse]=dem_DFUSC_2x2_STBC_Convcode(demparams,NoisePwr,ipfid_rx1,ipfid_rx2)

PwNorm_data=sqrt(2048/1536);     % data symbol power normalization factor
% load original data
load orig_DFUSC_QAM16_bit.mat;
load orig_DFUSC_QAM16.mat;
load Wk_preamble.mat;

logfile_ber='temp_ber.txt';

    % get preamble modulation and index values
    preamble_index_tx1=1:2:1702;    % Tx 1 use even subcarriers
    preamble_index_tx2=0:2:1702;    % Tx 2 use odd subcarriers
    preamble_mod_tx1=sqrt(2)*sqrt(2)*2*(0.5-Wk_preamble(2:2:end));  % Note: include DC. At No.426 element
    preamble_mod_tx2=sqrt(2)*sqrt(2)*2*(0.5-Wk_preamble(1:2:end));

    % ######## Perfect Channel Estimation ########
    switch demparams.chantype,
        case 1,
            load perfectCE_sui1_11.mat;
            load perfectCE_sui1_21.mat;
            load perfectCE_sui1_12.mat;
            load perfectCE_sui1_22.mat;
        case 2,
            load perfectCE_sui2_11.mat;
            load perfectCE_sui2_21.mat;
            load perfectCE_sui2_12.mat;
            load perfectCE_sui2_22.mat;
        case 3,
            load perfectCE_sui3_11.mat;
            load perfectCE_sui3_21.mat;
            load perfectCE_sui3_12.mat;
            load perfectCE_sui3_22.mat;
        case 4,
            load perfectCE_sui4_11.mat;
            load perfectCE_sui4_21.mat;
            load perfectCE_sui4_12.mat;
            load perfectCE_sui4_22.mat;
        case 5,
            load perfectCE_sui5_11.mat;
            load perfectCE_sui5_21.mat;
            load perfectCE_sui5_12.mat;
            load perfectCE_sui5_22.mat;
        case 6,
            load perfectCE_sui6_11.mat;
            load perfectCE_sui6_21.mat;
            load perfectCE_sui6_12.mat;
            load perfectCE_sui6_22.mat;
        otherwise,
            error('Unknown SUI channel type!');
    end
    perfectCE_11(:,1794:2048)=[]; perfectCE_11(:,1:256)=[];
    perfectCE_21(:,1794:2048)=[]; perfectCE_21(:,1:256)=[];
    perfectCE_12(:,1794:2048)=[]; perfectCE_12(:,1:256)=[];
    perfectCE_22(:,1794:2048)=[]; perfectCE_22(:,1:256)=[];
    % ################################################################
    
biterr=zeros(1,demparams.iteration);   % used to calculate bit error rate per iteration
suberr=0;
mse=0;
databitnum=demparams.numframe*demparams.sympf*1536*log2(demparams.qam)/2;  % data bits number

for frm=1:demparams.numframe
    % ############## When use Known Channel Knowledge #############
    %FullChanEst_11=PwNorm_data*perfectCE_11(frm,:);
    %FullChanEst_21=PwNorm_data*perfectCE_21(frm,:);
    %FullChanEst_12=PwNorm_data*perfectCE_12(frm,:);
    %FullChanEst_22=PwNorm_data*perfectCE_22(frm,:);
    % #############################################################
    
    % use preamble for channel estimation
       %---------- Path 11 and 21-------------
    [preamble_time_rx1, symlen] = fread(ipfid_rx1, 2*2048*(1+demparams.Guard), 'float32');
    if symlen~=2*2048*(1+demparams.Guard), error('fread Rx 1 input data error!'); end
    preamble_time_rx1 =  [ 1 1j ] * reshape(preamble_time_rx1, 2, symlen/2);
    symlen=symlen/2;
    % remove CP
    preamble_time_rx1=preamble_time_rx1((2048*demparams.Guard+1):end);
            % ###### Time domain ls estimation ######
            [FullChanEst_11,FullChanEst_21]=ls_time_2x2_code((preamble_time_rx1).',demparams.chantype,demparams.sampletime);
            FullChanEst_11=PwNorm_data*FullChanEst_11; FullChanEst_21=PwNorm_data*FullChanEst_21;
            % #######################################
    % FFT
 %   preamble_freq_rx1=fftshift(fft(preamble_time_rx1,2048)/sqrt(2048));
    % Trim Guard subcarriers
 %   preamble_freq_rx1(1877:2048)=[];  preamble_freq_rx1(1:173)=[];
            % ###### Extract preamble pilots AND Channel Estimation ######
 %           preamble_pilots_tx1=preamble_freq_rx1(preamble_index_tx1+1);
 %           preamble_pilots_tx2=preamble_freq_rx1(preamble_index_tx2+1);
 %           ChanEst_11=ls_freq(preamble_pilots_tx1,preamble_mod_tx1);
 %           ChanEst_21=ls_freq(preamble_pilots_tx2,preamble_mod_tx2);
            % Interpolate  Note: If interpolate 'Tx1', must remove DC
 %           FullChanEst_11=interpolate_2x2(preamble_index_tx1+1,ChanEst_11,'linear','Tx1');
 %           FullChanEst_21=interpolate_2x2(preamble_index_tx2+1,ChanEst_21,'linear','Tx2');
            % ############################################################
            
       %------------ Pathe 12 and 22-----------
    [preamble_time_rx2, symlen] = fread(ipfid_rx2, 2*2048*(1+demparams.Guard), 'float32');
    if symlen~=2*2048*(1+demparams.Guard), error('fread Rx 2 input data error!'); end
    preamble_time_rx2 =  [ 1 1j ] * reshape(preamble_time_rx2, 2, symlen/2);
    symlen=symlen/2;
    % remove CP
    preamble_time_rx2=preamble_time_rx2((2048*demparams.Guard+1):end);
            % ###### Time domain ls estimation ######
            [FullChanEst_12,FullChanEst_22]=ls_time_2x2_code((preamble_time_rx2).',demparams.chantype,demparams.sampletime);
            FullChanEst_12=PwNorm_data*FullChanEst_12; FullChanEst_22=PwNorm_data*FullChanEst_22;
            % #######################################
    % FFT
 %   preamble_freq_rx2=fftshift(fft(preamble_time_rx2,2048)/sqrt(2048));
    % Trim Guard subcarriers
 %   preamble_freq_rx2(1877:2048)=[];  preamble_freq_rx2(1:173)=[];
            % ###### Extract preamble pilots AND Channel Estimation ######
 %           preamble_pilots_tx1=preamble_freq_rx2(preamble_index_tx1+1);
 %           preamble_pilots_tx2=preamble_freq_rx2(preamble_index_tx2+1);
 %           ChanEst_12=ls_freq(preamble_pilots_tx1,preamble_mod_tx1);
 %           ChanEst_22=ls_freq(preamble_pilots_tx2,preamble_mod_tx2);
            % Interpolate  Note: If interpolate 'Tx1', must remove DC
 %           FullChanEst_12=interpolate_2x2(preamble_index_tx1+1,ChanEst_12,'linear','Tx1');
 %           FullChanEst_22=interpolate_2x2(preamble_index_tx2+1,ChanEst_22,'linear','Tx2');
            % ############################################################
            

    % ############# Temporal estimation ###################
  %  [FullChanEst_11,FullChanEst_21,FullChanEst_12,FullChanEst_22] ...
  %      =temporal_ml_2x2(fftshift(preamble_freq_rx1),fftshift(preamble_freq_rx2),demparams.chantype,demparams.sampletime);
    % #####################################################
        % ###### MSE Calculation ######
        mse=mse+sum(abs(PwNorm_data*perfectCE_11(frm,:)-FullChanEst_11).^2)/1703 ...
               +sum(abs(PwNorm_data*perfectCE_21(frm,:)-FullChanEst_21).^2)/1703 ...
               +sum(abs(PwNorm_data*perfectCE_12(frm,:)-FullChanEst_12).^2)/1703 ...
               +sum(abs(PwNorm_data*perfectCE_22(frm,:)-FullChanEst_22).^2)/1703;
           
           % Remove DC
            FullChanEst_11(769)=[];
            FullChanEst_21(769)=[];
            FullChanEst_12(769)=[];
            FullChanEst_22(769)=[];
            
    for sym=1:2:demparams.sympf  % Alamouti Receive Scheme
        % ------Rx 1 at Symbol 1------
        [sym_time, symlen] = fread(ipfid_rx1, 2*2048*(1+demparams.Guard), 'float32');
        if symlen~=2*2048*(1+demparams.Guard), error('fread channel output data error!'); end
        sym_time =  [ 1 1j ] * reshape(sym_time, 2, symlen/2);
        symlen=symlen/2;
        % remove CP
        sym_time=sym_time((2048*demparams.Guard+1):end);
        % FFT
        sym_freq_R1_S1=fftshift(fft(sym_time,2048)/sqrt(2048));     % Rx 1,Symbol 1
        % ##### Trim Guard subcarriers #####
             sym_freq_R1_S1(1794:2048)=[];  sym_freq_R1_S1(1:256)=[];
        % Remove DC
             sym_freq_R1_S1(769)=[];
             
        % ------Rx 1 at Symbol 2------
        [sym_time, symlen] = fread(ipfid_rx1, 2*2048*(1+demparams.Guard), 'float32');
        if symlen~=2*2048*(1+demparams.Guard), error('fread channel output data error!'); end
        sym_time =  [ 1 1j ] * reshape(sym_time, 2, symlen/2);
        symlen=symlen/2;
        % remove CP
        sym_time=sym_time((2048*demparams.Guard+1):end);
        % FFT
        sym_freq_R1_S2=fftshift(fft(sym_time,2048)/sqrt(2048));     % Rx 1,Symbol 2
        % ##### Trim Guard subcarriers #####
             sym_freq_R1_S2(1794:2048)=[];  sym_freq_R1_S2(1:256)=[];
        % Remove DC
             sym_freq_R1_S2(769)=[];
             
        % ------Rx 2 at Symbol 1------
        [sym_time, symlen] = fread(ipfid_rx2, 2*2048*(1+demparams.Guard), 'float32');
        if symlen~=2*2048*(1+demparams.Guard), error('fread channel output data error!'); end
        sym_time =  [ 1 1j ] * reshape(sym_time, 2, symlen/2);
        symlen=symlen/2;
        % remove CP
        sym_time=sym_time((2048*demparams.Guard+1):end);
        % FFT
        sym_freq_R2_S1=fftshift(fft(sym_time,2048)/sqrt(2048));     % Rx 2,Symbol 1
        % ##### Trim Guard subcarriers #####
             sym_freq_R2_S1(1794:2048)=[];  sym_freq_R2_S1(1:256)=[];
        % Remove DC
             sym_freq_R2_S1(769)=[];
             
        % ------Rx 2 at Symbol 2------
        [sym_time, symlen] = fread(ipfid_rx2, 2*2048*(1+demparams.Guard), 'float32');
        if symlen~=2*2048*(1+demparams.Guard), error('fread channel output data error!'); end
        sym_time =  [ 1 1j ] * reshape(sym_time, 2, symlen/2);
        symlen=symlen/2;
        % remove CP
        sym_time=sym_time((2048*demparams.Guard+1):end);
        % FFT
        sym_freq_R2_S2=fftshift(fft(sym_time,2048)/sqrt(2048));     % Rx 2,Symbol 2
        % ##### Trim Guard subcarriers #####
             sym_freq_R2_S2(1794:2048)=[];  sym_freq_R2_S2(1:256)=[];
        % Remove DC
             sym_freq_R2_S2(769)=[];
             
        % ######## Combiner ########
        ComSymbol_1 = conj(FullChanEst_11).*sym_freq_R1_S1 ...
                     +FullChanEst_21.*conj(sym_freq_R1_S2) ...
                     +conj(FullChanEst_12).*sym_freq_R2_S1 ...
                     +FullChanEst_22.*conj(sym_freq_R2_S2);
        ComSymbol_2 = conj(FullChanEst_21).*sym_freq_R1_S1 ...
                     -FullChanEst_11.*conj(sym_freq_R1_S2) ...
                     +conj(FullChanEst_22).*sym_freq_R2_S1 ...
                     -FullChanEst_12.*conj(sym_freq_R2_S2);
         % Maximum Likelihood Decision
         %[DemapSymbol_1,DemapSymbol_2]=ML_decision_2x2(FullChanEst_11,FullChanEst_21,FullChanEst_12,FullChanEst_22,ComSymbol_1,ComSymbol_2,demparams.qam);
         
         if frm<0,
             continue;
         end
         
         % compare with original data for SER
         %suberr=suberr+length(find(orig_DFUSC(sym,:)-DemapSymbol_1));
         %suberr=suberr+length(find(orig_DFUSC(sym+1,:)-DemapSymbol_2));
         
         % S1
         biterr_block=iterative_detecion_decoding_2x2(ComSymbol_1, orig_DFUSC_bit(sym,:), ...
                        FullChanEst_11,FullChanEst_21,FullChanEst_12,FullChanEst_22, ...
                        NoisePwr,demparams.qam,demparams.iteration,'zero');
         
         biterr=biterr+biterr_block;
         
         % S2
         biterr_block=iterative_detecion_decoding_2x2(ComSymbol_2, orig_DFUSC_bit(sym+1,:), ...
                        FullChanEst_11,FullChanEst_21,FullChanEst_12,FullChanEst_22, ...
                        NoisePwr,demparams.qam,demparams.iteration,'zero');
                            
         biterr=biterr+biterr_block;
         
     end    % end for sym
     logfid_ber=fopen(logfile_ber,'a');
     fprintf(logfid_ber,'frm = %f , biterr = %f \n', frm, biterr);
     fclose(logfid_ber);
     frm
     biterr
end % end for frm

ber=biterr/databitnum
mse=mse/(4*demparams.numframe)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -