%% Recover Header Bits from DMG OFDM Transmission
% Recover information bits from the DMG header in an OFDM transmission.
%
%% Transmitter
% Create a DMG configuration object with a modulation and coding scheme (MCS) for OFDM PHY.

cfg = wlanDMGConfig('MCS',14);

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

txBits = randi([0 1],8*cfg.PSDULength,1,'int8'); 
tx = wlanWaveformGenerator(txBits,cfg);

%
%% AWGN Channel
% Set an SNR of 10 dB, calculate the noise power (noise variance), and add AWGN to the waveform by using the awgn function.

snr = 10;
nVar = 10^(-snr/10);
rx = awgn(tx,snr);

%
%% Receiver
% Extract the DMG header.

ind = wlanFieldIndices(cfg);
rxHeader = rx(ind.DMGHeader(1):ind.DMGHeader(2));

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

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

% Recover the information bits from the DMG header.

[rxBits,failHCS] = wlanDMGHeaderBitRecover(rxSym,nVar,cfg);

% Confirm that the recovered bits pass the HCS.

disp(failHCS)

% Copyright 2012 The MathWorks, Inc.