Bài tập matlab bộ môn thông tin vô tuyến

download Bài tập matlab bộ môn thông tin vô tuyến

of 46

description

Hướng dẫn trình bày và đáp án cho phần bài tập mô phỏng matlab của bộ môn thông tin vô tuyến, cho sinh viên cái nhìn thực tế hơn về bộ môn này.

Transcript of Bài tập matlab bộ môn thông tin vô tuyến

Phn 2: Bi tp matlab thng tin v tuyn.Bi 1.1% exercise1.1% claulation of the probability density function (PDF) of a Gaussian% distributed random variableclear;t_a=0.05; %sampling intervalx= -4:t_a:4;% Clauculation of the PDF of a Gaussian distributed random variablep=(1/sqrt(2*pi))*exp(-x.^2/2);check=trapz(x,p); %integration of pplot(x,p);title('\fontsize{12}PDF of a Gaussian distributed random variable');xlabel('x','FontSize',12);ylabel('P(x)', 'FontSize',12);

Bi 1.2% E1.2% Comparison of Gaussian distribute PDF with simulation resultclear;m_mu=0; %mean valuesigma_mu=1; %variancen=1000000; %length of the noise vectorx=-4:0.05:4;%length of the noise vectorp=(1/sqrt(2*pi)*sigma_mu)*exp(-(x-m_mu).^2/2*sigma_mu^2); %calculate the Gaussian distributed PDFcheck=trapz(x,p); %the integration of P(x)for -4G+1)&(i>1) previous_symbol=rs_frame(i-1,:); %previous OFDM symbol ISI_term=previous_symbol(NFFT+2*G+1:NFFT+G+N_P-1); ISI=[ISI_term,zeros(1,length(previous_symbol)-length(ISI_term))]; rs_i=rs_frame(i,:)+ISI; %the ISI term is added to the current OFDM symbol else rs_i=rs_frame(i,:); end; %OFDM demodulator Demodulated_signal_i=OFDM_Demodulator(rs_i,NFFT,NFFT,G); %OFDM Equalization d=Demodulated_signal_i./H; demodulated_symbol_i= ddemodce(d,1,1,'QAM',M_ary); data_symbol=[data_symbol, demodulated_symbol_i]; end; data_symbol= data_symbol'; %calculation of error symbols [number, ratio]=symerr(symbols, data_symbol); ser=[ser, ratio];end; snr=snr_min:step:snr_max;semilogy(snr,ser,'*--');hold off;ylabel('SER');xlabel('SNR in dB');

