📄 dem_dfusc_2x2_stbc_ser.m
字号:
function [ser,mse]=dem_DFUSC_2x2_STBC_SER(demparams,NoisePwr,ipfid_rx1,ipfid_rx2)
PwNorm=sqrt(2048/1702); % symbol power normalization factor
% load original data
load orig_DFUSC_QAM16.mat;
load Wk_preamble.mat;
% 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(:,1877:2048)=[]; perfectCE_11(:,1:173)=[];
perfectCE_21(:,1877:2048)=[]; perfectCE_21(:,1:173)=[];
perfectCE_12(:,1877:2048)=[]; perfectCE_12(:,1:173)=[];
perfectCE_22(:,1877:2048)=[]; perfectCE_22(:,1:173)=[];
% ################################################################
suberr=0; % used to calculate subcarrier error rate
mse=0;
datanum=demparams.numframe*demparams.sympf*1702; % data number
for frm=1:demparams.numframe
% ############## When use Known Channel Knowledge #############
%FullChanEst_11=sqrt(2048/1702)*perfectCE_11(frm,:);
%FullChanEst_21=sqrt(2048/1702)*perfectCE_21(frm,:);
%FullChanEst_12=sqrt(2048/1702)*perfectCE_12(frm,:);
%FullChanEst_22=sqrt(2048/1702)*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((preamble_time_rx1).',demparams.chantype,demparams.sampletime);
FullChanEst_11=PwNorm*FullChanEst_11; FullChanEst_21=PwNorm*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((preamble_time_rx2).',demparams.chantype,demparams.sampletime);
FullChanEst_12=PwNorm*FullChanEst_12; FullChanEst_22=PwNorm*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*perfectCE_11(frm,:)-FullChanEst_11).^2)/1703 ...
+sum(abs(PwNorm*perfectCE_21(frm,:)-FullChanEst_21).^2)/1703 ...
+sum(abs(PwNorm*perfectCE_12(frm,:)-FullChanEst_12).^2)/1703 ...
+sum(abs(PwNorm*perfectCE_22(frm,:)-FullChanEst_22).^2)/1703;
% Remove DC
FullChanEst_11(852)=[];
FullChanEst_21(852)=[];
FullChanEst_12(852)=[];
FullChanEst_22(852)=[];
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(1877:2048)=[]; sym_freq_R1_S1(1:173)=[];
% Remove DC
sym_freq_R1_S1(852)=[];
% ------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(1877:2048)=[]; sym_freq_R1_S2(1:173)=[];
% Remove DC
sym_freq_R1_S2(852)=[];
% ------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(1877:2048)=[]; sym_freq_R2_S1(1:173)=[];
% Remove DC
sym_freq_R2_S1(852)=[];
% ------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(1877:2048)=[]; sym_freq_R2_S2(1:173)=[];
% Remove DC
sym_freq_R2_S2(852)=[];
% ######## 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);
% 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));
end
end
ser=suberr/datanum
mse=mse/(4*demparams.numframe)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -