資源簡介
這是一個在瑞利信道下的BER的仿真圖的程序,共有三個調制方式:bpsk qpsk 和16qam
代碼片段和文件信息
%?SNR_start=0;
%?SNR_delta=1;
%?SNR_stop=40;
%?BER_stop=0.00001;
%?sigma=0.5;
%?
%????%?Choose?a?file?to?save?the?results?into.
%?????filename?=?[‘results_‘num2str(SNR_start)‘.mat‘];
%?????%?Doing?the?simulation?frame-by-frame?rather?than?bit-by-bit?speeds?it?up.?This?is?because?we?can?use?vector?operations?instead?of?longer?loops.
%?????frame_length?=?10000;
%?????%?Setup?the?SNR?for?the?first?iteration?of?the?loop.
%?????SNR_count?=?1;
%?????SNR?=?SNR_start;
%?????BER?=?1;
%?
%?????%?Loop?until?the?job?is?killed?or?until?the?SNR?or?BER?target?is?reached.
%?????while?SNR?<=?SNR_stop?&&?BER?>=?BER_stop
%?
%?????????%?Convert?from?SNR?(in?dB)?to?noise?power?spectral?density.
%??????????N0?=?1/(10^((SNR+3.0103)/10));
%?????????
%?????????%?Counters?to?store?the?number?of?errors?and?bits?simulated?so?far.
%?????????error_count=0;
%?????????bit_count=0;
%????????
%?????????%?Keep?going?until?enough?errors?have?been?observed.?This?runs?the?simulation?only?as?long?as?is?required?to?keep?the?BER?vs?SNR?curve?smooth.
%?????????while?error_count?100
%?%--------------------------------------------------------------------------????????????
%?
%?%?BPSK?Generate?10000?symbols?each?contain?2?bits
%?%?rand(‘seed‘1);
%?realpart=round(rand(1frame_length));
%?imagpart=round(rand(1frame_length));
%?a=2^(-1/2);
%?xk=2*a*((realpart-0.5)+i*(imagpart-0.5));
%?
%?%?passing?channel?
%?
%?xt=xk;???????????%?no?phase?and?amplitude?distortion?
%?
%?
%?%?additive?white?Gaussian?noise?(AWGN)
%?snr=1/N0;
%?Ls?=?length(xt);
%?sigma_x=std(xt);
%?sigma_n?=?1/sqrt(2*snr);
%?noise=sigma_x*sigma_n*(randn(1Ls)+i*randn(1Ls));
%?
%?%?fading?channel
%?channel?=?sqrt(sigma)*(randn(1Ls)+i*randn(1Ls));
%?
%?xt_addnoise?=?xt.*(channel)?+?noise;
%?
%?%?decode?the?signal
%?xk_hat=xt_addnoise;?????%?down-sample?the?signal?
%?
%?
%?b_1hat=real(xk_hat)>0;
%?b_2hat=imag(xk_hat)>0;
%?
%?error_count=(sum(b_1hat~=realpart)+sum(b_2hat~=imagpart))+error_count;
%?bit_count=bit_count+frame_length*2;
%?
%?%?BER=(sum(b_1hat~=realpart)+sum(b_2hat~=imagpart))/20000
%?????????????
%?????????end
%?????????
%?????????%?Calculate?the?BER.
%?????????BER?=?error_count/bit_count;
%?????????
%?????????%?Store?the?SNR?and?BER?in?a?matrix?and?display?it.
%?????????results(SNR_count1)?=?SNR;
%?????????results(SNR_count2)?=?BER
%?????????
%?????????%?Save?the?results?into?binary?files.?This?avoids?the?loss?of?precision?that?is?associated?with?ASCII?files.
%?????????save(filename?‘results‘?‘-MAT‘);
%???semilogy(results(:1)results(:2)‘bv-‘);
%??????????????
%?????????xlabel(‘Eb/No?(in?dB)‘)
%?????????if?BER_stop?~=?0?
%?????????????ylim([BER_stop1]);
%?????????end
%?????????if?SNR_stop?~=?inf
%?????????????xlim([SNR_start?SNR_stop]);
%?????????end
%?????????
%?????????%?Setup?the?SNR?for?the?next?iteration?of?the?loop.
%?????????SNR?=?SNR?+?SNR_delta;
%?????????SNR_count?=?SNR_count?+?1;
%?????end
%?results1=res
- 上一篇:MATLAB時域有限差分法程序
- 下一篇:MATLAB傅里葉變換程序
評論
共有 條評論