function [rx,pktOffset,gain] = rxFrontEnd(rx,pktOffset,ind,cfgRx) sr = wlanSampleRate(cfgRx); % Sample rate % Coarse frequency offset estimation and correction using L-STF rxLSTF = rx(pktOffset+(ind.LSTF(1):ind.LSTF(2)), :); coarseFreqOffset = wlanCoarseCFOEstimate(rxLSTF,cfgRx.ChannelBandwidth); rx = helperFrequencyOffset(rx,sr,-coarseFreqOffset); % Symbol timing synchronization searchBufferLLTF = rx(pktOffset+(ind.LSTF(1):ind.LSIG(2)),:); pktOffset = pktOffset+wlanSymbolTimingEstimate(searchBufferLLTF,cfgRx.ChannelBandwidth); % Fine frequency offset estimation and correction using L-STF rxLLTF = rx(pktOffset+(ind.LLTF(1):ind.LLTF(2)),:); fineFreqOffset = wlanFineCFOEstimate(rxLLTF,cfgRx.ChannelBandwidth); rx = helperFrequencyOffset(rx,sr,-fineFreqOffset); % Timing synchronization complete: packet detected fprintf('Packet detected at index %d\n',pktOffset + 1); % Display estimated carrier frequency offset cfoCorrection = coarseFreqOffset + fineFreqOffset; % Total CFO fprintf('Estimated CFO: %5.1f Hz\n\n',cfoCorrection); % Scale the waveform based on L-STF power (AGC) gain = 1./(sqrt(mean(rxLSTF.*conj(rxLSTF)))); rx = rx.*gain; end