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

cfgHEMU = wlanHEMUConfig(0);

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

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

% Decode the L-SIG field and obtain the orthogonal frequency-division multiplexing (OFDM) information. This information is required to obtain the L-SIG length, which is used in the recovery configuration object.

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

% Recover the L-SIG bits and related information, making sure that the bits pass the parity check. 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(preHEInfo.DataIndices,:,:),0,csi);

% 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',cfgHEMU.ChannelBandwidth);
preHEInfo = wlanHEOFDMInfo('HE-SIG-A',cfgHEMU.ChannelBandwidth);
[bits,failCRC] = wlanHESIGABitRecover(sigaDemod(preHEInfo.DataIndices,:,:),0,csi);

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

cfg = wlanHERecoveryConfig('PacketFormat','HE-MU','LSIGLength',lsigInfo.Length);

% Update the recovery configuration object with the recovered HE-SIG-A bits. 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 field of the HE-MU packet.

cfgUpdated = interpretHESIGABits(cfg,bits);
disp(cfgUpdated);

% Copyright 2018 The MathWorks, Inc.