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

📄 receiver.asv

📁 详细的OFDM设计过程
💻 ASV
字号:
function [receiver_output, en_out, bn_out, size_frame_out] = receiver(training_seq, pilot, train_message,train_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;
global last_t;

forgeting_factor  = 1;              % parameter: depend how much on previous estimation
forgeting_noise = 0.7;              % parameter: depend how much on previous estimation
t_start = 36;                        % window in synchronization
t_end = 41;
Q = 8;                              % upsampling factor

if (begin_flag_receiver==0)
    % receive only training sequence and 10_pilots.
    % training sequence is used to tell receiver "start"
        
     begin_flag_receiver = 1;
%      m3 = m3(size_training_seq+1:end);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   % synchro, for ten_pilots      
      m3 = conv(m3,ones(1,8)) / norm(ones(1,8));
     % t_samp = synchro(m3(1:3 * nr_fft),nr_fft,nr_cyclic_bits,100) 
      
     t_samp = sync(m3(1:3 * Q * nr_fft),train_pilots,t_start, t_end);
     m3 = m3(1:end-4);    
     
     tempt = (length(m3) - t_samp);     
     L = (nr_fft + nr_cyclic_bits) * (nr_frames+2) * 8;
     if(tempt < L)
         t_samp = last_t;
     end
%      
     m3 = m3(t_samp:Q:end);
% %        
%     % Phase estimation and correction.
%     phihat = phase_estimation(m3,train_pilots);
%     m3 = m3 * exp(-j * phihat);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    
    % 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;        
            H = conj((alfa./belta)');
        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;   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % test
%     Noise_var = 1.25;
%     H = [ones(1,67) ones(1,60)*0.8];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    [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:22))   
    
   
     

else
  
%      if (train_flag_receiver==0)
%      % training sequence is regular wave, used to tell receiver "start"      
%          train_flag_receiver = 1;
%           m3 = m3(size_training_seq+1:end);
%      end
     
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% % for synchro
     m3 = conv(m3,ones(1,8))/norm(ones(1,8));
     t_samp = sync(m3(1:3 * Q * nr_fft),train_message,t_start, t_end);
     m3 = m3(1:end-4);
     
     tempt = (length(m3) - t_samp);     
     L = (nr_fft + nr_cyclic_bits) * (nr_frames+2) * 8;
     if(tempt < L)
         t_samp = last_t;
     end
     
     m3 = m3(t_samp : Q : 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    
      
   deinter_output = demod_output;
 
%     % 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;
last_t = t_samp;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   % maybe we can use the syn. training sequence like this: ok, I found the syn.
   % sequence, now I can start the receiver function. so, not included in
   % the receiver function

  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    

⌨️ 快捷键说明

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