%% Recover DMG Data Field from SC Transmission
% Recover bits from the DMG Data field of a single-carrier (SC) transmission.
% Configure an SC transmission by creating a DMG configuration object with an MCS of 10.

cfgDMG = wlanDMGConfig('MCS',10);

% 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 channel, assuming AWGN with an SNR of 10 dB.

snr = 10;                       % SNR, in dB
noiseVarEst = 10^(-snr/10);     % Noise variance
rxSig = awgn(waveform,snr);

% Extract the DMG Data field from the received signal.

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

% Reshape the received data waveform into blocks. Set the data block size to 512 and the guard interval (GI) length to 64. Remove the last GI from the received waveform. The resulting waveform is a 512-by-Nblks matrix, where Nblks is the number of DMG data blocks.

blkSize = 512;                                    % Block size
Ngi = 64;                                         % GI length
rxSymNoGI = rxSym(1:end-Ngi);                     % Remove GI
rxSymReshaped = reshape(rxSymNoGI,blkSize,[]);    % Reshape received data

% Remove the GI from each block. Confirm that the resulting signal is a 448-by-Nblks matrix, as expected for the time-domain DMG Data field signal in an SC PHY configuration.

rxData = rxSymReshaped(Ngi+1:end,:);
disp(size(rxData))

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

dataBits = wlanDMGDataBitRecover(rxData,noiseVarEst,cfgDMG,'LDPCDecodingMethod','layered-bp');

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

disp(isequal(bits,dataBits))

% Copyright 2012 The MathWorks, Inc.