%% Recover VHT-Data Field Over 2x2 Fading Channel
% Recover bits in the VHT-Data field using channel estimation on a VHT-LTF field over a 2 x 2 quasi-static fading channel.
% Create a VHT configuration object with 160 MHz channel bandwidth and two transmission paths.

cbw = 'CBW160';
vht = wlanVHTConfig('ChannelBandwidth',cbw,'NumTransmitAntennas',2,'NumSpaceTimeStreams',2,'APEPLength',512);

%
% Generate VHT-LTF and VHT-Data field signals.

txDataBits = randi([0 1],8*vht.PSDULength,1);
txVHTLTF  = wlanVHTLTF(vht); 
txVHTData = wlanVHTData(txDataBits,vht);

%
% Pass the transmitted waveform through a 2 x 2 quasi-static fading channel with AWGN.

snr = 10;
H = 1/sqrt(2)*complex(randn(2,2),randn(2,2));
rxVHTLTF  = awgn(txVHTLTF*H,snr);
rxVHTData = awgn(txVHTData*H,snr);

%
% Calculate the received signal power and use it to estimate the noise variance.

powerDB = 10*log10(var(rxVHTData));
noiseVarEst = mean(10.^(0.1*(powerDB-snr)));

%
% Perform channel estimation based on the VHT-LTF field.

demodVHTLTF = wlanVHTLTFDemodulate(rxVHTLTF,vht,1);
chanEst = wlanVHTLTFChannelEstimate(demodVHTLTF,vht);

%
% Recover payload bits in the VHT-Data field and compare against the original payload bits.

rxDataBits = wlanVHTDataRecover(rxVHTData,chanEst,noiseVarEst,vht);
numErr = biterr(txDataBits,rxDataBits)

% Copyright 2012 The MathWorks, Inc.