%% Recover L-SIG Information from 2x2 MIMO Channel
% Recover L-SIG information transmitted in a noisy 2x2 MIMO channel, and calculate the number of bit errors present in the received information bits.
% Set the channel bandwidth and sample rate.

chanBW = 'CBW40';
fs = 40e6;

%
% Create a VHT configuration object corresponding to a 40 MHz 2x2 MIMO channel.

vht = wlanVHTConfig( ...
    'ChannelBandwidth',chanBW, ...
    'NumTransmitAntennas',2, ...
    'NumSpaceTimeStreams',2);

%
% Generate the L-LTF and L-SIG field signals.

txLLTF = wlanLLTF(vht);
[txLSIG,txLSIGData] = wlanLSIG(vht);

%
% Create a 2x2 TGac channel and an AWGN channel with an SNR=10 dB.

tgacChan = wlanTGacChannel('SampleRate',fs,'ChannelBandwidth',chanBW, ...
    'NumTransmitAntennas',2,'NumReceiveAntennas',2);

chNoise = comm.AWGNChannel('NoiseMethod','Signal to noise ratio (SNR)',...
    'SNR',10);

%
% Pass the signals through the noisy 2x2 multipath fading channel.

rxLLTF = chNoise(tgacChan(txLLTF));
rxLSIG = chNoise(tgacChan(txLSIG));

%
% Add additional white noise corresponding to a receiver with a 9 dB noise figure. The noise variance is equal to k*T*B*F, where k is Boltzmann's constant, T is the ambient temperature, B is the channel bandwidth (sample rate), and F is the receiver noise figure.

nVar = 10^((-228.6+10*log10(290) + 10*log10(fs) + 9 )/10);
rxNoise = comm.AWGNChannel('NoiseMethod','Variance','Variance',nVar);

rxLLTF = rxNoise(rxLLTF);
rxLSIG = rxNoise(rxLSIG);

%
% Perform channel estimation based on the L-LTF.

demodLLTF = wlanLLTFDemodulate(rxLLTF,chanBW,1);
chanEst = wlanLLTFChannelEstimate(demodLLTF,chanBW);

%
% Recover the L-SIG information bits.

rxLSIGData = wlanLSIGRecover(rxLSIG,chanEst,0.1,chanBW);

%
% Verify that there are no bit errors in the recovered L-SIG data.

numErrors = biterr(txLSIGData,rxLSIGData)

% Copyright 2012 The MathWorks, Inc.