%% Update HE MU Recovery Configuration Object
% Update a WLAN HE recovery configuration object by interpreting recovered HE-SIG-A and HE-SIG-B information bits.
%
%% Generate HE MU Waveform
% Create a WLAN HE MU configuration object, setting the allocation index to 0.

cfgHEMU = wlanHEMUConfig(0);

% Generate a WLAN waveform and PPDU field indices for the specified configuration.

waveform = wlanWaveformGenerator(1,cfgHEMU);
ind = wlanFieldIndices(cfgHEMU);

%
%% Recover L-SIG Bits
% Create a WLAN recovery configuration object, specifying an HE MU packet format and the length of the L-SIG field.

cfg = wlanHERecoveryConfig('PacketFormat','HE-MU','ChannelBandwidth','CBW20');

% Decode the L-SIG field and obtain the orthogonal frequency-division multiplexing (OFDM) information. The recovery configuration object requires this information to obtain the L-SIG length.

lsig = waveform(ind.LSIG(1):ind.LSIG(2));
lsigDemod = wlanHEDemodulate(lsig,'L-SIG',cfg.ChannelBandwidth);
info = wlanHEOFDMInfo('L-SIG',cfg.ChannelBandwidth);
lsigDemod = lsigDemod(info.DataIndices,:);

% Recover the L-SIG bits and related information, making sure that the bits pass the parity check, and update the recovery configuration object with the L-SIG length. For this example we assume a noiseless channel. For more realistic results you can pass the waveform through an 802.11ax™ channel model by using the wlanTGaxChannel System object™ and work with the received waveform.

csi = ones(52,1);
[lsigBits,failCheck,lsigInfo] = wlanLSIGBitRecover(lsigDemod,0,csi);
cfg.LSIGLength = lsigInfo.Length;

%
%% Update Recovery Configuration Object with HE-SIG-A Bits
% Decode the HE-SIG-A field and recover the HE-SIG-A bits, ensuring that the bits pass the cyclic redundancy check (CRC).

siga = waveform(ind.HESIGA(1):ind.HESIGA(2));
sigaDemod = wlanHEDemodulate(siga,'HE-SIG-A',cfg.ChannelBandwidth);
sigaDemod = sigaDemod(info.DataIndices,:);
[sigaBits,failCRC] = wlanHESIGABitRecover(sigaDemod,0,csi);
disp(failCRC)

% Update the recovery configuration object with the recovered HE-SIG-A bits. Display the updated object. A property value of -1 or 'Unknown' indicates an unknown or undefined property, which can be updated after decoding the HE-SIG-B common and user fields of the HE MU packet.

[cfg,failInterpretation] = interpretHESIGABits(cfg,sigaBits)

%% Update Recovery Configuration Object with HE-SIG-B Common Field Bits
% Decode the HE-SIG-B common field, ensuring that all content channels pass the CRC.

len = getSIGBLength(cfg);
sigbCommon = waveform(double(ind.HESIGA(2))+(1:len.NumSIGBCommonFieldSamples),:);
sigbCommonDemod = wlanHEDemodulate(sigbCommon,'HE-SIG-B',cfgHEMU.ChannelBandwidth);
sigbCommonDemod = sigbCommonDemod(info.DataIndices);
[sigbCommonBits,status,~] = wlanHESIGBCommonBitRecover(sigbCommonDemod,0,csi,cfg);
disp(status)

% Update the recovery configuration object with the recovered HE-SIG-B common field bits and display the updated object. A field returned as -1 or 'Unknown' indicates an unknown or undefined property value, which can be updated after decoding the HE-SIG-B user field of the HE MU packet.

[cfg,failInterpretation] = interpretHESIGBCommonBits(cfg,sigbCommonBits,status)

%
%% Update Recovery Configuration Object with HE-SIG-B User Field Bits
% Decode the HE-SIG-B user field, ensuring that all users pass the CRC.

sigbUser = waveform(ind.HESIGB(1):ind.HESIGB(2));
sigbUserDemod = wlanHEDemodulate(sigbUser,'HE-SIG-B',cfgHEMU.ChannelBandwidth);
sigbUserDemod = sigbUserDemod(info.DataIndices,:);
[sigbUserBits,failCRC,~] = wlanHESIGBUserBitRecover(sigbUserDemod,0,csi,cfg);
disp(failCRC)

% Update the recovery configuration object with the recovered HE-SIG-B user field bits.

[user,failInterpretation] = interpretHESIGBUserBits(cfg,sigbUserBits,failCRC);

% Display the results of interpretation and the third element of the user output.

disp(failInterpretation)
disp(user{3})

% Copyright 2018 The MathWorks, Inc.