%% Recover Information Bits in HE-SIG-B User Field
% Recover the information bits in the HE-SIG-B user field of a WLAN HE MU waveform.
% Generate an HE MU waveform for the specified information bits and HE-MU-format configuration object.

cfgHE = wlanHEMUConfig(192);
bits = [1;0;1;1];
waveform = wlanWaveformGenerator(bits,cfgHE);

% Extract the L-SIG and HE-SIG-A portions of the waveform.

ind = wlanFieldIndices(cfgHE);
rxLSIG = waveform(ind.LSIG(1):ind.LSIG(2),:);
rxSIGA = waveform(ind.HESIGA(1):ind.HESIGA(2),:);

% Create an HE recovery configuration object for an HE-MU-format packet, specifying the channel bandwidth and packet format.

cbw = cfgHE.ChannelBandwidth;
cfgRecovery = wlanHERecoveryConfig('ChannelBandwidth',cbw,'PacketFormat','HE-MU');

% Perform OFDM demodulation to extract the L-SIG and HE-SIG-A fields, assuming no channel noise.

noiseVarEst = 0;
info = wlanHEOFDMInfo('L-SIG',cbw);
lsigDemod = wlanHEDemodulate(rxLSIG,'L-SIG',cbw);
sigaDemod = wlanHEDemodulate(rxSIGA,'HE-SIG-A',cbw);
[~,~,lsigInfo] = wlanLSIGBitRecover(lsigDemod(info.DataIndices,:),noiseVarEst);
cfgRecovery.LSIGLength = lsigInfo.Length;
siga = wlanHESIGABitRecover(sigaDemod(info.DataIndices,:),noiseVarEst);

% Update the HE recovery configuration object with the HE-SIG-A information bits.

cfg = interpretHESIGABits(cfgRecovery,siga);

% Extract the HE-SIG-B field.

rxSIGB = waveform(ind.HESIGB(1):ind.HESIGB(2),:);

% Demodulate and decode the HE-SIG-B user field, displaying the result.

sigbDemod = wlanHEDemodulate(rxSIGB,'HE-SIG-B',cbw);
sigb = sigbDemod(info.DataIndices,:,:);
[bits,failCRC,cfgUpdated] = wlanHESIGBUserBitRecover(sigb,noiseVarEst,cfg);
disp(bits')
disp(failCRC)

% Copyright 2019 The MathWorks, Inc.