通信建模作业程序集锦(共5页).docx

上传人:飞****2 文档编号:14270158 上传时间:2022-05-03 格式:DOCX 页数:5 大小:30.96KB
返回 下载 相关 举报
通信建模作业程序集锦(共5页).docx_第1页
第1页 / 共5页
通信建模作业程序集锦(共5页).docx_第2页
第2页 / 共5页
点击查看更多>>
资源描述

《通信建模作业程序集锦(共5页).docx》由会员分享,可在线阅读,更多相关《通信建模作业程序集锦(共5页).docx(5页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、精选优质文档-倾情为你奉上1.正态分布:#include #include #include #include #include using namespace std; #define pi 3. /Generate a randon number followed by uniform distribution between the inteval min,max template T rand(T min, T max) return min+(max-min)*rand()/(RAND_MAX+1.0); /calculate the normal density distribut

2、ion values double normal(double x, double miu,double sigma) return 1.0/sqrt(2*pi)/sigma*exp(-1*(x-miu)*(x-miu)/(2*sigma*sigma); /Generate a distributed random output numberdouble randn(double miu,double sigma, double min ,double max) double x,y,dScope; do x=rand(min,max); y=normal(x,miu,sigma); dSco

3、pe=rand(0.0,normal(miu,miu,sigma); while(dScopey); return x; /Generate 10000 distributed random output numbers and put into a text called123int main(int argc,char* argv) double min,max,miu,sigma; srand(unsigned)time( NULL ); cinminmaxmiusigma; ofstream outfile(123.txt); for (int i=0;i10000;i+) outfi

4、le randn(miu,sigma,min,max) endl; return 0; 2.瑞利分布:#include #include #include #include #define pi 3./ generate the random numbers between the interval 0,1double randn()double f;f = (double)(rand()%1001); /0,1000return f/1000.0; /0,1/calculate the Rayleigh density function values by using the followi

5、ng generated random numbers double ruili(double sigma) Return randn()/(sigma*sigma)*exp(-randn()*randn()/(2*sigma*sigma); /The main function can generate 10000 distributed random output numbers which are put into a text called”321”int main(void) double sigma; srand(unsigned)time( NULL ); printf(inpu

6、t sigma:n); scanf(%lf,&sigma); for (int i=0;i10000;i+) FILE *fp;fp=fopen(321.txt,a+);fprintf(fp,%lf,ruili(sigma);printf(%lfn,randn();fclose(fp); return 0;3.泊松分布:#include#include#include#include/Generate the random numberslong Possion(double u)double P,U;long N;u=exp(-u);P=1;N=0;while(1)U=(double)ran

7、d()/RAND_MAX;P=P*U;if(P=u) break;N+;return N;/ Generate 10000 distributed random output numbers which are put into a text called”312”void main() int k; double lamda; scanf(%lf,&lamda); FILE *fp1; fp1=fopen(p1.txt,w); srand(unsigned)time(0); for(k=1;k=0) r_data(i)=1; else r_data(i)=-1; end end pe(SNR

8、+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对数grid on;legend(理论误码率曲线,仿真误码率曲线);8. Simulate the error performance of a QPSK system using Quasi-analytical method, under AWGN channel. At least 200 errors should be generated fo

9、r each EbNo% QPSK System Simulation, Pe evaluationclear;clc;SNRindB1=0:0.05:10; %仿真信噪比范围SNRindB2=0:0.1:10; %理论信噪比范围for i=1:length(SNRindB1), pb=cm_sm32(SNRindB1(i); % simulated bit error rates smld_bit_err_prb(i)=pb; disp(pb); echo off;end;%echo on;For i=1:length(SNRindB2), SNR=exp(SNRindB2(i)*log(1

10、0)/10); % signal to noise ratio theo_err_prb(i)=0.5*erfc(sqrt(SNR); % theoretical bit error rate echo off;end;% Plotting commands follow %作图grid onsemilogy(SNRindB1,smld_bit_err_prb,*); % 用对数坐标作出仿真信噪比-误比特率的点hold onsemilogy(SNRindB2,theo_err_prb); %用对数坐标作出理论信噪比-误比特率曲线hold onxlabel(信噪比(dB);ylabel(误码率)

11、;legend(bit error probability,theory error probability);title(BER performance of QPSK transmission scheme under AWGN channel);function pb,ps=cm_sm32(snr_in_dB)% pb,ps=cm_sm32(snr_in_dB)% CM_SM3 finds the probability of bit error and symbol error for % the given value of snr_in_dB, signal to noise ra

12、tio in dB.N=10000;E=1; % energy per symbolsnr=10(snr_in_dB/10); % signal to noise ratiosgma=sqrt(E/snr)/2; % noise variances00=1 0; s01=0 1; s11=-1 0; s10=0 -1; % signal mapping% generation of the data source, QPSK modulationfor i=1:N, temp=rand; % a uniform random variable between 0 and 1 if (temp0

13、.25), % with probability 1/4, source output is 00 dsource1(i)=0; dsource2(i)=0; elseif (temp0.5), % with probability 1/4, source output is 01 dsource1(i)=0; dsource2(i)=1; elseif (temp0.75), % with probability 1/4, source output is 10 dsource1(i)=1; dsource2(i)=0; else % with probability 1/4, source

14、 output is 11 dsource1(i)=1; dsource2(i)=1; end;end;% detection and the probability of error calculationnumofsymbolerror=0;numofbiterror=0;% go through AWGN channelfor i=1:N, % the received signal at the detection, for the ith symbol,is: n=sgma*randn(1,2); % 2 normal distributed r.v with 0, variance

15、 sgma if (dsource1(i)=0) & (dsource2(i)=0), r=s00+n; elseif (dsource1(i)=0) & (dsource2(i)=1), r=s01+n; elseif (dsource1(i)=1) & (dsource2(i)=0), r=s10+n; else r=s11+n; end; % The correlation metrics are computed below c00=dot(r,s00); c01=dot(r,s01); c10=dot(r,s10); c11=dot(r,s11); % The decision on

16、 the ith symbol is made next c_max=max(c00,c01,c10,c11);% The decision on the ith symbol, MLD if (c00=c_max), decis1=0; decis2=0; elseif (c01=c_max), decis1=0; decis2=1; elseif (c10=c_max), decis1=1; decis2=0; else decis1=1; decis2=1; end;% Later, increment the error counter, if the decision is not

17、correct, % Increment the error counter, if the decision is not correct symbolerror=0; if (decis1=dsource1(i), numofbiterror=numofbiterror+1; symbolerror=1; end; if (decis2=dsource2(i), numofbiterror=numofbiterror+1; symbolerror=1; end; if (symbolerror=1), numofsymbolerror=numofsymbolerror+1; end;end

18、;ps=numofsymbolerror/N; % since there are totally N symbolspb=numofbiterror/(2*N); % since 2N bits are transmitted9. Simulate the error performance of an 8-QAM system using the built-in Matlab channel function rayleighchan .% 8QAM System Simulation, Pe evaluation M=8; % QAM 调制阶数 k = log2(M); hMod=co

19、mm.RectangularQAMModulator(M); % 产生 8 QAM 信号调制器 display(hMod); txd = randint(1e4,1,M); %产生1,M范围的均匀分布的随机序列,用于在接收端发送基带信号 qamSig = step(hMod, txd); % 8 QAM调制信号 chan = rayleighchan(1/50000,100); % 产生瑞利分布的信道模型 SNRindB1=0:0.2:12; %仿真信噪比范围 SNRindB2=0:0.1:12; %理论信噪比范围for i=1:length(SNRindB1), hDemod=comm.Re

20、ctangularQAMDemodulator(8); % 产生 8 QAM 信号解调器 fadedSig = filter(chan,qamSig); %将调制信号加入瑞利信道后再进行滤波得到瑞利衰落信号 rxd = step(hDemod, fadedSig); %接受解调后的信号 smld_bit_err_prb(i) = biterr(txd,rxd); %计算仿真误比特率end;%计算理论误比特率for i=1:length(SNRindB2), SNR=exp(SNRindB2(i)*log(10)/10); % signal to noise ratio theo_err_prb

21、(i)=2*erfc(sqrt(9*SNR/7)/sqrt(2); % theoretical bit error rate echo off;end;%echo on;% Plotting commands followgrid onsemilogy(SNRindB1,smld_bit_err_prb,*); % 用对数坐标作出仿真信噪比-误比特率的点hold onsemilogy(SNRindB2,theo_err_prb); %用对数坐标作出理论信噪比-误比特率曲线hold onxlabel(信噪比(dB);ylabel(误码率);legend(bit error probability,theory error probability);title(BER performance of 8QAM system scheme under rayleigh channel);专心-专注-专业

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