Main Content

Triggered WLAN Waveform Capture Using Preamble Detection

This example shows how to use a software-defined-radio (SDR) to capture a WLAN waveform from the air by detecting the legacy long training field (L-LTF).

Set Up Radio

Call the radioConfigurations function. The function returns all available radio setup configurations that you saved using the Radio Setup wizard. For more information, see Connect and Set Up NI USRP Radios.

savedRadioConfigurations = radioConfigurations;

To update the dropdown menu with your saved radio setup configuration names, click Update. Then select the radio to use with this example.

savedRadioConfigurationNames = [string({savedRadioConfigurations.Name})];
radio = savedRadioConfigurationNames(1) ;

Configure WLAN Channel Information

Select a frequency band and channel to search for a WLAN waveform.

These are the valid WLAN frequency bands.

  • 2.4 GHz

  • 5 GHz

These are the valid WLAN channel numbers.

  • 1–14 for the 2.4 GHz band

  • 1–200 for the 5 GHz band. However, the valid 20 MHz control channels for access points using 5 GHz are 32, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 149, 153, 157, 161, 165, 169, 173, and 177.

band = 5;
channel = 60;

Configure WLAN Preamble Detector

Load the WLAN preamble sequence and center frequency information. The preamble consists of one long training symbol from a 20 MHz L-LTF waveform, sampled at 40 MHz. Normalize the preamble sequence to be between -1 and 1.

preamble = preamble/sqrt(sum(abs(preamble).^2));

Create a preamble detector object with the specified radio. Because the object requires exclusive access to radio hardware resources, before running this example for the first time, clear any other object associated with the specified radio. In subsequent runs, to speed up the execution time of the example, reuse your new workspace object.

if ~exist("pd","var")
    pd = preambleDetector(radio);

Set the RF properties of the preamble detector.

pd.SampleRate = 40e6;
pd.CenterFrequency = getWLANCenterFrequency(WLANFrequenciesMap,band,channel);

To update the dropdown menu with the antennas available for your radio, call the hCaptureAntennas helper function. Then select the antenna to use with this example.

antennaSelection = hCaptureAntennas(radio);
pd.Antennas = antennaSelection(1);

Configure the filter coefficients for preamble detection.

pd.Preamble = preamble;

Set the threshold method to adaptive. To include the preamble sequence in the captured waveform, set the trigger offset to a negative value.

pd.ThresholdMethod = "adaptive";
pd.TriggerOffset = -200;

Configure Adaptive Threshold for Triggering

Set the adaptive threshold gain, adaptive threshold offset, and radio gain values of the preamble detector for the local environment. Use the plotThreshold function to analyze the behavior of the detector by plotting 120 ms of data. The function plots the correlator output, adaptive threshold, and detection points. The correlator output contains two peaks for each OFDM packet. Each peak corresponds to a long training symbol. Adjust the adaptive threshold gain, adaptive threshold offset, and radio gain values such that the trigger points occur only on the correlator output peaks. For more information on tuning these values, see Triggered Capture Using Preamble Detection.

pd.AdaptiveThresholdGain = 0.35;
pd.AdaptiveThresholdOffset = 0.01;
pd.RadioGain = 60;

Capture WLAN Signal

Use the capture function to capture data with the configured preamble detector. Because WLAN beacons are transmitted every 100 ms, capture 100 ms of data with a 100 ms timeout.

recordLen = milliseconds(100);
timeout = milliseconds(100);
[data, timestamp, ~, status] = capture(pd,recordLen,timeout);

If detection is successful, plot the first 500 samples.

if ~status
    disp("Detection failed.")
    disp("   WLAN signal detected at " + string(timestamp) + ".");
    subplot(2,1,1); plot(real(double(data(1:500)))); ...
        xlabel("Samples"); ylabel("Amplitude");
    subplot(2,1,2); plot(imag(double(data(1:500)))); ...
        xlabel("Samples"); ylabel("Amplitude");  
   WLAN signal detected at 06-Jan-2023 09:15:27.

Local Functions

function frequency = getWLANCenterFrequency(WLANFrequenciesMap,band,channel)
% Look up center frequency according to band and channel
channelSelectKey = band + "GHz:" + channel;
frequency = WLANFrequenciesMap(channelSelectKey);

See Also



Related Topics