main_2_sender_no_ERC.m
上传用户:cjx922
上传日期:2017-12-13
资源大小:205k
文件大小:3k
源码类别:

通讯编程

开发平台:

Matlab

  1. %两个等同发送者(一个接收端,只加一个噪声)的实际性能曲线和理论曲线的比较,及与单链路的比较,若等同发送者每个
  2. %的功率为p/2。则单链路发送者的功率为p
  3. tic
  4. nr_of_iterations=100; %循环次数
  5. SNR=[-10:2.5:15];%dB形式
  6. global signal;%发送信号的全局变量
  7. signal=generate_signal_structure;%发送信号结构体,包括传输比特数、传输字符数、每个字符包含的比特数、信号的调制方式、发送信号的比特序列、
  8.                                  %发送信号的字符序列,传输完毕后接收到的比特序列,用来求误码率.
  9. signal(1).modulation_type='QPSK' %单个链路功率p发送
  10. signal.nr_of_bits=2^5;
  11. calculate_signal_parameter;%发送信号准备完毕
  12. channel=generate_channel_structure;
  13. channel(1).attenuation(1).pattern='Rayleigh';
  14. channel.attenuation(1).block_length=1;
  15. channel(2)=channel(1);
  16. channel(3)=channel(1);
  17. channel(1).attenuation.distance=1;
  18. channel(2).attenuation.distance=1;
  19. channel(3).attenuation.distance=1;%for single link
  20. rx=generate_rx_structure;
  21. rx(1).combining_type='FRC';
  22. rx.sd_weight=1;
  23. rx(2)=rx(1);
  24. h = waitbar(0,'Please wait...');
  25. BER_2sender=zeros(size(SNR));
  26. BER_1sender=zeros(size(SNR));
  27. for iSNR=1:size(SNR,2)
  28.     waitbar(iSNR/size(SNR,2));
  29.     channel(1).noise(1).SNR=SNR(iSNR);
  30.     channel(2).noise(1).SNR=SNR(iSNR);
  31.     channel(3).noise(1).SNR=SNR(iSNR);
  32.      for it=1:nr_of_iterations
  33.           rx(1)=rx_reset(rx(1));
  34.           [channel(1),rx(1)]=add_channel_effect(channel(1),rx(1),sqrt(1/2)*signal.symbol_sequence);
  35.           %rx(1)=rx_correct_phaseshift(rx(1),channel(1).attenuation.phi);
  36.           [channel(2),rx(1)]=add_channel_effect_noNoise(channel(2),rx(1),sqrt(1/2)*signal.symbol_sequence);
  37.           rx(1)=rx_correct_phaseshift(rx(1),channel(2).attenuation.phi);
  38.           rx(2)=rx_reset(rx(2));
  39.           [channel(3),rx(2)]=add_channel_effect(channel(3),rx(2),signal.symbol_sequence);
  40.           rx(2)=rx_correct_phaseshift(rx(2),channel(3).attenuation.phi);
  41.           %接收端
  42.           %%%%%%%%%%%%%%%%%%两个等同独立发送端%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43.           [received_symbol,signal.received_bit_sequence]=rx_combine(rx(1),channel,1); 
  44.           BER_2sender(iSNR)=BER_2sender(iSNR)+sum(not(signal.received_bit_sequence==signal.bit_sequence));
  45.           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  46.           
  47.           %%%%%%%%%%%%%%%%%%%单链路%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  48.           [received_single_symbol,single_received_bit_sequence]=rx_combine(rx(2),channel,0);
  49.           BER_1sender(iSNR)=BER_1sender(iSNR)+sum(not(single_received_bit_sequence==signal.bit_sequence));
  50.           %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  51.       end%end of iteration
  52.    BER_2sender(iSNR)=BER_2sender(iSNR)./it./signal.nr_of_bits;
  53.    BER_1sender(iSNR)=BER_1sender(iSNR)./it./signal.nr_of_bits;
  54.     %计算两个等同发送者的理论ber 
  55.     SNR_avg(iSNR)=10^(SNR(iSNR)/10);
  56.     theo_ber(iSNR)=ber_2_sender(SNR_avg(iSNR),signal.modulation_type);
  57.     single_link_theo_ber(iSNR)=ber(2*SNR_avg(iSNR),'QPSK','Rayleigh');
  58. end
  59. close(h);
  60. %画出实际和理论误码率图
  61. figure,semilogy(3+SNR,BER_2sender,'r-o',3+SNR,theo_ber,'k-',3+SNR,BER_1sender,'g-^',3+SNR,single_link_theo_ber,'b-')
  62. legend('simulation 2sender','theory 2sender','simulation 1sender','theory single link');
  63. xlabel('Eb/No (dB)');
  64. ylabel('BER');
  65. grid on;
  66. hold on;
  67.           
  68.           
  69.           
  70.           
  71.           
  72.           
  73.           
  74.