通信人家园

标题: 麻烦高手给我看下协作通信的程序,急,谢谢了  [查看完整版帖子] [打印本页]

时间:  2011-10-19 10:28
作者: wptx032     标题: 麻烦高手给我看下协作通信的程序,急,谢谢了

%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.

clear all;

%the times of Monte Carlo
%蒙特卡罗仿真的次数
Monte_MAX=10^(7);

%the length of data frame
M2=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,'%%%s\n',datestr(now));
fclose(fid);

%set the SD distance and RD distance
%设置SD距离和RD的距离,归一化为1
sd_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^(SNR/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.
            %一个标志,表明是否转发
            tx_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 signal 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_dsr>0)*2-1;
            
            %如果中继解码错误,则不转发
            if (sum(Xs~=Xr)>0) tx_coop=0; end
            %如果使用固定DF,我们强制设置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+xy_noise(M2);
            %the decode signal of direct source-destination transmission
            %目的节点对信道进行估计,匹配后硬判决得到的源的信号,根据MRC(最大比合并)的基本原理
            Y_dsd=(conj(CH_sd)*sqrt(sig).*R_dsd>0)*2-1;


            %the received signal of cooperative source-destination transmission
            %在使用协同情况下,目的节点接收到的源的信号,y=hx+n,这里,源节点使用半功率发送
            R_csd=CH_sd*sqrt(POW_DIV*sig).*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+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=conj(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_combine>0)*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_num_dsd/(M2*Monte_MAX);  
            ber_coop(snrcount)=err_num_coop/(M2*Monte_MAX);
           

    end % SNR=MIN_SNR:MAX_SNR  
     
     %以追加的方式打开文件,将数据写入记录文件
     fid=fopen('record.txt','a');
     fprintf(fid,'\n%%ber_dsd is\nber_dsd%d=[ ',sr_INDEX);
     fprintf(fid,'%d ',ber_dsd);
     fprintf(fid,'];\n');
     fprintf(fid,'\n%%fixed ber_coop is\nber_coop%d=[ ',sr_INDEX);
     fprintf(fid,'%d ',ber_coop);
     fprintf(fid,'];\n');
     fclose(fid);
     
end %Sr index



SNR1=MIN_SNR:INTERVAL:MAX_SNR;

%瑞利信道下的直接发送的理论BER表达式
sig1=10.^(SNR1/10);
u1=sqrt(sig1./(1+sig1));
Pe10=1/2*(1-u1);

%瑞利信道下的二阶分集理论BER表达式,使用半功率
sig2=1/2*10.^(SNR1/10);
u2=sqrt(sig2./(1+sig2));
Pe20=1/4*(1-u2).^(2).*(2+u2);

%使用半对数画出SNR和BER的曲线
semilogy(SNR1,ber_dsd,'-o',SNR1,ber_coop,'-+',SNR1,Pe10,'-+',SNR1,Pe20,'-*');
legend('direct','cooperative','L=1, therotic','L=2 therotic');
grid on;
ylabel('The AVERAGE BER');
xlabel('SNR(dB)');
title('the cooperative BER of BPSK in Rayleigh fading channel');
axis([MIN_SNR,MAX_SNR,10^(-6),1]);
我想问的就是我现在要把多径衰落的程序加进去,好像是matlab自带的berfading文件吧,但我不知道应该怎么用那个berfading文件,里面的几个参数也不知道该取什么值合适,还有这个berfading程序应该放在我上面程序中的哪个位置啊,那位高手帮我解答下啊,本人要写论文,很急。谢谢了
时间:  2011-10-19 10:30
作者: wptx032

最好把加进去的程序写下啊,本人学的不是很好,所以不怎么懂,多谢了
时间:  2011-10-19 10:31
作者: wptx032

对多径协作比较熟悉的高手帮帮忙啊
时间:  2012-5-31 22:40
作者: xinjie1023     标题: 学习程序

学习程序




通信人家园 (https://www.txrjy.com/) Powered by C114