⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.m

📁 OFDM的在瑞利信道下的与单载波信号的识别算法
💻 M
字号:

clear all

% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %  %
%                                                                        %
%       IEEE 802.11a based OFDM PHY program by You Li 2006.10.12         % 
%                                                                        %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %  % 

%%%  Program parameters are as following %%%%
% Working frequency: fc = 5.2GHz
% Bit rate: 24Mbps
% Number of data subcarriers: Nsd = 48
% Number of pilot subcarriers: Nsp = 4
% Number of total subcarriers: Nst = 52
% Subcarrier frequency spacing: fs = 0.3125MHz ( = 20MHz/64)
% Total bandwidth: ft = fs * Nst = 52 * 0.3125MHz = 16.25MHz
% IFFT/FFT period: T_FFT = 1/fs =1/0.3125M = 3.2us
% Guard interval: T_GI = T_FFT/4 = 3.2us/4 = 0.8us
% OFDM symbol period: T_sym = T_FFT + T_GI = 3.2+0.8 = 4us
% Coding: Convolutional code with coding rate R = 1/2
% Modulation: 16-QAM
% Coded bits per subcarrier: N_BPSC = 4;
% Coded bits per OFDM symbol: N_CBPS = 4 * 48 = 192
% Data bits per OFDM symbol: N_DBPS = N_CBPS * R = 192 * 1/2 = 96
% IFFT/FFT sampling point: 64, over sampling
% Sampling rate: f_s = 1/(T_FFT/64) = 1/(0.05us) = 20Msps 

diary IEEE802.11a_OFDM_PHY.txt
fd=40;
L=8;
delay=[1e-6 2e-6 3e-6 4e-6 5e-6 6e-6 7e-6 8e-6]; 
t_interval=1e-6;
trms=2e-6;
var_pow=10*log10(exp(-delay/trms));
rand('state',sum(100*clock));%?
N_DBPS = 96;
N_SPF =100; %input('Please enter the OFDM symbol number of each frame:\n');  % Number of OFDM symbols per fram 
frame_num = 50;%input('Please enter the number of frames: \n');
N_DBPF = N_DBPS * N_SPF - 6;   % Data bits per frame,minus the 6 tail bits to return the convolutional encoder to the "zero state"
fprintf('\nFrame size is %d OFDM symbols, and %d bits\n ',N_SPF, N_DBPF);
T_sym = 4 * 1e6;           % OFDM symbol period is 4us
fc = 5.2e9;                % Carrier frequency 5.2GHz
v = 2.7e3/3600;            % Vehicle speeed, 2.7km/h
f_max = v/3e8*fc;          % Maximum Dopper frequency, 13Hz 
T_start = rand(1) * 10^(-6);                    % A random starting time for simulation
%channel_option = 1;
%channel_response = channel_model(channel_option,f_max,frame_num,T_sym,T_start);   % Channel response of multipath Rayleigh fading channel during the simulation
                                                                                  % Assuming the channel response is invariant during one frame
pilot_sym = pilot_generator(128);               % Generate the pilot symbols, all in BPSK modulation
pilot_syms=pilot_sym';
pilot_syms=pilot_syms(:)';

