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

cfgDMG = wlanDMGConfig('MCS',0);

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

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

%
%% Receiver
% Assume that the transmission passes through a noiseless channel.

rx = tx;

%  Extract the header and the data field by using the wlanFieldIndices function.

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

% De-rotate the received signal by 90 degrees and despread it with a spreading factor of 32. Generate the Golay sequence by using the wlanGolaySequence function.

rxSym = rxSym.*exp(-1i*pi/2*(0:size(rxSym,1)-1).');
sf = 32; 
Ga = wlanGolaySequence(sf);
rxSymDespread = (reshape(rxSym,sf,length(rxSym)/sf)'*Ga)/sf;

% Recover the PSDU from the DMG Data field.

rxBits = wlanDMGDataBitRecover(rxSymDespread,0,cfgDMG);

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

disp(isequal(txBits,rxBits))

% Copyright 2012 The MathWorks, Inc.