% This function generates the plots illustrating the loss dues to channel
% estimation when using the MIMO training sequences designed for a GSM
% multi-antenna system with 2/4 transmit antennas.

M=2tr; % Number of antenna elements
L_max=8; % Use L_max=7 for M=4 
N_trn=26; % Training length for M=2
%N_trn=36; % Training length for M=4

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

span=1:L_max;
loss_ideal=10*log10(1+M*span./(N_trn-span+1));

figure;
pl1=plot(span,loss_ideal,'k-s','LineWidth',2);
hold on;
grid on;
xlabel('Channel Length');
ylabel('Loss in SNR (dB)');

for trn_code=0:7, %various training sequences

for s=1:L_max,
if (M==2)
     trn_seq=trainseqm2(trn_code);
elseif (M==4)
     trn_seq=trainseqm4(trn_code);
end;
err_ls(s)=trnseq_eval(trn_seq,s);
end;

loss_trn=10*log10(1+M*span.*err_ls./(N_trn-span+1)); 
pl2=semilogy(span,loss_trn,'r-^','LineWidth',2);
end;

legend([pl1,pl2],'Ideal training','Suboptimal training',2);






