%% Recover Bits from VHT Signal Transmitted Through 2x2 Fading Channel
% Recover bits from the VHT-Data field of a VHT waveform transmitted though a 2x2 fading channel by using channel estimation on the VHT long training field (VHT-LTF).
% Configure a VHT transmission with a channel bandwidth of 160 MHz, two transmit antennas, and two transmission paths.

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

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

psduLength = 8*cfgVHT.PSDULength;
bits = randi([0 1],psduLength,1);
txLTF  = wlanVHTLTF(cfgVHT); 
txDataSig = wlanVHTData(bits,cfgVHT);

% Pass the transmitted waveform through a 2x2 quasi-static fading channel with additive white Gaussian noise (AWGN).

snr = 10;
H = complex(randn(2,2),randn(2,2))/sqrt(2);
rxLTF  = awgn(txLTF*H,snr);
rxDataSig = awgn(txDataSig*H,snr);

% Calculate the received signal power and estimate the noise variance.

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

% Perform channel estimation based on the VHT-LTF.

sym = wlanVHTLTFDemodulate(rxLTF,cfgVHT,1);
chEst = wlanVHTLTFChannelEstimate(sym,cfgVHT);

% Recover the bits from the received VHT-Data field and confirm that the received bits match the transmitted bits.

dataBits = wlanVHTDataRecover(rxDataSig,chEst,noiseVarEst,cfgVHT);
numErr = biterr(bits,dataBits)

% Copyright 2012 The MathWorks, Inc.