%% Detect Delayed 802.11a Packet
% Detect a received 802.11a packet that has been delayed. No channel impairments are added. Set the input offset to 5 and use a threshold setting very close to 1.
% Create an non-HT configuration object. Generate the transmit waveform.

cfgNonHT = wlanNonHTConfig;

txWaveform = wlanWaveformGenerator([1;0;0;1],cfgNonHT,...
    'WindowTransitionTime',0);

%
% Delay the signal by appending zeros at the start. Set an initial offset of 5 and a threshold very close to 1. Detect the delayed packet.

rxWaveform = [zeros(20,1);txWaveform];

offset = 5;
threshold = 1-10*eps;
startOffset = wlanPacketDetect(rxWaveform,...
    cfgNonHT.ChannelBandwidth,offset,threshold)

%
% Calculate the detected packet offset by adding the returned startOffset and the input offset.

totalOffset = offset + startOffset

% Using a threshold close to 1 and an undistorted received waveform increases the accuracy of the packet detect location. The detected offset from the first sample of the received waveform to the start of the packet is determined to be 20 samples.
% Copyright 2012 The MathWorks, Inc.