Get Started with WLAN System-Level Simulation in MATLAB
This example shows how to model a WLAN network consisting of an IEEE® 802.11ax™  access point (AP) and a station (STA) by using WLAN Toolbox™ and the Communications Toolbox™ Wireless Network Simulation Library.
Using this example, you can:
Simulate a multinode WLAN system by configuring the application layer (APP), medium access control (MAC), and physical layer (PHY) parameters at each node.
Model uplink and downlink communication between an AP and a STA.
Switch between the abstracted and full models of MAC and PHY layers.
Visualize the time spent by each node in Idle, Contention, Transmission, and Reception state.
Capture the APP, MAC, and PHY statistics for each node.
The simulation results show performance metrics such as throughput, latency, and packet loss.
Additionally, you can use this example script to generate, configure and add external application traffic patterns such as On-Off, Video, Voice, and FTP to the WLAN nodes. For more information, see Further Exploration.
WLAN System-Level Simulation
This example shows you how to model a WLAN network with uplink and downlink communication between an AP and a STA. This figure illustrates the example network.
This figure shows the example workflow.
To confirm compliance with the IEEE 802.11 standard , the features in this example are validated with Box-3 and Box-5 scenarios specified in the TGax evaluation methodology . The network throughputs that are calculated for TGax simulation scenarios  are validated against the published calibration results from the TGax Task Group.
Check for Support Package Installation
Check if the Communications Toolbox™ Wireless Network Simulation Library support package is installed. If the support package is not installed, MATLAB® returns an error with a link to download and install the support package.
Configure Simulation Parameters
Set the seed for the random number generator to
1. The seed value controls the pattern of random number generation. The random number generated by the seed value impacts several processes within the simulation, including backoff counter selection at the MAC layer and predicting packet reception success at the physical layer. To improve the accuracy of your simulation results after running the simulation, you can change the seed value, run the simulation again, and average the results over multiple simulations.
Specify the simulation time in seconds. To visualize a live state transition plot for all of the nodes, set the
showLiveStateTransitionPlot variable to
simulationTime = 1; showLiveStateTransitionPlot = true;
At the transmitter and receiver, modeling full MAC processing involves complete MAC frame generation at the MAC layer. Similarly, modeling full PHY processing involves complete operations related to waveform transmission and reception through a fading channel. When simulating large networks, full MAC and PHY processing is computationally expensive.
In the abstracted MAC, the node does not generate or decode any frames at the MAC layer. Similarly, in the abstracted PHY, the node does not generate or decode any waveforms at the PHY. MAC and PHY abstraction enable you to minimize the complexity and runtime of system-level simulations. For more information on PHY abstraction, see the Physical Layer Abstraction for System-Level Simulation example.
This table shows you how to switch between the abstracted and full MAC or PHY by configuring the values of the
PHYAbstractionMethod properties of
If you set the
tgax-evaluation-methodology, the PHY estimates the performance of a link with the TGax channel model by using an effective signal-to-interference-plus-noise ratio (SINR) mapping. Alternatively, if you set the
tgax-mac-calibration the PHY assumes a packet failure on interference without actually calculating the link performance. To use the full PHY, set the value of
MACFrameAbstraction = false; PHYAbstractionMethod = "tgax-evaluation-methodology";
Configure WLAN Scenario
Initialize the wireless network simulator by using the
networkSimulator = wirelessNetworkSimulator.init;
wlanDeviceConfig object enables you to set the configuration parameters for the AP and STA. Create two WLAN device configuration objects, one for the AP and the other for the STA. Specify the operating mode, modulation and coding scheme, and transmission power (in dBm) for the AP and STA.
accessPointCfg = wlanDeviceConfig(Mode="AP",MCS=2,TransmitPower=15); % AP device configuration stationCfg = wlanDeviceConfig(Mode="STA",MCS=2,TransmitPower=15); % STA device configuration
To create an AP node and a STA node from the specified WLAN device configurations, use
wlanNode objects. Specify the name and position of the AP and the STA. Specify the PHY abstraction method used for the AP and the STA. Configure the
MACFrameAbstraction property of the
wlanNode object to indicate if the MAC frames are abstracted by the nodes.
accessPoint = wlanNode(Name="AP", ... Position=[10 0 0], ... DeviceConfig=accessPointCfg, ... PHYAbstractionMethod=PHYAbstractionMethod, ... MACFrameAbstraction=MACFrameAbstraction); station = wlanNode(Name="STA", ... Position=[20 0 0], ... DeviceConfig=stationCfg, ... PHYAbstractionMethod=PHYAbstractionMethod, ... MACFrameAbstraction=MACFrameAbstraction);
Create a WLAN network consisting of the AP and the STA.
nodes = [accessPoint station];
To ensure all the nodes are configured properly, use the
hCheckWLANNodesConfiguration helper function.
Association and Application Traffic
Associate the STA to the AP by using the
associateStations object function of the wlanNode object. To configure uplink and downlink application traffic between the AP and STA, use the
FullBufferTraffic argument of the
associateStations object function.
To model a random TGax fading channel between each node, this example uses the
hSLSTGaxMultiFrequencySystemChannel helper object. Add the channel model to the wireless network simulator by using the
addChannelModel object function of the
channel = hSLSTGaxMultiFrequencySystemChannel(nodes); addChannelModel(networkSimulator,channel.ChannelFcn)
Export WLAN MAC Frames to PCAP or PCAPNG File
The example demonstrates packet capture at both AP and STA nodes. Set the
capturePacketsFlag flag to
true to capture the packets exchanged during the simulation. The packet capture (PCAP) or packet capture next generation (PCAPNG) file (.pcap or .pcapng, respectively) is a widely used packet capture file format to perform packet analysis. The packets are captured into a PCAP file in this example.
capturePacketsFlag = true;
hExportWLANPackets helper object to generate PCAP files. Specify the node objects at which you want to capture the packets. The helper object captures transmitted and received packets at each of these nodes and generates a PCAP file for each node. If you want to capture the packets in a PCAPNG file, specify the string "pcapng" as the second argument to the object function call. Note that capturing packets is possible only when
MACFrameAbstraction flag is set to
if capturePacketsFlag clear capturePacketsObj; % Clear existing helper object capturePacketsObj = hExportWLANPackets(nodes); end
You can visualize and analyze the PCAP or PCAPNG file by using a third-party packet analyzer tool such as Wireshark.
Add your nodes to the wireless network simulator.
To view the state transition and performance metrics plots, create a
hSimulationPlotViewer helper object. The simulation shows the plots for all the nodes configured in the simulation. To visualize the state transitions and performance metrics of a specific node, specify the corresponding node object as the second argument to the helper object.
viewerObj = hSimulationPlotViewer(showLiveStateTransitionPlot,nodes);
Run the network simulation for the specified simulation time. The runtime visualization shows the time spent by the AP and the STA in Idle, Contention, Transmission, and Reception state.
Retrieve the APP, MAC, and PHY statistics at each node by using the
statistics object function of the
stats = statistics(nodes);
Plot the performance of each node by using the p
lotNetworkStats object function of the
hSimulationPlotViewer object. You can visualize these simulation plots.
Throughput (in Mbps) at each transmitter (AP and STA).
Packet loss ratio (ratio of unsuccessful data transmissions to the total data transmissions) at each transmitter (AP and STA).
Average packet latency incurred at each receiver (AP and STA). The average packet latency shows the average latency that the STA incurs to receive the downlink traffic from the AP and the average latency that the AP incurs to receive uplink traffic from the STA.
hExportWLANPackets helper object does not overwrite the existing PCAP or PCAPNG file, deleting the PCAP objects used in this simulation.
if capturePacketsFlag delete(capturePacketsObj.PCAPObjList); end
Configure External Application Traffic
To generate and add external application traffic pattern (On-Off, Video, Voice, and FTP) to the WLAN nodes, modify the traffic configuration in this example. To generate an On-Off application traffic, create two
networkTrafficOnOff objects for downlink and uplink traffic, respectively. Configure these objects by specifying the application data rate and packet size.
% trafficSourceDL = networkTrafficOnOff(DataRate=100000,PacketSize=1500); % trafficSourceUL = networkTrafficOnOff(DataRate=100000,PacketSize=1500);
Attach downlink application traffic from the AP node to the STA node by using the
addTrafficSource object function of the
wlanNode object. Similarly, attach uplink application traffic from the STA node to the AP node.
% addTrafficSource(accessPoint,trafficSourceDL,DestinationNode=station,AccessCategory=0); % addTrafficSource(station,trafficSourceUL,DestinationNode=accessPoint,AccessCategory=0);
To generate video, voice, and FTP application traffic, use the
networkTrafficFTP objects, respectively
This example uses these helpers:
hCheckWLANNodesConfiguration— Check if the node parameters are configured correctly
hExportWLANPackets— Capture MAC frames and write them into a PCAP/PCAPNG file
hSLSTGaxMultiFrequencySystemChannel— Return a system channel object
hSLSTGaxAbstractSystemChannel— Return a channel object for abstracted PHY layer
hSLSTGaxSystemChannel— Return a channel object for full PHY layer
hSLSTGaxSystemChannelBase— Return the base channel object
hSimulationPlotViewer— Plot the state transition and performance metrics figures
Institute of Electrical and Electronics Engineers (IEEE). IEEE Standard for Information Technology--Telecommunications and Information Exchange between Systems Local and Metropolitan Area Networks--Specific Requirements Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications Amendment 1: Enhancements for High-Efficiency WLAN. IEEE 802.11ax-2021. IEEE, May 19, 2021. https://doi.org/10.1109/IEEESTD.2021.9442429.
Institute of Electrical and Electronics Engineers (IEEE). IEEE Standard for Information Technology--Telecommunications and Information Exchange between Systems Local and Metropolitan Area Networks--Specific Requirements Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications. IEEE 802.11-2020. IEEE, February 26, 2021. https://doi.org/10.1109/IEEESTD.2021.9363693.
Institute of Electrical and Electronics Engineers (IEEE). 11ax Evaluation Methodology. IEEE 802.11-14/0571r12. IEEE, January 2016.
Institute of Electrical and Electronics Engineers (IEEE). TGax Simulation Scenarios. IEEE 802.11-14/0980r16. IEEE, 2015.