%% Recover DMG Header Field from OFDM Transmission
% Recover bits from the DMG Header field of an OFDM transmission.
% Configure an OFDM transmission by creating a DMG configuration object with an MCS of 14.

cfgDMG = wlanDMGConfig('MCS',14);

% Create a sequence of data bits and generate a DMG waveform.

bits = randi([0 1],8*cfgDMG.PSDULength,1,'int8'); 
waveform = wlanWaveformGenerator(bits,cfgDMG);

% Pass the waveform through a channel, assuming additive white Gaussian noise (AWGN) for the specified signal-to-noise ratio (SNR).

snr = 10;                      % SNR, in dB
noiseVarEst = 10^(-snr/10);    % Noise variance
rxSig = awgn(waveform,snr);

% Extract the DMG Header field from the received signal.

ind = wlanFieldIndices(cfgDMG);
rxSym = rxSig(ind.DMGHeader(1):ind.DMGHeader(2));

% Perform OFDM demodulation on the received header and extract the data subcarriers.

demod = wlanDMGOFDMDemodulate(rxSym);
info = wlanDMGOFDMInfo;
rxHeader = demod(info.DataIndices,:);

% Recover the bits from the DMG Header field, assuming a CSI estimate of all ones.

csi = ones(length(info.DataIndices),1);
[headerBits,failHCS] = wlanDMGHeaderBitRecover(rxHeader,noiseVarEst,csi,cfgDMG);

% Confirm that the recovered bits pass the HCS.

disp(failHCS)

% Copyright 2012 The MathWorks, Inc.