%% Estimate and Correct CFO for VHT Waveform
% Estimate the frequency offset for a VHT signal passing through a noisy, TGac channel. Correct for the frequency offset.
% Create a VHT configuration object and create the L-LTF.

vht = wlanVHTConfig;
txltf = wlanLLTF(vht);

%
% Set the sample rate to correspond to the default bandwidth of the VHT configuration object.

fs = 80e6;

%
% Create TGac and thermal noise channel objects. Set the noise figure of the AWGN channel to 10 dB.

tgacChan = wlanTGacChannel('SampleRate',fs, ...
    'ChannelBandwidth',vht.ChannelBandwidth, ...
    'DelayProfile','Model-C','LargeScaleFadingEffect','Pathloss');

noise = comm.ThermalNoise('SampleRate',fs, ...
    'NoiseMethod','Noise figure', ...
    'NoiseFigure',10);

%
% Pass the L-LTF through the noisy TGac channel.

rxltfNoNoise = tgacChan(txltf);
rxltf = noise(rxltfNoNoise);

%
% Create a phase and frequency offset object and introduce a 25 Hz frequency offset.

pfoffset = comm.PhaseFrequencyOffset('SampleRate',fs,'FrequencyOffsetSource','Input port');
rxltf = pfoffset(rxltf,25);

%
% Perform a fine estimate the frequency offset using a correlation offset of 0.6. Your results may differ slightly.

fOffsetEst = wlanFineCFOEstimate(rxltf,vht.ChannelBandwidth,0.6)

%
% Correct for the estimated frequency offset.

rxltfCorr = pfoffset(rxltf,-fOffsetEst);

%
% Estimate the frequency offset of the corrected signal.

fOffsetEstCorr = wlanFineCFOEstimate(rxltfCorr,vht.ChannelBandwidth,0.6)

% The corrected signal has negligible frequency offset.
% Copyright 2012 The MathWorks, Inc.