📄 rx_find_packet_edge.m
字号:
function [flag, thres_idx, detected_packet] = rx_find_packet_edge(rx_signal, sim_options)
global sim_consts;
search_win = 800; %注意在接收信号之前加入了sim_consts.ExtraNoiseSamples(=500)的噪声
D = 16;%短训练符号的周期。
flag=1; %用于判决是否正确地进行了分组检测
if sim_options.PacketDetection
rx_len = length(rx_signal);
% 计算延迟相关。
delay_xcorr = rx_signal(:,1:search_win+2*D).*conj(rx_signal(:,1*D+1:search_win+3*D));
% 延迟相关的滑动平均
ma_delay_xcorr = abs(filter(ones(1,2*D), 1, delay_xcorr, [], 2));
% L=2*D 参考《OFDM无线局域网》第36页(2.8)式。
% 计算互相关系数窗口期间接收信号的能量。此值用于判决统计的归一化。
% ma_rx_pwr = filter(ones(1,2*D), 1, abs(rx_signal(:,1*D+1:search_win+3*D)).^2,[], 2);
ma_rx_pwr = filter(ones(1,2*D), 1,abs(rx_signal(:,1:search_win+2*D)).^2+abs(rx_signal(:,1*D+1:search_win+3*D)).^2,[], 2);
%//////////////////////////////////////////////////
%Y = FILTER(B,A,X) filters the data in vector X with the
%filter described by vectors A and B to create the filtered
%data Y. The filter is a "Direct Form II Transposed"
% implementation of the standard difference equation:
%a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
% - a(2)*y(n-1) - ... - a(na+1)*y(n-na)
%FILTER(B,A,X,[],DIM) or FILTER(B,A,X,Zi,DIM) operates along the
%dimension DIM.
%故此处实际上是计算窗口L=32长度内的延迟相关的累加,即(2.8)式。
%//////////////////////////////////
% 统计判决变量
delay_len = length(ma_delay_xcorr);
% ma_M = ma_delay_xcorr(:,1:delay_len)./ma_rx_pwr(:,1:delay_len);
ma_M = 2*ma_delay_xcorr(:,1:delay_len)./ma_rx_pwr(:,1:delay_len);
% 移除延迟的部分
ma_M(:,1:2*D) = [];
% 如果采用了接收分集
ma_M = sum(ma_M, 1);
if ~sim_options.UseRxDiv
threshold = 0.75; %如果没有使用接收分集,则设门限值为0.75
else
threshold = 1.5;
end
thres_idx = find(ma_M > threshold);
if isempty(thres_idx)
thres_idx = 1;% 如果thres_idx为空,则设thres_idx = 1。
else
thres_idx = thres_idx(1);%定义数据分组开始时刻为第一个大于门限值的ma_M的下标。
end
else
thres_idx = sim_consts.ExtraNoiseSamples;
end;
% 检查分组是否检测得太迟或者由于噪声而使判决变量超过门限
if (thres_idx > sim_consts.ExtraNoiseSamples + 35) | (thres_idx < 475)
thres_idx = 1;
end
detected_packet = rx_signal(:,thres_idx:length(rx_signal));
if thres_idx ==1 %没有正确地检测到分组
flag=0;
end
%keyboard
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -