%% Extract VHT-LTF and Recover VHT Data
% Generate a VHT waveform. Extract and demodulate the VHT long training field (VHT-LTF) to estimate the channel coefficients. Recover the data field by using the channel estimate and use this field to determine the number of bit errors.
% Configure a VHT-format configuration object with two paths.

vht = wlanVHTConfig('NumTransmitAntennas',2,'NumSpaceTimeStreams',2);

% Generate a random PSDU and create the corresponding VHT waveform.

txPSDU = randi([0 1],8*vht.PSDULength,1);
txSig = wlanWaveformGenerator(txPSDU,vht);

% Pass the signal through a TGac 2x2 MIMO channel.

tgacChan = wlanTGacChannel('NumTransmitAntennas',2,'NumReceiveAntennas',2, ...
    'LargeScaleFadingEffect','Pathloss and shadowing');
rxSigNoNoise = tgacChan(txSig);

% Add AWGN to the received signal. Set the noise variance for the case in which the receiver has a 9-dB noise figure.

nVar = 10^((-228.6+10*log10(290)+10*log10(80e6)+9)/10);
awgnChan = comm.AWGNChannel('NoiseMethod','Variance','Variance',nVar);
rxSig = awgnChan(rxSigNoNoise);

% Determine the indices for the VHT-LTF and extract the field from the received signal.

indVHT = wlanFieldIndices(vht,'VHT-LTF');
rxLTF = rxSig(indVHT(1):indVHT(2),:);

% Demodulate the VHT-LTF and estimate the channel coefficients.

dLTF = wlanVHTLTFDemodulate(rxLTF,vht);
chEst = wlanVHTLTFChannelEstimate(dLTF,vht);

% Extract the VHT-Data field and recover the information bits.

indData = wlanFieldIndices(vht,'VHT-Data');
rxData = rxSig(indData(1):indData(2),:);
rxPSDU = wlanVHTDataRecover(rxData,chEst,nVar,vht);

% Determine the number of bit errors.

numErrs = biterr(txPSDU,rxPSDU)

% Copyright 2012 The MathWorks, Inc.