%% Recover Header Field from DMG SC Transmission
% Recover information bits from the DMG header in a single-carrier (SC) transmission.
%
%% Transmitter
% Create a DMG configuration object with a modulation and coding scheme (MCS) for SC PHY.

cfg = wlanDMGConfig('MCS',10);

% 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 data field.

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

% Reshape the received data waveform into blocks. Set the data block size to 512 and the guard interval length to 64. Remove the last guard interval from the received data waveform. The resulting signal is a 512-by-2 matrix.

blkSize = 512; 
Ngi = 64; 
rxHeader = reshape(rxHeader,blkSize,[]);
rxSym = rxHeader(Ngi+1:end,:);
disp(size(rxSym))

% Recover the PSDU from the DMG data field, specifying layered belief propagation LDPC decoding.

[rxBits,failHCS] = wlanDMGHeaderBitRecover(rxSym,nVar,cfg,'LDPCDecodingMethod','layered-bp');

% Confirm that the recovered bits pass the HCS.

disp(failHCS)

% Copyright 2012 The MathWorks, Inc.