%% Recover HE-Data Field from HE TB Packet in AWGN Channel
% Generate an HE TB packet, pass through an AWGN channel, then demodulate and recover the HE-Data field from the received waveform.
% Generate a WLAN HE TB waveform in response to a frame containing the TRS control subfield.

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

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

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

% Extract the data field from the received waveform.

ind = wlanFieldIndices(cfgHE);
rxData = rxWaveform(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 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.

disp(isequal(dataBits,psdu))

% Copyright 2019 The MathWorks, Inc.