frame_timing.m
上传用户:look542
上传日期:2009-06-04
资源大小:784k
文件大小:5k
源码类别:

传真(Fax)编程

开发平台:

Matlab

  1. function [recv_frame, err_frame_timing] = frame_timing( recv_signal ,Window1, Threshold1, Delay1 , ...
  2.     PreNoiseLen, PostNoiseLen, N_subc,PrefixRatio,FrameTiming , N_Rx_ant, Timing,AddChFreq)
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. % 实现OFDM的接收机帧定时(包检测,粗定时)算法
  5. % 如果有多天线, 则有两种处理方法:
  6. % 1) 每条天线分别进行帧定时. 
  7. % 2) 取多条天线的帧定时位置的加权平均值
  8. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  9. if ~AddChFreq
  10.     
  11.     % 有2个OFDM符号长度的训练序列, 加上噪声样点
  12.     
  13.     signal_len = size(recv_signal,2);
  14.     recv_frame = zeros(size(recv_signal));
  15.     
  16.     if Timing
  17.         
  18.         for ant = 1: N_Rx_ant
  19.             recv_tmp = recv_signal(:,:,ant);
  20.             
  21.             switch FrameTiming              % 帧定时算法
  22.                 
  23.             case 1                          % 1--单窗口能量检测方法
  24.                 
  25.                 for start_idx = 1:PreNoiseLen*2       
  26.                     timing_metric(start_idx) = sum( recv_tmp(start_idx : start_idx + Window1 - 1).*...
  27.                         conj( recv_tmp(start_idx :start_idx + Window1 - 1)) )/ Window1;
  28.                     %                 if timing_metric(start_idx) >= Threshold1  % 固定门限的方法,效果不好
  29.                     %                     timing_idx = start_idx;
  30.                     %                     %break;
  31.                     %                 end
  32.                 end
  33.                 max_value = max(timing_metric);       % 求得最大的估计值,然后取其比例(ratio值)得到门限
  34.                 % plot(abs(timing_metric));
  35.                 ratio = 0.8 ;
  36.                 threshould = max_value*ratio;         % 门限由最高延时相关值确定,以防止出现漏判
  37.                 timing = find(timing_metric >= threshould);
  38.                 timing_idx = timing(1);
  39.                 
  40.             case 2                          %  2--双窗口能量检测方法
  41.                 
  42.                 for start_idx = 1:PreNoiseLen*2
  43.                     timing_A_window = sum(recv_tmp(start_idx : start_idx+Window1 - 1).*...
  44.                         conj(recv_tmp(start_idx :start_idx + Window1 - 1)));
  45.                     timing_B_window = sum(recv_tmp(start_idx + Window1: start_idx + 2*Window1 - 1).*...
  46.                         conj(recv_tmp(start_idx + Window1:start_idx + 2*Window1 - 1)));
  47.                     timing_metric(start_idx) = timing_B_window/timing_A_window;
  48.                 end
  49.                 [max_value,max_idx] = max(timing_metric);
  50.                 % plot(abs(timing_metric);
  51.                 timing_idx = max_idx + Window1;
  52.                 
  53.             case 3                          % 3--延时相关方法帧定时
  54.                 
  55.                 for start_idx = 1:PreNoiseLen*2
  56.                     correlation = sum(recv_tmp(start_idx : start_idx + Window1 - 1).*...
  57.                         conj(recv_tmp(start_idx + Delay1 : start_idx + Window1 + Delay1 - 1)));
  58.                     power = sum(recv_tmp(start_idx + Delay1 : start_idx + Window1 + Delay1 - 1).*...
  59.                         conj(recv_tmp(start_idx + Delay1 : start_idx + Window1 + Delay1 - 1)));
  60.                     timing_metric(start_idx) = (correlation.*conj(correlation))/(power.*conj(power));               
  61.                     %                 if timing_metric(start_idx) >= threshould     % 固定门限的方法,效果不好
  62.                     %                     timing_idx = start_idx;
  63.                     %                     break;
  64.                     %                 end
  65.                     p(start_idx) = power;
  66.                 end          
  67.                 max_value = max(timing_metric);      % 求得最大的估计值,然后取其比例(ratio值)得到门限
  68.                 % plot(abs(timing_metric);
  69.                 ratio = 0.6 ;
  70.                 threshould = max_value*ratio;        % 门限由最高延时相关值确定,以防止出现漏判
  71.                 timing = find(timing_metric >= threshould);
  72.                 timing_idx = timing(1);
  73.             otherwise
  74.             end
  75.             
  76.             idx_cnt(ant) = timing_idx ;         %   最佳定时值 : PreNoiseLen + 1
  77.             
  78.             % 多天线帧定时处理方法1:各条天线分别进行定时
  79.             % recv_frame( 1,1:signal_len - idx_cnt(ant) + 1,ant ) = recv_signal( 1, idx_cnt(ant):end , ant );
  80.         end
  81.         
  82.         % 多天线帧定时处理方法2:多条天线使用平均的定时位置
  83.         idx = round(sum(idx_cnt)/N_Rx_ant);
  84.         % 截取得到接收信号
  85.         recv_frame = recv_signal( 1,idx : end ,: );
  86.         
  87.         % 计算误差的样点数
  88.         err_frame_timing = sum( ( PreNoiseLen + 1) - idx_cnt )/N_Rx_ant ;
  89.         
  90.     else
  91.         delay = 0; 
  92.         recv_frame = recv_signal(1,PreNoiseLen + 1 + delay : end ,:);
  93.         err_frame_timing = 0;
  94.     end
  95.     
  96. else
  97.     recv_frame = NaN;
  98.     err_frame_timing = NaN;
  99.     
  100. end