frame_timing.m
资源名称:MIMO-OFDM.rar [点击查看]
上传用户:look542
上传日期:2009-06-04
资源大小:784k
文件大小:5k
源码类别:
传真(Fax)编程
开发平台:
Matlab
- function [recv_frame, err_frame_timing] = frame_timing( recv_signal ,Window1, Threshold1, Delay1 , ...
- PreNoiseLen, PostNoiseLen, N_subc,PrefixRatio,FrameTiming , N_Rx_ant, Timing,AddChFreq)
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % 实现OFDM的接收机帧定时(包检测,粗定时)算法
- % 如果有多天线, 则有两种处理方法:
- % 1) 每条天线分别进行帧定时.
- % 2) 取多条天线的帧定时位置的加权平均值
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- if ~AddChFreq
- % 有2个OFDM符号长度的训练序列, 加上噪声样点
- signal_len = size(recv_signal,2);
- recv_frame = zeros(size(recv_signal));
- if Timing
- for ant = 1: N_Rx_ant
- recv_tmp = recv_signal(:,:,ant);
- switch FrameTiming % 帧定时算法
- case 1 % 1--单窗口能量检测方法
- for start_idx = 1:PreNoiseLen*2
- timing_metric(start_idx) = sum( recv_tmp(start_idx : start_idx + Window1 - 1).*...
- conj( recv_tmp(start_idx :start_idx + Window1 - 1)) )/ Window1;
- % if timing_metric(start_idx) >= Threshold1 % 固定门限的方法,效果不好
- % timing_idx = start_idx;
- % %break;
- % end
- end
- max_value = max(timing_metric); % 求得最大的估计值,然后取其比例(ratio值)得到门限
- % plot(abs(timing_metric));
- ratio = 0.8 ;
- threshould = max_value*ratio; % 门限由最高延时相关值确定,以防止出现漏判
- timing = find(timing_metric >= threshould);
- timing_idx = timing(1);
- case 2 % 2--双窗口能量检测方法
- for start_idx = 1:PreNoiseLen*2
- timing_A_window = sum(recv_tmp(start_idx : start_idx+Window1 - 1).*...
- conj(recv_tmp(start_idx :start_idx + Window1 - 1)));
- timing_B_window = sum(recv_tmp(start_idx + Window1: start_idx + 2*Window1 - 1).*...
- conj(recv_tmp(start_idx + Window1:start_idx + 2*Window1 - 1)));
- timing_metric(start_idx) = timing_B_window/timing_A_window;
- end
- [max_value,max_idx] = max(timing_metric);
- % plot(abs(timing_metric);
- timing_idx = max_idx + Window1;
- case 3 % 3--延时相关方法帧定时
- for start_idx = 1:PreNoiseLen*2
- correlation = sum(recv_tmp(start_idx : start_idx + Window1 - 1).*...
- conj(recv_tmp(start_idx + Delay1 : start_idx + Window1 + Delay1 - 1)));
- power = sum(recv_tmp(start_idx + Delay1 : start_idx + Window1 + Delay1 - 1).*...
- conj(recv_tmp(start_idx + Delay1 : start_idx + Window1 + Delay1 - 1)));
- timing_metric(start_idx) = (correlation.*conj(correlation))/(power.*conj(power));
- % if timing_metric(start_idx) >= threshould % 固定门限的方法,效果不好
- % timing_idx = start_idx;
- % break;
- % end
- p(start_idx) = power;
- end
- max_value = max(timing_metric); % 求得最大的估计值,然后取其比例(ratio值)得到门限
- % plot(abs(timing_metric);
- ratio = 0.6 ;
- threshould = max_value*ratio; % 门限由最高延时相关值确定,以防止出现漏判
- timing = find(timing_metric >= threshould);
- timing_idx = timing(1);
- otherwise
- end
- idx_cnt(ant) = timing_idx ; % 最佳定时值 : PreNoiseLen + 1
- % 多天线帧定时处理方法1:各条天线分别进行定时
- % recv_frame( 1,1:signal_len - idx_cnt(ant) + 1,ant ) = recv_signal( 1, idx_cnt(ant):end , ant );
- end
- % 多天线帧定时处理方法2:多条天线使用平均的定时位置
- idx = round(sum(idx_cnt)/N_Rx_ant);
- % 截取得到接收信号
- recv_frame = recv_signal( 1,idx : end ,: );
- % 计算误差的样点数
- err_frame_timing = sum( ( PreNoiseLen + 1) - idx_cnt )/N_Rx_ant ;
- else
- delay = 0;
- recv_frame = recv_signal(1,PreNoiseLen + 1 + delay : end ,:);
- err_frame_timing = 0;
- end
- else
- recv_frame = NaN;
- err_frame_timing = NaN;
- end