%% Create 802.11ax System-Level Simulation with Full MAC and Abstracted PHY
% To access the helper files that this example uses, add the mlWLANSystemSimulation folder to the MATLAB path.

addpath(genpath(fullfile(pwd,'mlWLANSystemSimulation')));

% Set the simulation time in milliseconds.

simulationTime = 0.02*1e3;

% Specify the total number of nodes (APs and STAs) in the network. This example contains one AP and one STA.

numNodes = 2;

% Specify the x-, y-, and z-coordinates of the WLAN nodes in the Cartesian coordinate system. This example considers the first node as the AP and the second node as the STA.

nodePositions = [10 0 0; 20 0 0];

% Load the default configuration for the WLAN nodes.

load('wlanNodeConfig.mat');

% Copy the default configuration for all of the nodes.

nodeConfig = repmat(wlanNodeConfig,1,numNodes);

% Initialize the node position of the AP and STAs.

for index = 1:1:numNodes
    nodeConfig(index).NodePosition = nodePositions(index,:);
end

% Load the default application traffic configuration for the nodes.

load('wlanTrafficConfig.mat');

% Initialize the node with the traffic configuration by copying the default configuration.

trafficConfig = wlanTrafficConfig;

% Configure the uplink traffic at the AP from the STA. Node ID 1 represents the AP, whereas node ID 2 represents the STA.

trafficConfig(1).SourceNode = 2;                       % STA node ID
trafficConfig(1).DestinationNode = 1;                  % AP node ID

% Create WLAN nodes with the specified MAC, PHY, and application traffic configuration by using the hCreateWLANNodes helper function.  By default, the hCreateWLANNodes helper function configures abstracted MAC and PHY at each WLAN node.
% The hCreateWLANNodes helper function enables you to switch between abstracted and full MAC or PHY by configuring the MACFrameAbstraction and PHYAbstractionType input parameters. The valid values for these parameters are:
% MACFrameAbstraction: true or false
% PHYAbstractionType: ‘TGax Evaluation Methodology Appendix 1’ (default), ‘TGax Simulation Scenarios MAC Calibration’, or ‘None’
% If you set the PHYAbstractionType parameter to 'TGax Evaluation Methodology Appendix 1', 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, the 'TGax Simulation Scenarios MAC Calibration' value of PHYAbstractionType assumes a packet failure on interference without actually calculating the link performance. To use full PHY, set the value of PHYAbstractionType to 'None'.
% To use full MAC, set the value of MACFrameAbstraction to false. To use abstracted PHY, set the value of PHYAbstractionType to ‘TGax Evaluation Methodology Appendix 1’ or ‘TGax Simulation Scenarios MAC Calibration’. This example uses the PHY abstraction type as 'TGax Simulation Scenarios MAC Calibration'.

wlanNodes = hCreateWLANNodes(nodeConfig,trafficConfig, ...
    'MACFrameAbstraction',false, ...
    'PHYAbstractionType','TGax Simulation Scenarios MAC Calibration');

% At the end of the simulation, remove the mlWLANSystemSimulation folder from the path.

rmpath(genpath(fullfile(pwd,'mlWLANSystemSimulation')));

% Copyright 2021 The MathWorks, Inc.