www.pudn.com > SpacetimeMatlabCode.rar > runsim.m, change:2004-03-25,size:2790b


function runsim(sim_options) 
 
%examine options 
fr_length=sim_options.FrmLen; 
NumberofPackets=sim_options.NumberofPackets; 
option=sim_options.Option; 
channel_model=sim_options.ChannelModel; 
Tx_antennas=2; 
Rx_antennas=sim_options.RxDiv; 
corr_value=sim_options.corr_value; 
 
%append zeros to the data to reset this trellis to zero 
zf=3; %length of zero appendix.  
 
%prepare look-up table 
[dlt,slt,md] = ltable(option,sim_options); 
 
%md -> number of constellation points. BITS define the number of coded bits 
if md==4 %4PSK 
    BITS=2; 
elseif md==8%8PSK 
    BITS=3; 
elseif md==16%16QAM 
    BITS=4; 
end 
 
%examine if MMSE estimation is required. If yes append 20 symbols for 
%additional channel noise, since we are using 20 pilot symbols(zeros+10) 
if sim_options.Channel_Est==1 
    add_est=20; 
else 
    add_est=0; 
end 
 
%SNR variation in dBs 
SNR=0:2:20;
 
h=waitbar(0,'Percentage Completed'); 
set(h,'Position',[230 50 275.25 56.25]); 
set(h,'name','Please wait...'); 
wb=9.09; 
  
%commence loop  
for i=1:length(SNR) 
    	source_data = generate_data(fr_length,NumberofPackets,md,zf); 
	 
        encoded_data = trellis_encoder(source_data,dlt,slt); 
	 
    	mod_sig = modul(encoded_data,md,sim_options); 
 
	 
	    [signal,ch_coefs] = channel(mod_sig,add_est,channel_model,SNR(i),sim_options); 
 
 
        if sim_options.Channel_Est==1 
            [est_coefs,signal]=est(signal,ch_coefs,NumberofPackets,sim_options); 
            ch_coefs=est_coefs; 
        end     
        if sim_options.Rx_corr==1 
        	signal=correlate(signal,corr_value,NumberofPackets); 
        end 
     
        [data_est,state_est] = detect(signal,dlt,slt,ch_coefs); 
 
 
 
% counting the errors 
    	[FER_i,SER_i] = count(source_data,data_est); 
	 
    	SER(i) = SER_i; 
        BER(i)=SER(i)/BITS; 
        FER(i) = FER_i; 
        str_bar=[num2str(wb) '% Completed']; 
        waitbar(wb/100,h,str_bar); 
        wb=wb+9.09; 
    end 
close(h); 
 
str1=cd; 
str2=sim_options.FileName; 
str3=[str1 '\' str2]; 
 
if sim_options.Savefile==1 
    save(str3); 
end 
 
%plot routines.  
figure; 
semilogy(SNR,FER,'r-'); 
hold on 
semilogy(SNR,SER,'b-*' ); 
semilogy(SNR,BER,'g-o'); 
hold off 
xlabel('SNR [dB]') 
ylabel('FER/SER/BER') 
axis([min(SNR) max(SNR) 1e-6 1e0]) 
str1='System:'; 
str2=num2str(2); 
str3=num2str(2); 
str=[str1 str2 'x' str2]; 
title(str,'FontWeight','bold','Color','r'); 
legend('FER','SER','BER'); 
set(gcf,'NumberTitle','off'); 
set(gcf,'Name',sim_options.Option); 
grid on 
[flag]=disptrell(dlt,slt,data_est,state_est);       % display trellis  
if flag 
  str1 = num2str(15); 
  str2=['Packet is too long!                      ']; 
  str3=['Only first ',str1,' symbols will be displayed. ']; 
 msgbox([str2;str3]); 
end 
figure; 
dispdes(dlt,slt);