Bi 8.3%Main function: OFDM system over a time-variant channelclear all;NFFT=64;G=9;M_ary=16;t_a=50*10^(-9);%load rho.am-ascii;rho=[1, 0.6095, 0.4945, 0.3940, 0.2371, 0.19, 0.1159, 0.0699];N_P=length(rho); %Parameters for Monte Carlo channelsymbol_duration=NFFT*t_a;number_of_summations=40; %Number of summations for Monte-Carlo methodf_dmax=50; NofOFDMSymbol=100;length_data=(NofOFDMSymbol)*NFFT; %Source bitessource_data=randint(length_data,sqrt(M_ary)); %bit to symbol codersymbols=bi2de(source_data); %QAM modulation in base bandQAM_Symbol=dmodce(symbols,1,1,'qam',M_ary); %Preparing data patternData_Pattern=[];for i=0:NofOFDMSymbol-1; QAM_tem=[]; for n=1:NFFT; QAM_tem=[QAM_tem,QAM_Symbol(i*NFFT+n)]; end; Data_Pattern=[Data_Pattern;QAM_tem]; clear QAM_tem;end; Number_Relz=50;ser_relz=[];for number_of_relialization=1:Number_Relz; u=rand(N_P,number_of_summations); %A random variable for Monte-Carlo method ser=[]; snr_min=0; snr_max=25; step=1; for snr=snr_min:step:snr_max; snr=snr-10*log10((NFFT+G)/NFFT); %Miss matching effect caused by using guard interval rs_frame=[]; h_frame=[]; initial_time=0; for i=0:NofOFDMSymbol-1; %OFDM modulation OFDM_signal_tem=OFDM_Modulator(Data_Pattern(i+1,:),NFFT,G); [h, t]=MCM_channel_model(u, initial_time, number_of_summations, symbol_duration, f_dmax, rho); h_frame=[h_frame; h]; %The received signal over multipath channel is created by a %convolutional operation rs=conv(OFDM_signal_tem,h); %Additive noise is added rs=awgn(rs,snr,'measured','dB'); rs_frame=[rs_frame;rs]; initial_time=t; clear OFDM_signal_tem; end; %Receiver Receiver_Data=[]; d=[]; data_symbol=[]; for i=1:NofOFDMSymbol; if (N_P>G+1)&(i>1) previous_symbol=rs_frame(i-1,:); ISI_term=previous_symbol(NFFT+2*G+1:NFFT+G+N_P-1); ISI=[ISI_term,zeros(1,length(previous_symbol)-length(ISI_term))]; rs_i=rs_frame(i,:)+ISI; else rs_i=rs_frame(i,:); end; %OFDM demodulator Demodulated_signal_i=OFDM_Demodulator(rs_i,NFFT,NFFT,G); %OFDM Equalization h=h_frame(i,:); H=fft([h,zeros(1,NFFT-N_P)]); d=Demodulated_signal_i./H; demodulated_symbol_i=ddemodce(d,1,1,'QAM',M_ary); data_symbol=[data_symbol, demodulated_symbol_i]; end; data_symbol=data_symbol'; %Calculation of error symbols [number, ratio]=symerr(symbols, data_symbol); ser=[ser, ratio]; end; ser_relz=[ser_relz;ser]; end; ser=sum(ser_relz)/Number_Relz; snr=snr_min:step:snr_max; semilogy(snr,ser,'bo'); hold on %Parameters for Monte Carlo channelsymbol_duration=NFFT*t_a;number_of_summations=40; %Number of summations for Monte-Carlo methodf_dmax=0;NofOFDMSymbol=100;length_data=(NofOFDMSymbol)*NFFT; %Source bitessource_data=randint(length_data,sqrt(M_ary)); %bit to symbol codersymbols=bi2de(source_data); %QAM modulation in base bandQAM_Symbol=dmodce(symbols,1,1,'qam',M_ary); %Preparing data patternData_Pattern=[];for i=0:NofOFDMSymbol-1; QAM_tem=[]; for n=1:NFFT; QAM_tem=[QAM_tem,QAM_Symbol(i*NFFT+n)]; end; Data_Pattern=[Data_Pattern;QAM_tem]; clear QAM_tem;end; Number_Relz=50;ser_relz=[];for number_of_relialization=1:Number_Relz; u=rand(N_P,number_of_summations); %A random variable for Monte-Carlo method ser=[]; snr_min=0; snr_max=25; step=1; for snr=snr_min:step:snr_max; snr=snr-10*log10((NFFT+G)/NFFT); %Miss matching effect caused by using guard interval rs_frame=[]; h_frame=[]; initial_time=0; for i=0:NofOFDMSymbol-1; %OFDM modulation OFDM_signal_tem=OFDM_Modulator(Data_Pattern(i+1,:),NFFT,G); [h, t]=MCM_channel_model(u, initial_time, number_of_summations, symbol_duration, f_dmax, rho); h_frame=[h_frame; h]; %The received signal over multipath channel is created by a %convolutional operation rs=conv(OFDM_signal_tem,h); %Additive noise is added rs=awgn(rs,snr,'measured','dB'); rs_frame=[rs_frame;rs]; initial_time=t; clear OFDM_signal_tem; end; %Receiver Receiver_Data=[]; d=[]; data_symbol=[]; for i=1:NofOFDMSymbol; if (N_P>G+1)&(i>1) previous_symbol=rs_frame(i-1,:); ISI_term=previous_symbol(NFFT+2*G+1:NFFT+G+N_P-1); ISI=[ISI_term,zeros(1,length(previous_symbol)-length(ISI_term))]; rs_i=rs_frame(i,:)+ISI; else rs_i=rs_frame(i,:); end; %OFDM demodulator Demodulated_signal_i=OFDM_Demodulator(rs_i,NFFT,NFFT,G); %OFDM Equalization h=h_frame(i,:); H=fft([h,zeros(1,NFFT-N_P)]); d=Demodulated_signal_i./H; demodulated_symbol_i=ddemodce(d,1,1,'QAM',M_ary); data_symbol=[data_symbol, demodulated_symbol_i]; end; data_symbol=data_symbol'; %Calculation of error symbols [number, ratio]=symerr(symbols, data_symbol); ser=[ser, ratio]; end; ser_relz=[ser_relz;ser]; end; ser=sum(ser_relz)/Number_Relz; snr=snr_min:step:snr_max; semilogy(snr, ser, '*--'); hold off ylabel('SER'); xlabel('SNR in dB'); legend('time-variant', 'time-invariant');