%% Estimate MIMO Channel Using VHT-LTF
% Estimate and display the channel coefficients of a 4x2 MIMO channel using the VHT-LTF.
% Create a VHT format configuration object for a channel having four spatial streams and four transmit antennas. Transmit a complete VHT waveform.

cfg = wlanVHTConfig('NumTransmitAntennas',4, ...
    'NumSpaceTimeStreams',4,'MCS',5);
txWaveform = wlanWaveformGenerator([1;0;0;1;1;0],cfg);

%
% Set the sampling rate, and then pass the transmitted waveform through a 4x2 TGac channel.

fs = 80e6;
tgacChan = wlanTGacChannel('SampleRate',fs, ...
    'NumTransmitAntennas',4,'NumReceiveAntennas',2);
rxWaveform = tgacChan(txWaveform);

%
% Determine the VHT-LTF field indices and demodulate the VHT-LTF from the received waveform.

indVHTLTF = wlanFieldIndices(cfg,'VHT-LTF');
ltfDemodSig = wlanVHTLTFDemodulate(rxWaveform(indVHTLTF(1):indVHTLTF(2),:), cfg);

%
% Generate the channel estimate by using the demodulated VHT-LTF signal. Specify a smoothing filter span of five subcarriers.

est = wlanVHTLTFChannelEstimate(ltfDemodSig,cfg,5);

%
% Plot the magnitude response of the first space-time stream for both receive antennas. Due to the random nature of the fading channel, your results may vary.

plot(abs(est(:,1,1)))
hold on
plot(abs(est(:,1,2)))
xlabel('Subcarrier')
ylabel('Magnitude')
legend('Rx Antenna 1','Rx Antenna 2')

% Copyright 2012 The MathWorks, Inc.