%% Recover Bits from HE-Data Field from HE TB Transmission
% Recover bits from the HE-Data field of an HE TB waveform transmitted through an AWGN channel.
% Generate a WLAN HE TB waveform in response to a frame containing the TRS control subfield.

cfgHE = getTRSConfiguration(wlanHETBConfig);
psduLength = 8*getPSDULength(cfgHE);
bits = randi([0,1],psduLength,1,'int8');
waveform = wlanWaveformGenerator(bits,cfgHE);

% Pass the waveform through an AWGN channel with an SNR of 30 dB.

snr = 30;
rx = awgn(waveform,snr);

% Extract the HE-Data field from the received waveform.

ind = wlanFieldIndices(cfgHE);
rxData = rx(ind.HEData(1):ind.HEData(2),:);

% Demodulate the waveform and extract the data subcarriers.

demod = wlanHEDemodulate(rxData,'HE-Data',cfgHE);
info = wlanHEOFDMInfo('HE-Data',cfgHE);
rxDataSym = demod(info.DataIndices,:,:);

% Recover the data bits subject to the specified estimates for CSI and noise variance, implementing normalized min-sum low-density parity-check (LDPC) decoding.

csi = ones(length(rxDataSym),1);
noiseVarEst = 10^(-snr/10);
dataBits = wlanHEDataBitRecover(rxDataSym,noiseVarEst,csi,cfgHE, ...
    'LDPCDecodingMethod','norm-min-sum');

% Confirm that the recovered information bits match the transmitted PSDU.

isequal(dataBits,bits)

% Copyright 2019 The MathWorks, Inc.