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

传真(Fax)编程

开发平台:

Matlab

  1. function [timed_sym , err_sym_timing] = sym_timing( coarse_freq_out ,N_subc, PrefixRatio, N_sym ,...
  2.     N_syn_preamble,syn_preamble,Window2,TimingAhead, N_Rx_ant,Timing,AddChFreq)
  3. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  4. % 和已知的序列求相关, 得到符号定时位置
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. if ~AddChFreq
  7.     N_sample_ofdm = N_subc*(1+PrefixRatio);
  8.     if Timing
  9.         % 得到第2个OFDM符号的时域样点值
  10.         training_timing = syn_preamble( 1 ,N_sample_ofdm  + 1 : N_sample_ofdm + Window2 );
  11.         
  12.         for ant = 1: N_Rx_ant
  13.             recv_tmp = coarse_freq_out(:,:,ant);
  14.             % 搜索第二个OFDM符号, 开始搜索的位置是N_sample_ofdm*3/4, 结束搜索的位置N_sample_ofdm*5/4  
  15.             cnt = 1;
  16.             start_sample = N_sample_ofdm*3/4;
  17.             end_sample = N_sample_ofdm*5/4;
  18.             for start_idx = start_sample:end_sample      
  19.                 correlation(cnt) = sum( (recv_tmp(start_idx : start_idx + Window2 - 1).*conj(training_timing)) );
  20.                 cnt = cnt + 1;
  21.             end    
  22.             %[max_value, max_idx] = max(correlation); 
  23.             m_idx = find(abs(correlation) > 0.5*max(abs(correlation)));
  24.             max_idx = m_idx(1);
  25.             % plot(abs(correlation));
  26.             timing_idx = max_idx + start_sample - 1;    % 最佳定时值: N_sample_ofdm + 1
  27.             idx_cnt(ant) = timing_idx - TimingAhead;         
  28.         end
  29.         
  30.         % 计算得到多条天线的加权定时位置
  31.         idx = sum(idx_cnt)/N_Rx_ant;
  32.         % 定时截取
  33.         timed_sym = coarse_freq_out( 1, idx + N_sample_ofdm*(N_syn_preamble-1) : idx + N_sample_ofdm*(N_sym-1) - 1, :);
  34.         % 计算定时误差的样点数
  35.         err_sym_timing = (N_sample_ofdm + 1) - idx ;
  36.     else
  37.         timed_sym = coarse_freq_out( 1, N_sample_ofdm*N_syn_preamble + 1 : N_sample_ofdm*N_sym  , :);
  38.         err_sym_timing = 0;
  39.     end
  40. else
  41.     timed_sym = NaN;
  42.     err_sym_timing = NaN;
  43. end