
% Initialization
rand('seed',0);
chan_num=1000; 
SNR_min=2;SNR_max=14;SNR_step=1;

% Number of blocks
N=1000;           % block length

M=2;P=2;          % Number of antenna elements
terrain=2; % Power profile terrain "urban"
method1='joint_sic';method2='joint_sicrev';
snr=SNR_min:SNR_step:SNR_max;
Lf1=16;Lf2=16;Lb1=8;Lb2=8;

tic

SER=zeros(M,length(snr));SER_tr=SER;SER_bidfe=SER;
SER_soft_bidfe=SER;SER_ideal=SER;SER_ideal_tr=SER;
SER_soft=SER;SER_soft_tr=SER;

for chan=1:chan_num,    
chan

%generate channels
for m=1:M,
  for p=1:P
[C]=generate_channels(terrain,0.125,1);%real, baud-spaced
C=C./sqrt(C*C');%'
Lc=length(C);
C1((m-1)*Lc+1:m*Lc,p)=C';
C2((m-1)*Lc+1:m*Lc,p)=flipud(C');
end;
end;

% Simulate SER...
[ser,ser_tr,ser_soft,ser_soft_tr,ser_ideal,ser_ideal_tr,ser_bidfe,ser_soft_bidfe]=bidfe_mimo_fading(C1,C2,method1,method2,snr,M,P,N);

SER=SER+ser;
SER_tr=SER_tr+ser_tr;
SER_soft=SER_soft+ser_soft;
SER_soft_tr=SER_soft_tr+ser_soft_tr;
SER_ideal=SER_ideal+ser_ideal;
SER_ideal_tr=SER_ideal_tr+ser_ideal_tr;
SER_bidfe=SER_bidfe+ser_bidfe;
SER_soft_bidfe=SER_soft_bidfe+ser_soft_bidfe;

end;
toc

SER=SER/chan_num;SER_tr=SER_tr/chan_num;
SER_ideal=SER_ideal/chan_num;SER_ideal_tr=SER_ideal_tr/chan_num;
SER_soft=SER_soft/chan_num;SER_soft_tr=SER_soft_tr/chan_num;
SER_bidfe=SER_bidfe/chan_num;SER_soft_bidfe=SER_soft_bidfe/chan_num;

% Plot figures

set(0,'DefaultAxesFontSize',18);
set(0,'DefaultTextFontSize',18);
set(0,'DefaultTextFontName','times');
set(0,'DefaultAxesFontName','times');

for m=1:M,
figure(m);
pl1=semilogy(snr,SER(m,:),'b-.','LineWidth',2);
hold on;
pl2=semilogy(snr,SER_tr(m,:),'r-^','LineWidth',2);
pl4=semilogy(snr,SER_bidfe(m,:),'k-o','LineWidth',2);
pl5=semilogy(snr,SER_soft_bidfe(m,:),'g-*','LineWidth',2);
grid on;
legend([pl1,pl2,pl4,pl5],'Normal Mode DFE','Time-reversal Mode DFE','LC-BiDFE : (Hard)','LC-BiDFE : (Soft)');
xlabel('SNR  in  dB','FontSize',18);
ylabel('Symbol  Error  Rate','FontSize',18);
end;

save results_bidfemimo_fading Lf1 Lf2 Lb1 Lb2 method1 method2 M P snr N chan_num SER SER_tr SER_ideal SER_ideal_tr SER_soft SER_soft_tr SER_bidfe SER_soft_bidfe 











