Main Content

wirelessNetworkSimulator

Wireless network simulator

Since R2022b

    Download Required: To use wirelessNetworkSimulator, first download the Communications Toolbox Wireless Network Simulation Library add-on.

    Description

    The wirelessNetworkSimulator object simulates different wireless network scenarios with different types of wireless nodes. Use the Object Functions to add nodes to the simulator, interact with the nodes, schedule actions to perform during simulation, plug in custom channel models, and run simulations.

    Creation

    Description

    example

    networkSimulator = wirelessNetworkSimulator.init() creates a wirelessNetworkSimulator object with default property values. If the wirelessNetworkSimulator object networkSimulator already exists in the MATLAB® workspace, the function resets the object to its default state.

    Properties

    expand all

    This property is read-only.

    Current simulation time, stored as a non-negative scalar. Units are in seconds.

    Data Types: double

    This property is read-only.

    Channel model, stored as a function handle. By default, the simulator uses the fspl function to model the channel. To specify a custom channel model, use the addChannelModel function.

    Data Types: function_handle

    This property is read-only.

    Simulation end time, stored as a non-negative scalar. Units are in seconds.

    Data Types: double

    Object Functions

    wirelessNetworkSimulator.getInstanceGet instance of wirelessNetworkSimulator object
    addNodesAdd nodes to simulation
    addChannelModelAdd custom channel or path loss model
    scheduleActionSchedule action to perform during simulation
    cancelActionCancel scheduled action
    runRun simulation

    Examples

    collapse all

    Create a wirelessNetworkSimulator object by using the wirelessNetworkSimulator.init() function. By default, the wirelessNetworkSimulator object applies free-space path loss model for the channel effects.

    networkSimulator = wirelessNetworkSimulator.init();

    Create two Bluetooth BR nodes, one with the "central" role and other with the "peripheral" role. Specify the position of the Peripheral node in meters.

    centralNode = bluetoothNode("central");
    peripheralNode = bluetoothNode("peripheral",Position=[1 0 0]);

    Create a default Bluetooth BR connection configuration object to configure and share a connection between Bluetooth BR Central and Peripheral nodes.

    cfgConnection = bluetoothConnectionConfig;

    Configure connection between the Central and the Peripheral nodes.

    connection = configureConnection( ...
        cfgConnection,centralNode,peripheralNode);

    Create and configure a networkTrafficOnOff object to generate an On-Off application traffic pattern.

    traffic = networkTrafficOnOff( ...
        DataRate=200, ...
        PacketSize=27, ...
        GeneratePacket=true, ...
        OnTime=inf);

    Add application traffic from the Central to the Peripheral node.

    addTrafficSource(centralNode,traffic, ...
        DestinationNode=peripheralNode);

    Add the Central and Peripheral nodes to the wireless network simulator.

    addNodes(networkSimulator,[centralNode peripheralNode]);

    Specify the simulation time in seconds.

    simulationTime = 0.05;

    Run the simulation for the specified simulation time.

    run(networkSimulator,simulationTime);
    Custom channel model is not added. Using free space path loss (fspl) model as the default channel model.
    

    Retrieve application, baseband, and physical layer (PHY) statistics corresponding to the Central and Peripheral nodes.

    centralStats = statistics(centralNode)
    centralStats = struct with fields:
            Name: "Node1"
              ID: 1
             App: [1x1 struct]
        Baseband: [1x1 struct]
             PHY: [1x1 struct]
    
    
    peripheralStats = statistics(peripheralNode)
    peripheralStats = struct with fields:
            Name: "Node2"
              ID: 2
             App: [1x1 struct]
        Baseband: [1x1 struct]
             PHY: [1x1 struct]
    
    

    Create a wirelessNetworkSimulator object.

    networkSimulator = wirelessNetworkSimulator.init();

    Create two Bluetooth BR nodes, one with the "central" role and other with the "peripheral" role. Specify the position of the Peripheral node in meters.

    centralNode = bluetoothNode("central");
    peripheralNode = bluetoothNode("peripheral",Position=[1 0 0]);

    Create a default Bluetooth BR connection configuration object to configure and share a connection between Bluetooth BR Central and Peripheral nodes.

    cfgConnection = bluetoothConnectionConfig;

    Configure connection between the Central and the Peripheral nodes.

    connection = configureConnection(cfgConnection,centralNode,peripheralNode);

    Create and configure a networkTrafficOnOff object to generate an On-Off application traffic pattern.

    traffic = networkTrafficOnOff(DataRate=200,PacketSize=27, ...
        GeneratePacket=true,OnTime=inf);

    Add application traffic from the Central to the Peripheral node.

    addTrafficSource(centralNode,traffic, ...
        DestinationNode=peripheralNode);

    Add the Central and Peripheral nodes to the wireless network simulator.

    addNodes(networkSimulator,[centralNode peripheralNode]);

    By default, the wirelessNetworkSimulator object applies free-space path loss model for the channel effects. You can add custom channel effects by using the addChannelModel function. However, to model the channel without any channel effects, specify a custom MATLAB™ function, removeChannelEffect, in which the input transmitted packets are returned at the output without any changes.

    addChannelModel(networkSimulator,@removeChannelEffect);

    Specify the simulation time in seconds.

    simulationTime = 0.05;

    Run the simulation for the specified simulation time.

    run(networkSimulator,simulationTime);

    Retrieve application, baseband, and physical layer (PHY) statistics corresponding to the Central and Peripheral nodes.

    centralStats = statistics(centralNode)
    centralStats = struct with fields:
            Name: "Node1"
              ID: 1
             App: [1x1 struct]
        Baseband: [1x1 struct]
             PHY: [1x1 struct]
    
    
    peripheralStats = statistics(peripheralNode)
    peripheralStats = struct with fields:
            Name: "Node2"
              ID: 2
             App: [1x1 struct]
        Baseband: [1x1 struct]
             PHY: [1x1 struct]
    
    
    function outputData = removeChannelEffect(~,txData)
    outputData = txData;
    end

    Version History

    Introduced in R2022b

    expand all