%% Recover Data Field from DMG OFDM Transmission
% Recover information bits from the DMG Data field of 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);

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

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

%
%% Receiver
%  Extract the DMG data field.

ind = wlanFieldIndices(cfg);
rxData = rx(ind.DMGData(1):ind.DMGData(2));

% Perform the OFDM demodulation on the received waveform, then extract the data subcarriers.

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

% Recover the PSDU from the DMG Data field, assuming a CSI estimate of all ones.

csi = ones(length(info.DataIndices),1);
rxBits = wlanDMGDataBitRecover(rxSym,nVar,csi,cfg);

% Confirm that the decoded bits match the original information bits.

disp(isequal(txBits,rxBits));

% Copyright 2012 The MathWorks, Inc.