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

📄 receiver.m

📁 详细的OFDM设计过程
💻 M
字号:
function [receiver_output, en_out, bn_out, size_frame_out] = receiver(training_seq, pilot, uptrain_message,uptrain_pilots,m3)
        
% This is simulation for the receiver in the OFDM system.


% - receiver_output: output of the receiver, the received message
% - m: signal received from the channel

% ------- receiver.m ------------------------------------
% Black team
% April-08-05
% ----------------------------------------------------------

global nr_cyclic_bits
global nr_subcarriers
global encoder_order
global size_training_seq
global Ex
global gap
global nr_pilots
global nr_frames
global nr_fft


global begin_flag_receiver
global train_flag_receiver
global alfa;
global belta;
global tempN;

global tempb;
global tempe;
global tempH;
global Len;

forgeting_factor  = 1;              % parameter: depend how much on previous estimation
forgeting_noise = 0.7;              % parameter: depend how much on previous estimation


if (begin_flag_receiver==0)
    % receive only 10_pilots.
        
    begin_flag_receiver = 1;
   
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % serial to parallel
    cyclic_frames = reshape(m3,(nr_fft + nr_cyclic_bits),(nr_pilots + nr_pilots + 1));
    
    % remove the prefix
    frames = cyclic_frames(nr_cyclic_bits+1:end,:);
    
    % fft
    frames_output = zeros(nr_subcarriers,nr_pilots);
    for nr = 1 : nr_pilots
        frames_output(:,nr) = symfft(frames(:,nr));
    end
   
    % isolate the pilots
    emp_pilot_output = frames(:,[nr_pilots+2:end]);
    % only estimate half channel according to symfft
    emp_pilot_output = emp_pilot_output(2:nr_subcarriers+1,:);
    pilot_output = frames_output;
        
    % parallel to serial
    receiver_output =[];
    
    % estimate the channel
    
    Noise_var = 0;
    for nr = 1:nr_pilots
        %Y(n)*conj(X(n))
        num = pilot_output(:,nr) .* conj(pilot + nr * 0.05);   
        %X(n)*conj(X(n))
        den = (pilot + nr * 0.05) .* conj(pilot + nr * 0.05); 
        alfa = alfa + num;
        belta = belta + den;        
            
        Noise_var = Noise_var + mean(abs(emp_pilot_output(:,nr)).^2); 
    end
    
    % H = sum(Y(n)*conj(X(n))) / sum(X(n)*conj(X(n)))
    H = conj((alfa./belta)');
    Noise_var = Noise_var / nr_pilots;   
         
    [gn_out,bn_out,en_out,Nuse_out,btot] = waterfill(H,Ex,nr_subcarriers,gap,Noise_var);
    size_frame_out = 1 / encoder_order *  btot ;    
    
    % obtain the length of message
       
     len_frame = symfft(frames(:,nr_pilots+1));
     len_frame = reshape(len_frame,1,nr_subcarriers);
     len_bits = demodulation(len_frame,ones(1,nr_subcarriers),Ex*ones(1,nr_subcarriers),H);
     Len = bi2de(len_bits(1:20))   ;
              
else
  
     if (train_flag_receiver==0)
         train_flag_receiver = 1;
     end
     

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   
    % serial to parallel: construct a matrix, each column is a frame.
    cyclic_frames = reshape(m3,(nr_fft + nr_cyclic_bits),(nr_frames+2));
    
    % remove the cyclic prefix 
    frames = cyclic_frames(nr_cyclic_bits+1:end,:);
    
    frames_output(:,1) = symfft(frames(:,1));
    % compute the FFT
    for nr = 3:nr_frames+2
        frames_output(:,nr) = symfft(frames(:,nr));
    end
 
    % isolate the pilots
    emp_pilot_output = frames(:,2);
    emp_pilot_output = emp_pilot_output(2:nr_subcarriers+1,:);
    pilot_output = frames_output(:,1);
    frames_output = frames_output(:,[3:end]);
    
    % parallel to serial
    serial_output = reshape( frames_output,1,nr_subcarriers * nr_frames);
     
    
    %demodulation using bit loading frame by frame :
    demod_output=[];
    for ii = 1:nr_frames
       
      demod_output = [demod_output ...
             demodulation(serial_output(nr_subcarriers * (ii-1) + 1 : ii * nr_subcarriers),tempb,tempe,tempH)];
 
    end    
      
 
 
    % deinterleaving
    deinter_output = deinterleaving(demod_output,5,5);
    
    % decoder
    receiver_output = decoder(deinter_output);
    
    
    Len = Len - length(receiver_output);
    if(Len<0)
   
        %%%% stop receiving
        receiver_output = receiver_output(1:end + Len);
    end
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    
    
   % estimate the channel
   
        %Y(n)*conj(X(n))
        num = pilot_output.*conj(pilot);   
        %X(n)*conj(X(n))
        den = pilot.*conj(pilot);     
        %  sum(Y(n)*conj(X(n))),sum(X(n)*conj(X(n)));
        alfa = alfa + num;
        belta = belta + den;
        H_t = (num + forgeting_factor * alfa)./ (den + forgeting_factor * belta);
        H = conj(H_t');
        
        Noise_var = forgeting_noise * tempN + (1 - forgeting_noise) * mean(abs(emp_pilot_output).^2);  
             
         % allocation of the bits per subchannel 
        [gn_out,bn_out,en_out,Nuse_out,btot] = waterfill(H,Ex,nr_subcarriers,gap,Noise_var);
     
         % number of bits per frame (adapted according to bit loading)
         size_frame_out = 1 / encoder_order *  btot ;

 end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% store for next demodulation
tempb = bn_out;
tempe = en_out;
tempH = H;
tempN = Noise_var;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    

⌨️ 快捷键说明

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