• 山西省互联网违法和不良信息举报中心——黄河新闻网 2019-01-28
  • 【三厢轿车】最新汽车报价 2019-01-28
  • 世界小姐张梓琳练功晒逆天长腿 被调侃心疼屋顶 2019-01-26
  • 网站最新上线://www.hslogic.com/

    双色球走势图表近50期:OFDM系统的整体性仿真

    排列五开奖结果查询 www.kj742.com 上一篇 / 下一篇  2018-10-29 14:55:16

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %文件说明
    %函数说明:这是一个比较完整的OFDM系统,我在发送端做了比较简单的QPSK调制映射生成OFDM 符号,
    %         经串并转换后插入导频Pilot和循环前缀CP,再进行并串转换加噪声送入多径瑞利信道。
    %         在接收端,先进行串并转换;然后去掉循环前缀,提取导频信息进行LS估计,最后经过并串
    %         转换,QPSK解码还原信息
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %参数说明
    %X:欲发送的二进制比特流
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    clear all;
    clc;
    IFFT_bin_length=128;  % IFFT和FFT的点数 128
    carrier_count=100;    % 子载波个数 100
    bits_per_symbol=2;    % 每符号上的比特数 2
    symbols_per_carrier=12;   % 每桢的OFDM符号数 12
    LI=7 ; %导频之间的间隔
    Np=ceil(carrier_count/LI)+1; %导频数加1 使最后一列也是导频,即有16个导频子信道

    N_number=carrier_count*symbols_per_carrier*bits_per_symbol; %总共发送的信息比特数
                                                                 % 100*12*2=2400
    carriers=1:carrier_count+Np;

    GI=8;             % ?;ぜ涓舫ざ?/div>
    N_snr=40;          % 每比特信息上的信噪比
    snr=8;             %信噪比间隔
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %发送端变量初始化
    X=zeros(1,N_number);    %X:欲发送的二进制比特流
    X1=[]; %原始的二进制数据流每2个一组进行QPSK映射编码得到X1
    X2=[]; %X1串并转换后得到X2
    X3=[]; %X2插入导频后得到X3
    X4=[]; %IFFT变换后得到X4
    X5=[]; 
    X6=[]; %加入循环前缀后得到X6
    X7=[]; %并串转换后得到X7

    %接收端变量初始化
    Y1=[]; %X1的估计值
    Y2=[]; %提取数据信道上的信息
    Y3=[]; 
    Y4=[]; %Y5经FFT变换后得到Y4
    Y5=[]; %Y6去掉循环前缀后得到Y5
    Y6=[]; %Y7并串转换后得到Y6
    Y7=[]; %接收端从信道上得到的信号,即信道输出Y7

    XX=zeros(1,N_number);
    dif_bit=zeros(1,N_number);
    dif_bit1=zeros(1,N_number);
    dif_bit2=zeros(1,N_number);
    dif_bit3=zeros(1,N_number);
    X=randint(1,N_number);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %QPSK调制:(1 1)->pi/4;(0 1)->3*pi/4;(0 0)->-3*pi/4;(1,0)->-pi/4;
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    s=(X.*2-1)/sqrt(2);
    sreal=s(1:2:N_number);  % 将原信息比特流每两个为一组编码
    simage=s(2:2:N_number); %前后比特分别编码为OFDM符号的实,虚部
    X1=sreal+j.*simage ;    % 进行QPSK映射编码(复数形式)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %产生随机导频信号
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    train_sym=randint(1,2*symbols_per_carrier);
    t=(train_sym.*2-1)/sqrt(2);   % 将导频序列也进行QPSK调制映射
    treal=t(1:2:2*symbols_per_carrier);
    timage=t(2:2:2*symbols_per_carrier);
    training_symbols1=treal+j.*timage;      % 构成两组相同的
    training_symbols2=training_symbols1.' ;   % 训练序列用于信道估计
    training_symbols=repmat(training_symbols2,1,Np);
    %将training_symbols2作为一个子矩阵,生成12行,Np=16列大型矩阵

    disp(training_symbols)  % 显示训练序列的内容,共16列
    pilot=1:(LI+1):(carrier_count+Np);
    %以LI+1=8 为间隔,标注导频子载波,即每8个子载波,第1个传导频,其余7个传数据
    if length(pilot)~=Np
        pilot=[pilot,carrier_count+Np]; 
    end

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %串并转换
    X2=reshape(X1,carrier_count,symbols_per_carrier).';
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %插入导频
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    signal=1:carrier_count+Np;
    signal(pilot)=[];
    X3(:,pilot)=training_symbols; % 在导频子载波上填入导频符号
    X3(:,signal)=X2;   %在数据子载波上填入数据

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %OFDM调制
    IFFT_modulation=zeros(symbols_per_carrier,IFFT_bin_length);
    IFFT_modulation(:,carriers)=X3;  
    X4=ifft(IFFT_modulation,IFFT_bin_length,2);

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %加?;ぜ涓簦ㄑ非白海?/div>
    for k=1:symbols_per_carrier;
       for i=1:IFFT_bin_length;
          X6(k,i+GI)=X4(k,i);
       end
       for i=1:GI;
          X6(k,i)=X4(k,i+IFFT_bin_length-GI);  % 加CP:将每个符号最后的GI位复制到最前端 
       end
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %并串转换
    X7=reshape(X6.',1,symbols_per_carrier*(IFFT_bin_length+GI));
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %信道模型:带多普勒频移的瑞利衰落信道

    fd=100; %多普勒频移
    r=6;   %多径数
    a=[0.12 0.3 0.4 0.5 0.7 0.8]; %多径的衰落幅度
    d=[2 3 4 5 7 6]; %各径的延迟
    T=1;  %系统采样周期
    th=[90 0 72 144 216 288]*pi./180; % 各径的相移

    h=zeros(1,carrier_count);
    hh=[];
        for k=1:r
            h1=a(k)*exp(j*((2*pi*T*fd*d(k)/carrier_count)));%各径的响应函数
            hh=[hh,h1];
        end
        h(d+1)=hh;

    %6条信道模拟多径
    channel1=zeros(size(X7));
    channel1(1+d(1):length(X7))=hh(1)*X7(1:length(X7)-d(1));
    channel2=zeros(size(X7));
    channel2(1+d(2):length(X7))=hh(2)*X7(1:length(X7)-d(2));
    channel3=zeros(size(X7));
    channel3(1+d(3):length(X7))=hh(3)*X7(1:length(X7)-d(3));
    channel4=zeros(size(X7));
    channel4(1+d(4):length(X7))=hh(4)*X7(1:length(X7)-d(4));
    channel5=zeros(size(X7));
    channel5(1+d(5):length(X7))=hh(5)*X7(1:length(X7)-d(5));
    channel6=zeros(size(X7));
    channel6(1+d(6):length(X7))=hh(6)*X7(1:length(X7)-d(6));

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    Tx_data=X7+channel1+channel2+channel3+channel4+channel5+channel6;  %发送端送入信道的符号,即信道输入
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    %加高斯白噪声
    Error_ber=[];   %误比特率
    Error_ber1=[];
    Error_ber2=[];
    Error_ber3=[];
    for snr_db=0:snr:N_snr  %在每比特数据上加噪声

        code_power=0;
        code_power=[norm(Tx_data)]^2/(length(Tx_data)); % 符号功率
        bit_power=code_power/bits_per_symbol;  %比特功率 
        noise_power=10*log10((bit_power/(10^(snr_db/10))));%噪声功率
        noise=wgn(1,length(Tx_data),noise_power,'complex');%产生高斯白噪声
        
        Y7=Tx_data+noise;   % 接收端从信道上得到的信息,即信道输出

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %接收端 
    %串并变换
       Y6=reshape(Y7,IFFT_bin_length+GI,symbols_per_carrier).';
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
      %去?;ぜ涓簦–P)
        for k=1:symbols_per_carrier;
           for i=1:IFFT_bin_length;
               Y5(k,i)=Y6(k,i+GI);
           end
        end
         Y4=fft(Y5,IFFT_bin_length,2);
         Y3=Y4(:,carriers);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % LS信道估计
      H=[];
      Y2=Y3(:,signal);  %提取数据信息
      Rx_training_symbols=Y3(:,pilot);  % 提取导频信道上的导频信息
      Rx_training_symbols0=reshape(Rx_training_symbols,symbols_per_carrier*Np,1);
      
      training_symbol0=reshape(training_symbols,1,symbols_per_carrier*Np);
      training_symbol1=diag(training_symbol0);
     
      training_symbol2=inv(training_symbol1);
      Hls=training_symbol2*Rx_training_symbols0; % LS估计量的公式H=X’Y
      Hls1=reshape(Hls,symbols_per_carrier,Np);
      HLs=[];
      HLs1=[];
     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
     if ceil(carrier_count/LI)==carrier_count/LI                          
         for k=1:Np-1         % 依此得到各个信道上的响应估计量              
            HLs2=[];                                                      
               for t=1:LI                                                 
               HLs1(:,1)=(Hls1(:,k+1)-Hls1(:,k))*(t-1)./LI+Hls1(:,k);    
               HLs2=[HLs2,HLs1];                                         
            end
           HLs=[HLs,HLs2];
        end
     else
        for k=1:Np-2
            HLs2=[];
            for t=1:LI
               HLs1(:,1)=(Hls1(:,k+1)-Hls1(:,k))*(t-1)./LI+Hls1(:,k);
               HLs2=[HLs2,HLs1];
            end
           HLs=[HLs,HLs2];
        end
        
        HLs3=[];
        for t=1:mod(carrier_count,LI)
            HLs1(:,1)=(Hls1(:,Np)-Hls1(:,Np-1))*(t-1)./LI+Hls1(:,Np-1);
            HLs3=[HLs3,HLs1];
        end;
        HLs=[HLs,HLs3];
    end
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

      Y1=Y2./HLs;
      

    % Hls是导频位置上获得的信道响应估计量,由于采用慢变信道,所以将它也看作数据
    % 子信道的响应估计量,用该估计量估计出实际接发送的信号Y1,即Y1是X1的估计值            
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      %并串变换
      %通过采用估计和不采用对比体现采用信道估计可以提升OFDM系统的通信质量
      YY=reshape(Y2.',1,N_number/bits_per_symbol);  %不采用信道估计未解码符号
      YY1=reshape(Y1.',1,N_number/bits_per_symbol); %采用LS估计的未解码符号
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %QPSK解码
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       y_real=sign(real(YY));  %通过符号函数进行解码
       y_image=sign(imag(YY));
       y_re=y_real./sqrt(2);
       y_im=y_image./sqrt(2); %未进行估计的
       
       y_real1=sign(real(YY1));
       y_image1=sign(imag(YY1));
       y_re1=y_real1./sqrt(2);
       y_im1=y_image1./sqrt(2);  %进行了LS估计的
     
       r00=[];
       r01=[];
       r10=[];
       r11=[];
     
     % 反映射还原信息比特流
     for k=1:length(y_re);
         r01=[r01,[y_re(k),y_im(k)]];
     end;
     for k=1:length(y_re1);
         r11=[r11,[y_re1(k),y_im1(k)]];
     end;
      
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %计算在不同信噪比下的误比特率
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     dif_bit=s-r01;  %s是发送端的输入比特流经编码后得到的符号
     dif_bit1=s-r11; %r01是未进行估计,解码得到的符号
                     %r11是进行估计后,解码得到的符号
                     %它们进行比较判断误比特
     ber_snr=0;    %记录误比特数
        for k=1:N_number;
           if dif_bit(k)~=0;
             ber_snr=ber_snr+1;
           end
       end;
     ber_snr1=0;    %记录误比特数
        for k=1:N_number;
           if dif_bit1(k)~=0;
              ber_snr1=ber_snr1+1;
          end
        end
     
     Error_ber=[Error_ber,ber_snr];
     Error_ber1=[Error_ber1,ber_snr1];
    end

    BER=zeros(1,length(0:snr:N_snr));
    BER1=zeros(1,length(0:snr:N_snr));

    BER=Error_ber./N_number;  %未进行估计的BER
    BER1=Error_ber1./N_number;  %进行LS估计的BER

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %作图比较未进行信道估计和进行LS估计后的误比特(BER)性能
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    i=0:snr:N_snr;
    semilogy(i,BER,'-*r');
    grid on;
    xlabel('SNR in dB');
    ylabel('Bit Error Rate');

    hold on;
    semilogy(i,BER1,'-ob');
    grid on;
    xlabel('SNR in dB');
    ylabel('Bit Error Rate');
    title('BER性能比较');
    legend('No Channel Estimation','LS Channel Estimation');

    关注我。


    TAG:

     

    评分:0

    我来说两句

    显示全部

    :loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

    日历

    « 2018-12-11  
          1
    2345678
    9101112131415
    16171819202122
    23242526272829
    3031     

    数据统计

    • 访问量: 2170212
    • 日志数: 96
    • 建立时间: 2011-03-03
    • 更新时间: 2018-12-03

    RSS订阅

  • 山西省互联网违法和不良信息举报中心——黄河新闻网 2019-01-28
  • 【三厢轿车】最新汽车报价 2019-01-28
  • 世界小姐张梓琳练功晒逆天长腿 被调侃心疼屋顶 2019-01-26