for snr = 5:5
    nframe = 0;
    nerror = 0;
    db=20;
    while nframe < frame_num
        %======================
        %      Transmitter
        %======================
        info_bits = round(rand(1, N_DBPF));     % Generate the information bites randomly
        tail = zeros(1,6);                      % Tail bits for convolutional encoder
        info_bits = [info_bits tail];           % Append the tail bits to the infomation bits
        trl = poly2trellis(7,[133 171]);        % Trellis structure of convolutional encoder,
                                                % Constraint length K = 7,generator polynomial in octal g0 = 133, g1 = 171
        code_bits = convenc(info_bits, trl);    % Convolutional encoder,rate R = 1/2
        code=2*code_bits-1;                     %BPSK  modulation
        tx=code;
        C40b=(mean((tx).^4)-3*(mean((tx).^2))^2);
        bpsk(nframe+1)=abs(C40b);
        
        code=awgn(code,db);                    %BPSK   噪声
        tx=code;
         tx1=zeros(48,400);
        for n=1:400
            tx1(:,n)=tx(1,(n-1)*48+1:n*48).';
        end
        tx2=multipath_chann1(tx1,1,var_pow,delay,fd,t_interval);
        tx1=zeros(1,19200);
        for n=1:400
            tx1(1,(n-1)*48+1:n*48)=tx2(:,n).';
        end
        tx=tx1;
        C40bg=(mean((tx).^4)-3*(mean((tx).^2))^2);
        bpskg(nframe+1)=abs(C40bg);
        
                                      %QPSK  modulation
    nb=length(code_bits);             %number of bits
    ns=ceil(nb/2);                    %number of symbols

    b0=zeros(1,ns*2);                 %zero padding
    b0(1:nb)=code_bits;

    j=sqrt(-1);
    for s=1:ns
     ba=b0(((s-1)*2)+1);         %分别取数据流第1个
     bb=b0(((s-1)*2)+2);         %分别取数据流第2个
     k=bb+ba*2;
     p=((pi/4)*(2*k-1))-pi;      %相位
     
     Sc(s)=cos(p);               %同相成分
     Ss(s)=sin(p);               %正交相成分
     S(s)=Sc(s)+j*Ss(s);         %合成
    end
     
     tx=S;                       %QPSK  modulation
     C40Q=mean((tx).^4)-3*(mean((tx).^2))^2;
     qpsk(nframe+1)=abs(C40Q);
     
     tx=awgn(S,db);                            %QPSK  modulation  
      tx1=zeros(48,200);
        for n=1:200
            tx1(:,n)=tx(1,(n-1)*48+1:n*48).';
        end
        tx2=multipath_chann1(tx1,1,var_pow,delay,fd,t_interval);
        tx1=zeros(1,9600);
        for n=1:200
            tx1(1,(n-1)*48+1:n*48)=tx2(:,n).';
        end
        tx=tx1;
         
     
     C40Qg=mean((tx).^4)-3*(mean((tx).^2))^2;
     qpskg(nframe+1)=abs(C40Qg);   
     
        
        TX = tx_16qam_mod(code_bits);           % 16-QAM modulation
          
        
        TXg=awgn(TX,db);
        tx=TXg;                            % 16-QAM modulation  噪声
        tx1=zeros(48,100);
        for n=1:100
            tx1(:,n)=tx(1,(n-1)*48+1:n*48).';
        end
        tx2=multipath_chann1(tx1,1,var_pow,delay,fd,t_interval);
        tx1=zeros(1,4800);
        for n=1:100
            tx1(1,(n-1)*48+1:n*48)=tx2(:,n).';
        end
        tx=tx1;
         
        C400g=(mean((tx).^4)-3*(mean((tx).^2))^2);
        qamg(nframe+1)=abs(C400g);
        
        pilot_num = 1;                                         % The start number of the cyclic pilot symbols 
        
        tx = tx_fre_to_time(TX,N_SPF,pilot_syms,pilot_num);    % Serial to parallel,Add pilot symbols, IFFT ( Oversampling),Add cyclic prefix  
        tx1=zeros(80,100);
        for n=1:100
            tx1(:,n)=tx(1,(n-1)*80+1:n*80).';
        end
         tx2=multipath_chann1(tx1,L,var_pow,delay,fd,t_interval);
        tx1=zeros(1,8000);
        for n=1:100
            tx1(1,(n-1)*80+1:n*80)=tx2(:,n).';
        end
        tx=tx1;
        C40=(mean((tx).^4)-3*(mean((tx).^2))^2);
        ofdm(nframe+1)=abs(C40);
        
        
        tx=awgn(tx,db); 
        C40g=(mean((tx).^4)-3*(mean((tx).^2))^2);
        ofdmg(nframe+1)=abs(C40g);
        
        nframe = nframe + 1;
        
        
    end
    

      %  figure(1)
      %  plot(bpsk,'k-h')
      %  hold on
      %  plot(qpsk,'g-o')
      %  hold on
      %  plot(qam,'b-x')
      %  hold on
      %  plot(ofdm,'r-*')
      %  axis([-1,61,-0.5,2.5])
      %  grid on
      %  legend('BPSK','QPSK','16QAM','OFDM')
      %  Ylabel('估计值');
      %  xlabel('Trail');
        
        
        figure(2)
        plot(bpskg,'k-h')
        hold on
        plot(qpskg,'g-o')
        hold on
        plot(qamg,'b-x')
        hold on
        plot(ofdmg,'r-*')
        axis([-1,61,-0.5,2.5])
        grid on
        legend('BPSK','QPSK','16QAM','OFDM')
        Ylabel('估计值');
        xlabel('Trail');
end

        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -