%% Detect HE-SU-Format Waveform
% Detect the format of a WLAN HE SU waveform
% Generate an HE SU waveform and obtain a received signal by adding noise.

cbw = 'CBW20'; % Specify channel bandwidth of 20MHz
cfgHESU = wlanHESUConfig('ChannelBandwidth',cbw); % Create configuration object for HE SU format
bits = [1;0;0;1];
tx = wlanWaveformGenerator(bits,cfgHESU); % Generate HE SU waveform
snr = 10; % Specify signal-to-noise ratio (SNR)
rx = awgn(tx,snr); % Create receive waveform

% Specify the sample rate and durations of the relevant PPDU fields.

sr = 20e6; % Sample rate in samples per second
tLSTF = 8e-6; % Duration of legacy short training field (L-STF)
tLLTF = tLSTF; % Duration of legacy long training field (L-LTF)

% Determine the field indices and estimate the channel using the L-LTF.

ind = tLSTF*sr+(1:tLLTF*sr);
y = wlanLLTFDemodulate(rx(ind,:),cbw);
chEst = wlanLLTFChannelEstimate(y,cbw);

% Specify the channel noise variance estimate and detect the format of the waveform.

noiseVarEst = 10^(-snr/20);
rxSig = rx((tLSTF+tLLTF)*sr+(1:sr*(16e-6)),:); % 16 microseconds corresponding to four OFDM symbols after HE L-LTF
format = wlanFormatDetect(rxSig,chEst,noiseVarEst,cbw);
disp(format)

% Copyright 2019 The MathWorks, Inc.