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
Use the radioConfigurations
function to identify a radio to use with this example. 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.
radios = radioConfigurations;
Specify the name of a saved radio setup configuration to use with this example.
radioName =
radios(1).Name;
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 =
52;
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.
load("TriggeredWLANData.mat");
preamble = preamble/sqrt(sum(abs(preamble).^2));
Create a preamble detector object with the specified radio. To speed up the execution time of this example upon subsequent runs, reuse the workspace object from the first run of the example.
if ~exist("pd","var") pd = preambleDetector(radioName); end
Set the RF properties of the preamble detector.
pd.SampleRate = 40e6;
pd.CenterFrequency = getWLANCenterFrequency(WLANFrequenciesMap,band,channel);
pd.Antennas =
"RF0:RX2";
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.2; pd.AdaptiveThresholdOffset =
0.15; pd.RadioGain =
60; plotThreshold(pd,milliseconds(120));
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 200 ms timeout.
recordLen =milliseconds(100); timeout =
milliseconds(200); [data, timestamp, ~, status] = capture(pd, recordLen, timeout);
If detection is successful, plot the first 500 samples.
if ~status disp("Detection failed.") else disp(" WLAN signal detected at " + string(timestamp) + "."); figure(); 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"); end
WLAN signal detected at 19-Jan-2022 11:50:19.
Local Functions
function frequency = getWLANCenterFrequency(WLANFrequenciesMap,band,channel) % Look up center frequency according to band and channel channelSelectKey = band + "GHz:" + channel; frequency = WLANFrequenciesMap(channelSelectKey); end