%% Recover DMG Header Field from Control Transmission
% Recover bits from the DMG Header field in a control transmission.
% Create a DMG configuration object with a modulation and coding scheme (MCS) for a control PHY configuration.

cfgDMG = wlanDMGConfig('MCS',0);

% 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 noiseless channel.

noiseVarEst = 0;

%  Extract the DMG Header field by using the wlanFieldIndices function.

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

% Rotate the received signal by 90 degrees.

rxSymRotated = rxSym.*exp(-1i*(pi/2)*(0:size(rxSym,1) - 1).');

% Generate a Golay sequence of length 32 by using the wlanGolaySequence function.

len = 32;
Ga = wlanGolaySequence(len);

% Despread the signal with a factor equal to the golay sequence length.

rxHeader = reshape(rxSymRotated,len,length(rxSymRotated)/len)'*Ga/len;

% Recover the bits from the DMG Header field.

[headerBits,failHCS] = wlanDMGHeaderBitRecover(rxHeader,noiseVarEst,cfgDMG);

% Display the result of the HCS check.

disp(failHCS);

% Copyright 2012 The MathWorks, Inc.