%% Detect HT Packet and Estimate Symbol Timing
% Detect a received 802.11n™ packet and estimate its symbol timing at 20 dB SNR.
% Create an HT format configuration object and TGn channel configuration object.

cfgHT = wlanHTConfig;
tgn = wlanTGnChannel;

%
% Generate a transmit waveform and add a delay at the start of the waveform.

txWaveform = wlanWaveformGenerator([1;0;0;1],cfgHT);
txWaveform = [zeros(100,1);txWaveform];

%
% Pass the waveform through the TGn channel model and add noise.

SNR = 20; % In decibels
fadedSig = tgn(txWaveform);
rxWaveform = awgn(fadedSig,SNR,0);

%
% Detect the packet. Extract the non-HT fields. Estimate the fine packet offset using the coarse detection for the first symbol of the waveform and the non-HT preamble field indices.

startOffset = wlanPacketDetect(rxWaveform,cfgHT.ChannelBandwidth);
ind = wlanFieldIndices(cfgHT);
nonHTFields = rxWaveform(startOffset+(ind.LSTF(1):ind.LSIG(2)),:);

startOffset = wlanSymbolTimingEstimate(nonHTFields, ...
    cfgHT.ChannelBandwidth)

% Copyright 2012 The MathWorks, Inc.