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

AllocationIndex = 192;
cfgHE = wlanHEMUConfig(AllocationIndex,'SIGBCompression',false);
bits = [1;0];
waveform = wlanWaveformGenerator(bits,cfgHE);

% Extract the L-SIG and HE-SIG-A portions from 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.

s = getSIGBLength(cfg);
rxSIGB = waveform(double(ind.HESIGA(2))+(1:s.NumSIGBCommonFieldSamples),:);

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

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

% Copyright 2019 The MathWorks, Inc.