%% Detect VHT Waveform After Adjusting Recovery Algorithm
% Detect the format of a WLAN very high throughput (VHT) waveform, adjusting the default recovery algorithm settings.
% Generate a VHT waveform and add white Gaussian noise to the transmitted waveform.

cbw = 'CBW80';
cfgTx = wlanVHTConfig('ChannelBandwidth',cbw);
tx = wlanWaveformGenerator([1;0;0;1],cfgTx);
snr = 10;
rxSig = awgn(tx,snr);

%
%% Received signal demodulation and channel estimation
% Determine indices for the L-LTF for the 80 MHz bandwidth waveform. For this calculation, define local variables for the sample rate and duration of the L-STF and L-LTF in seconds.
% Demodulate the L-LTF.
% Perform channel estimation using the L-LTF.
% Estimate the noise variance.

sr = 80e6;
Tlstf = 8e-6;
Tlltf = 8e-6;
idxlltf = Tlstf*sr+(1:Tlltf*sr);
lltfDemod = wlanLLTFDemodulate(rxSig(idxlltf,:),cbw);
chEst = wlanLLTFChannelEstimate(lltfDemod,cbw);
noiseVarEst = 10^(-snr/20);

%
%% Format detection
% Determine indices for the three symbols following the L-LTF. For an 80 MHz bandwidth waveform, the duration for three symbols is 12 \mu s.
% Detect format detection using modified recovery settings.

TdetectionSymbols = 12e-6;
idxDetectionSymbols = (Tlstf+Tlltf)*sr+(1:TdetectionSymbols*sr);
in = rxSig(idxDetectionSymbols,:);
format = wlanFormatDetect(in,chEst,noiseVarEst,cbw,...
    'OFDMSymbolOffset',0.5,'PilotPhaseTracking','None')

% Copyright 2012 The MathWorks, Inc.