通信建模作业程序集锦

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

11.正态分布:#includemath.h#includestdlib.h#includetime.h#includefstream#includeiostreamusingnamespacestd;#definepi3.1415926//Generatearandonnumberfollowedbyuniformdistributionbetweentheinteval[min,max]templatetypenameTTrand(Tmin,Tmax){returnmin+(max-min)*rand()/(RAND_MAX+1.0);}//calculatethenormaldensitydistributionvaluesdoublenormal(doublex,doublemiu,doublesigma){return1.0/sqrt(2*pi)/sigma*exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma));}//Generateadistributedrandomoutputnumberdoublerandn(doublemiu,doublesigma,doublemin,doublemax){doublex,y,dScope;do{x=rand(min,max);y=normal(x,miu,sigma);dScope=rand(0.0,normal(miu,miu,sigma));}while(dScopey);returnx;}//Generate10000distributedrandomoutputnumbersandputintoatextcalled123intmain(intargc,char*argv[]){doublemin,max,miu,sigma;srand((unsigned)time(NULL));cinminmaxmiusigma;ofstreamoutfile(123.txt);for(inti=0;i10000;i++){outfilerandn(miu,sigma,min,max)endl;}return0;}2.瑞利分布:#includemath.h#includestdio.h#includestdlib.h#includetime.h#definepi3.1415926//generatetherandomnumbersbetweentheinterval[0,1]doublerandn(){doublef;f=(double)(rand()%1001);//[0,1000]returnf/1000.0;//[0,1]}//calculatetheRayleighdensityfunctionvaluesbyusingthefollowinggeneratedrandomnumbersdoubleruili(doublesigma){Returnrandn()/(sigma*sigma)*exp(-randn()*randn()/(2*sigma*sigma));}//Themainfunctioncangenerate10000distributedrandomoutputnumberswhichareputintoatextcalled”321”intmain(void){doublesigma;srand((unsigned)time(NULL));printf(inputsigma:\n);scanf(%lf,&sigma);for(inti=0;i10000;i++){FILE*fp;fp=fopen(321.txt,a+);fprintf(fp,%lf,,ruili(sigma));printf(%lf\n,randn());fclose(fp);2}return0;]3.泊松分布:#includestdio.h#includestdlib.h#includectime#includemath.h//GeneratetherandomnumberslongPossion(doubleu){doubleP,U;longN;u=exp(-u);P=1;N=0;while(1){U=(double)rand()/RAND_MAX;P=P*U;if(P=u)break;N++;}returnN;}//Generate10000distributedrandomoutputnumberswhichareputintoatextcalled”312”voidmain(){intk;doublelamda;scanf(%lf,&lamda);FILE*fp1;fp1=fopen(p1.txt,w);srand((unsigned)time(0));for(k=1;k10000;k++){fprintf(fp1,%6ld,Possion(lamda));}fclose(fp1);}4.Designa128thorderFIRband-passdigitalfilterwithcut-offfrequencies10MHz&50MHzApplyittoasignal,anddisplayrelatedfilterandsignalwaveforms.fc=1000;%载波频率Êfc=1000HZqifs=280;%采样频率fs=280HZt=1:2:1000;x=sin(2*pi*t*fc);%generatesignalwaveforms.a=fir1(128,[1050]/(qifs/2));%Bandpassbutt.freqz(a,1);%plotgain&phase(thebarrayis1forFIRfilter)y=filter(a,1,x);%FIRband-passfilterdesign.5.Designa4thorderIIRlow-passfilterwithfc=100Hz.Applyittoasignal,anddisplayrelatedfilterandsignalwaveforms.fc=100;%载波频率fc=100HZqifs=1000;%采样频率fs=1KHZt=(1:1000)/500;x=sin(2*pi*t*fc)%generatesignalwaveforms.[a,b]=butter(4,fc/(qifs/2));%lowpassButt.freqz(a,b);%plotgain&phaseresponsesofdigitalfiltersy=filter(a,b,x);%toimplement6.BasedonProgram2.3/2.4ofRef.[9](byYongSooCho,etal),investigatetheimpactofoftheRMSdelayspreadτandTstothechannelfrequencyselectivity.%plot_IEEE80211_model.mclear,clfscale=1e-9;%nanoTs=100*scale;%Samplingtimet_rms=250*scale;%RMSdelayspreadnum_ch=10000;%NumberofchannelsN=128;%FFTsizePDP=IEEE802_11_model(t_rms,Ts);fork=1:length(PDP)h(:,k)=Ray_model(num_ch).'*sqrt(PDP(k));avg_pow_h(k)=mean(h(:,k).*conj(h(:,k)));endH=fft(h(1,:),N);subplot(221)stem([0:length(PDP)-1],PDP,'ko'),holdon,stem([0:length(PDP)-1],avg_pow_h,'k.');xlabel('channeltapindex,p'),ylabel('AverageChannelPower[linear]');title('IEEE802.11Model,\sigma_\tau=25ns,T_S=25ns');3legend('Ideal','Simulation');axis([-1701]);subplot(222)plot([-N/2+1:N/2]/N/Ts/10^6,10*log10(H.*conj(H)),'k-');xlabel('Frequency[MHz]'),ylabel('Channelpower[dB]')title('Frequencyresponse,\sigma_\tau=25ns,T_S=25ns');7.SimulateaBPSKcommunicationsystem,comparingsimulatedwiththeoreticalBERresultsunderAWGNchannel.clc;clearall;closeall;num=100000;forSNR=0:10data_bpsk=randsrc(1,num,[1,-1]);snr=1/(10^(SNR/10));noise=sqrt(snr/2)*(randn(1,num));receive=data_bpsk+noise;pe(SNR+1)=0;for(i=1:num)if(receive(i)=0)r_data(i)=1;elser_data(i)=-1;endendpe(SNR+1)=(sum(abs((r_data-data_bpsk)/2)))/num;peb(SNR+1)=0.5*erfc(sqrt(10^(SNR/10)));endr=0:10;semilogy(r,peb,'b-v',r,pe,'m-x');%对y取底为10对数gridon;legend('理论误码率曲线','仿真误码率曲线');8.SimulatetheerrorperformanceofaQPSKsystemusingQuasi-analyticalmethod,underAWGNchannel.Atleast200errorsshouldbegeneratedforeachEbNo%QPSKSystemSimulation,Peevaluationclear;clc;SNRindB1=0:0.05:10;%仿真信噪比范围SNRindB2=0:0.1:10;%理论信噪比范围fori=1:length(SNRindB1),pb=cm_sm32(SNRindB1(i));%simulatedbiterrorratessmld_bit_err_prb(i)=pb;disp(pb);echooff;end;%echoon;Fori=1:length(SNRindB2),SNR=exp(SNRindB2(i)*log(10)/10);%signaltonoiseratiotheo_err_prb(i)=0.5*erfc(sqrt(SNR));%theoreticalbiterrorrateechooff;end;%Plottingcommandsfollow%作图gridonsemilogy(SNRindB1,smld_bit_err_prb,'*');%用对数坐标作出仿真信噪比-误比特率的点holdonsemilogy(SNRindB2,theo_err_prb);%用对数坐标作出理论信噪比-误比特率曲线holdonxlabel('信噪比(dB)');ylabel('误码率');legend('biterrorprobability','theoryerrorprobability');title('BERperformanceofQPSKtransmissionschemeunderAWGNchannel');function[pb,ps]=cm_sm32(snr_in_dB)%[p

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功