Detect Clear WLAN Channels and Transmit
This example shows how to use a software-defined radio (SDR) energy detector to detect clear WLAN channels and transmit a waveform. The example uses WLAN signal descriptor objects to configure an SDR energy detector to scan a specified WLAN band. The example then tabulates and plots the activity detected in occupied channels, then transmits a waveform in a clear channel.
Introduction
In this example, you use hWLANOFDMDescriptor
helper objects to detect the occupancy of 20 MHz WLAN channels in the specified band. Using the configureDetector
helper function, you configure an SDR energy detector to scan each band by setting the following parameters:
Center frequency
Sample rate
Window Length
Trigger offset
After you establish the detection status of each channel, you calculate the power of the signals in the occupied channels for visualisation and analysis. You then transmit a 20 MHz bandwidth WLAN beacon signal on a clear channel. This diagram shows the workflow.
Describe Wireless Signals
Use the hWLANOFDMDescriptor helper object to describe the WLAN signals to look for. Use the 20MHz bandwidth in the 5GHz band to scan. The hWLANOFDMDescriptor
generates an object for each appropriate WLAN channel defined by the 802.11 standard.
WLANBand = 5; channelBandWidth = "CBW20"; wsds = hWLANOFDMDescriptor(Band=WLANBand,ChannelBandwidth=channelBandWidth);
Create and Configure Radio as Energy Detector
Set Up Radio
Call the radioConfigurations
(Wireless Testbench) function. The function returns all available radio setup configurations that you saved using the Radio Setup (Wireless Testbench) wizard.
savedRadioConfigurations = radioConfigurations;
To add the names of your radio setup configurations to the menu options, click Update. Then select the radio to use with this example.
savedRadioConfigurationNames = [string({savedRadioConfigurations.Name})]; radio = savedRadioConfigurationNames(1) ;
Configure Energy Detector
Create an energyDetector
(Wireless Testbench) 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("ed","var") ed = energyDetector(radio); end
To update the dropdown menu with the antennas available for capture on your radio, call the hCaptureAntennas
helper function. Then select the antenna to use with this example.
captureAntennaSelection = hCaptureAntennas(radio); ed.Antennas = captureAntennaSelection(1); ed.CaptureDataType = 'single';
Tune Energy Detector
Configure the energy delta threshold, minimum energy, and radio gain values of the energy detector for the local environment. For more information, see Triggered Capture Using Energy Detection (Wireless Testbench). Configuring these values requires manual tuning by exploring the trigger points provided by the plotDetectionSignals
function.
ed.ThresholdMethod = "adaptive"; ed.EnergyDeltaThreshold = 5; ed.MinimumEnergy = 0.08; ed.RadioGain = 30;
Scan Clear Channels for WLAN Signals
Use the configureDetector
function to configure the energy detector with an appropriate sliding window length, trigger offset, sample rate and center frequency. Set the detection timeout to 100 milliseconds, which is the expected periodicity of a WLAN beacon packet. Then use the capture
(Wireless Testbench) function to detect and capture the described WLAN signal. To estimate the signal power in the channel, capture 10 ms of data.
wb = hCaptureWaitBar(length(wsds)); occupiedChannels = []; clearChannels = []; for wsd = wsds hUpdateCaptureWaitBar(wb,wsd) ed = configureDetector(wsd,ed); [data,timestamp,~,detectionSuccessful] = capture(ed,milliseconds(10), milliseconds(100)); if detectionSuccessful occupiedChannels = [occupiedChannels,struct(Data=data, Timestamp=timestamp, SampleRate=ed.SampleRate, Descriptor=wsd)]; %#ok<*AGROW> else clearChannels = [clearChannels;wsd]; end end close(wb) if isempty(occupiedChannels) disp("All channels are clear.") return elseif isempty(clearChannels) disp("All channels are occupied.") return end
Tabulate and Plot Detections
Calculate Power
Calculate the power of the signals in the occupied channels.
fullscale = single(intmax('int16')); for ii = 1:length(occupiedChannels) pTime = 20e-6; % Calculate preamble length in Samples pLen = 1:ceil(pTime*occupiedChannels(ii).SampleRate); % Calculate the power of the IQ samples in the detected PSS power = mean(abs(single(occupiedChannels(ii).Data)).^2); % Calculate the dBFS value for the power powerDBFS = 10*log10(power/fullscale^2); occupiedChannels(ii).Power = powerDBFS; %#ok<*SAGROW> end
Tabulate Detected Signals
Display the occupied channels in a table.
detectedWirelessSignals = [occupiedChannels.Descriptor]'; occupiedChannelTableTable = table; for ii = 1:length(occupiedChannels) occupiedChannelTableTable(ii,:) = table(... string(class(detectedWirelessSignals(ii))),... detectedWirelessSignals(ii).CenterFrequency/1e6,... detectedWirelessSignals(ii).Band,... detectedWirelessSignals(ii).Channel,... double(extractAfter(detectedWirelessSignals(ii).ChannelBandwidth,"CBW")),... occupiedChannels(ii).Power,... VariableNames=["Detected Wireless Signal","Center Frequency (MHz)","Band","Channel", "CBW","Signal Power Estimate (dBFS)"]); end disp(occupiedChannelTableTable)
Detected Wireless Signal Center Frequency (MHz) Band Channel CBW Signal Power Estimate (dBFS) ________________________ ______________________ ____ _______ ___ ____________________________ "hWLANOFDMDescriptor" 5220 5 44 20 -126.97 "hWLANOFDMDescriptor" 5240 5 48 20 -138.3 "hWLANOFDMDescriptor" 5500 5 100 20 -128.03 "hWLANOFDMDescriptor" 5520 5 104 20 -141.99 "hWLANOFDMDescriptor" 5540 5 108 20 -140.22 "hWLANOFDMDescriptor" 5580 5 116 20 -134.83 "hWLANOFDMDescriptor" 5600 5 120 20 -142.93 "hWLANOFDMDescriptor" 5765 5 153 20 -120.68 "hWLANOFDMDescriptor" 5785 5 157 20 -144.56 "hWLANOFDMDescriptor" 5805 5 161 20 -142.4 "hWLANOFDMDescriptor" 5825 5 165 20 -139.74
Plot Detected Signals
Plot the power of the occupied channels using the hPlotWLANDetections
helper function.
hPlotWLANDetections(occupiedChannelTableTable);
Select Clear Channel and Transmit Waveform
Select a clear channel to transmit on and configure the energy detector for that channel to visually confirm that the channel is empty.
vacantChannelNumbers = string([clearChannels.Channel]); vacantChannelNumber = vacantChannelNumbers(5); wsdTransmit = clearChannels(vacantChannelNumbers == vacantChannelNumber);
Since the hWLANOFDMDescriptor
helper function sets the energy detector window length to an appropriate value for detecting WLAN signals, signals with smaller bandwidths can be present but not detected. To verify that no other energy signatures are present in your selected band, you may need to use a smaller window length, use a longer timeout, or call plotDetectionSignals
(Wireless Testbench) to visualize energy signals.
plotDetectionSignals(ed,milliseconds(200))
Once satisfied, transmit on the clear channel.
txGain = 30; % Increase if signal levels are low. transmitAntennaSelection = hTransmitAntennas(radio); txAntenna = transmitAntennaSelection(4);
Continuously transmit a WLAN beacon signal on the selected clear channel.
load WLANBeaconWaveform.mat; transmit(ed, WLANBeaconWaveform,"continuous",TransmitGain=txGain, ... TransmitCenterFrequency=ed.CenterFrequency,TransmitAntennas=txAntenna);
Stop Transmission
When ready, stop the transmission.
stopTransmission(ed);
Related Topics
- Connect and Set Up NI USRP Radios (Wireless Testbench)