Matlab仿真DF和AF源程序

上传人:re****.1 文档编号:445330790 上传时间:2023-11-05 格式:DOCX 页数:11 大小:17.31KB
返回 下载 相关 举报
Matlab仿真DF和AF源程序_第1页
第1页 / 共11页
Matlab仿真DF和AF源程序_第2页
第2页 / 共11页
Matlab仿真DF和AF源程序_第3页
第3页 / 共11页
Matlab仿真DF和AF源程序_第4页
第4页 / 共11页
Matlab仿真DF和AF源程序_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《Matlab仿真DF和AF源程序》由会员分享,可在线阅读,更多相关《Matlab仿真DF和AF源程序(11页珍藏版)》请在金锄头文库上搜索。

1、精品文档,仅供学习与交流,如有侵权请联系网站删除版权所有,如转载,请注明出处。说明: 该程序是使用Matlab仿真协同通信的DF(解码转发)基本性能,基本模型S-R-D三个节点,接收端使用MRC(最大比合并)。固定DF由于SR信道的错误,其性能受到限制,在大SNR情况下不能获得有效分集。而当SR距离足够近的时候,可能获得一定的分集增益。 该程序也可以作为学习Matlab 通信仿真的入门实例。使用的基本函数:随机数函数 :rand randn 文件操作:fopen fprintf fclose 时间函数:datestr(now)画图函数:semilogylegendaxis通信基本概念和函数:

2、瑞利信道及其产生 高斯噪声的产生蒙特卡罗仿真 MRC最大比合并程序一:DF_SNR_SR_distance.m 主程序%written by xiyong8260 25/08/2009%this code is for fixed DF performance evaluation, compare the diffirent SR distance%该仿真用来评估不同的SR距离下的固定DF转发性能%for S-R-D three nodes%the SD and RD channel is Rayleigh fading, and the average SNR is varied.clea

3、r all;%the times of Monte Carlo%蒙特卡罗仿真的次数Monte_MAX=10(7);%the length of data frameM2=10(0);MIN_SNR=0;MAX_SNR=30;INTERVAL=2;%功率划分因子,在协同情况下,为了保证总的功率一定,每个节点使用1/2的功率发送POW_DIV=1/2;%open a new record file%打开一个新的文件,如果文件已经存在,那么清除以前的内容fid=fopen(record.txt,w);fprintf(fid,%sn,datestr(now);fclose(fid);%set the

4、SD distance and RD distance%设置SD距离和RD的距离,归一化为1sd_distance=1;rd_distance=1;%变化不同的SR距离sr_distances=0.1,0.5,0.7,0.9;%使用循环的方式仿真不同的SR距离性能for sr_INDEX=1:2 %通过sr_INDEX变量获得真正的SR距离 sr_distance=sr_distances(sr_INDEX); %snrcount这个变量用来对下面的SNR循环进行计数 snrcount=0; %变化SNR循环 for SNR=MIN_SNR:INTERVAL:MAX_SNR sig=10(SN

5、R/10); %just display something on the screen. %仅仅是在计算机上显示一些信息,因为仿真往往很漫长,只是想知道仿真到哪里了. datestr(now) M2 SNR snrcount=snrcount+1; %用来对错误的bit计数 err_num_dsd=0; err_num_coop=0; for tries=0:Monte_MAX %flag indicate if the cooperate is used, if 1, use cooperation,else direct tran is perferred. %一个标志,表明是否转发 t

6、x_coop=1; %generate the source BPSK signal, 0,1 %产生一个长度为M2的0,1随机数 X1=rand(1,M2)0.5;%generate the source BPSK signal,+1,-1 %产生一个长度为M2的BPSK随机信号 Xs=X1*2-1;%generate the source-relay channel, the channel keep constant in a frame %产生SR信道,假设信道在一帧内保持不变 CH_sr=xy_RayleighCH(1)/(sr_distance)2; %the received s

7、ignal of source-relay transmission %中继接收到的源的信号,y=hx+n R_dsr=CH_sr*sqrt(POW_DIV*sig).*Xs+xy_noise(M2);%the decode signal of source-relay transmission %中继对信道进行估计,匹配后硬判决得到的源的信号,根据MRC(最大比合并)的基本原理 Xr=(conj(CH_sr)*sqrt(POW_DIV*sig).*R_dsr0)*2-1; %如果中继解码错误,则不转发 if (sum(Xs=Xr)0) tx_coop=0; end%如果使用固定DF,我们强制

8、设置tx_coop为1 tx_coop=1; %generate the source-destination channel, the channel keep constant in a frame %产生SD信道,假设信道在一帧内保持不变 CH_sd=xy_RayleighCH(1)/(sd_distance)2; %the received signal of direct source-destination transmission %假设不使用协同,直接传输情况下目的节点接收到的源的信号,y=hx+n,这里,源节点使用全功率发送 R_dsd=CH_sd*sqrt(sig).*Xs

9、+xy_noise(M2);%the decode signal of direct source-destination transmission %目的节点对信道进行估计,匹配后硬判决得到的源的信号,根据MRC(最大比合并)的基本原理 Y_dsd=(conj(CH_sd)*sqrt(sig).*R_dsd0)*2-1;%the received signal of cooperative source-destination transmission %在使用协同情况下,目的节点接收到的源的信号,y=hx+n,这里,源节点使用半功率发送 R_csd=CH_sd*sqrt(POW_DIV*s

10、ig).*Xs+xy_noise(M2);%generate the relay-destination channel, the channel keep constant in a frame %产生RD信道,假设信道在一帧内保持不变 CH_rd=xy_RayleighCH(1)/(rd_distance)2; if (tx_coop=1)%the received signal of cooperative relay-destination transmission %在使用协同情况下,目的节点接收到的来自中继的信号 R_crd=CH_rd*sqrt(POW_DIV*sig).*Xr+

11、xy_noise(M2);%MRC的合并信号 R_combine=conj(CH_sd)*sqrt(POW_DIV*sig).*R_csd+conj(CH_rd)*sqrt(POW_DIV*sig).*R_crd; else%if direct transmission is chosen, the source just retransmit the signal again. %如果不使用协同,源节点重复发送自己的数据,假设两次重复发送期间信道保持不变 R_crd=CH_sd*sqrt(POW_DIV*sig).*Xs+xy_noise(M2);%MRC的合并信号 R_combine=co

12、nj(CH_sd)*sqrt(POW_DIV*sig).*R_csd+conj(CH_sd)*sqrt(POW_DIV*sig).*R_crd; end %the decode signal of of cooperative MRC combining %MRC后的判决信号 Y_combine=(R_combine0)*2-1;%the number of error bit %统计每一帧里面错误的比特数目 err_num_dsd=sum(Xs=Y_dsd)+err_num_dsd; err_num_coop=sum(Xs=Y_combine)+err_num_coop; end%try=0:Monte_MAX%the real ber %计算每个SNR下的平均错误BER ber_dsd(snrcount)=err_nu

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

当前位置:首页 > 中学教育 > 试题/考题 > 初中试题/考题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号