run
Download Required: To use run
,
first download the Communications Toolbox Wireless Network Simulation Library add-on.
Description
run(
runs the wireless network simulation for the specified simulation time duration. If any
action is scheduled at a particular simulation time, the networkSimulator
,simDuration
)run
function performs the scheduled action. Use the scheduleAction
function to schedule an action to be performed during the simulation process.
You must call the run
function only once after initializing
the wirelessNetworkSimulator
object.
Examples
Simulate Bluetooth BR Network with Default Channel Effects
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);
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]
Schedule Action to Perform During Network Simulation
Simulate Bluetooth BR Network
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]);
Schedule Action
Create a custom function displayInfo
to define the actions for the simulator to perform during simulation. You can define an one time action, periodic action, and action when simulator advances in time. The input data for the custom function is stored as a structure and passed using the scheduleAction
function.
A) Schedule One Time Action
For the one time action, the displayInfo
function displays the details of the nodes in the network.
Specify the ActionType
input argument value of displayInfo
function as "OneTime"
. Specify the names of the nodes in the network as input to displayInfo
function.
userdata = struct( ... ActionType="OneTime", ... Nodes=[centralNode peripheralNode]);
Configure the simulator by using the scheduleAction
function to display the node details when the simulation time is 0.001s.
startTime = 0.001; scheduleAction(networkSimulator,@displayInfo,userdata,startTime);
B) Schedule Periodic Action
For the periodic action, the displayInfo
function displays the physical layer statistics of the central node in the Bluetooth BR network.
Specify the ActionType
input argument value of displayInfo
function as "Periodic"
. Specify the central node and the simulator as inputs to displayInfo
function.
userdata = struct( ... ActionType="Periodic", ... CentralNode=centralNode, ... Simulator=networkSimulator);
Configure the simulator by using the scheduleAction
function to display the physical layer statistics of the central node at a time interval of 0.002s starting from the beginning of the simulation.
startTime = 0;
periodicity = 0.002;
scheduleAction( ...
networkSimulator,@displayInfo,userdata,startTime,periodicity);
C) Schedule Action When Simulator Advances in Time
When the simulator advances in time, the displayInfo
function displays the next event time of the simulator.
Specify the ActionType
input argument value of displayInfo
function as "TimeAdvance"
. Specify the simulator as input to the displayInfo
function.
userdata = struct( ... ActionType="TimeAdvance", ... Simulator=networkSimulator);
Set the periodicity value to 0. Configure the simulator by using the scheduleAction
function to display the time of the next event.
startTime = 0;
periodicity = 0;
scheduleAction( ...
networkSimulator,@displayInfo,userdata,startTime,periodicity);
Run Simulation
Specify the simulation time in seconds.
simulationTime = 0.003;
Run the simulation for the specified simulation time.
run(networkSimulator,simulationTime);
-------Periodic Action ------- Statistics of Node1 at time 0.000 seconds: ReceivedPackets: 0 DecodeFailures: 0 PacketCollisions: 0 CoChannelCollisions: 0 CollisionsWithBREDR: 0 CollisionsWithNonBREDR: 0 CollisionsWithBREDRAndNonBREDR: 0 TransmittedPackets: 1 TransmittedBits: 366 -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00037 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00063 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00075 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00100 seconds -------End------- -------One Time Action ------- Node details: Name: Node1 ID: 1 Role: central Name: Node2 ID: 2 Role: peripheral -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00108 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00125 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00162 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00187 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00200 seconds -------End------- -------Periodic Action ------- Statistics of Node1 at time 0.002 seconds: ReceivedPackets: 2 DecodeFailures: 0 PacketCollisions: 0 CoChannelCollisions: 0 CollisionsWithBREDR: 0 CollisionsWithNonBREDR: 0 CollisionsWithBREDRAndNonBREDR: 0 TransmittedPackets: 2 TransmittedBits: 732 -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00200 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00216 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00250 seconds -------End------- -------Action When Simulator Advances in Time------- Simulator next event time is at 0.00287 seconds -------End-------
function displayInfo(~,userdata) switch(userdata.ActionType) case "Periodic" fprintf("-------Periodic Action -------\n") fprintf("Statistics of %s at time %.3f seconds:\n", ... userdata.CentralNode.Name, ... userdata.Simulator.CurrentTime); stats = statistics(userdata.CentralNode); disp(stats.PHY) fprintf("-------End-------\n") case "OneTime" fprintf("-------One Time Action -------\n") fprintf("Node details:\n") for idx=1:numel(userdata.Nodes) fprintf("Name: %s ID: %d Role: %s\n", ... userdata.Nodes(idx).Name, ... userdata.Nodes(idx).ID, ... userdata.Nodes(idx).Role) end fprintf("-------End-------\n") case "TimeAdvance" fprintf("-------Action When Simulator Advances in Time-------\n") fprintf("Simulator next event time is at %.5f seconds\n", ... userdata.Simulator.CurrentTime) fprintf("-------End-------\n") end end
Input Arguments
networkSimulator
— Wireless network simulator
wirelessNetworkSimulator
object
Wireless network simulator, specified as a wirelessNetworkSimulator
object.
simDuration
— Duration of simulation
positive scalar
Duration of simulation, specified as a positive scalar. Units are in seconds. The
function rounds simDuration
to the nearest nanosecond.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
Version History
Introduced in R2022bR2023a: Moved to Communications Toolbox Wireless Network Simulation Library from Bluetooth Toolbox
Previously, this wirelessNetworkSimulator
object function required Bluetooth® Toolbox.
See Also
Objects
Functions
Topics
- Create, Configure, and Simulate Bluetooth BR/EDR Piconet (Bluetooth Toolbox)
- Bluetooth BR/EDR Data and Voice Communication with WLAN Signal Interference (Bluetooth Toolbox)
- Simulate Multiple Bluetooth BR/EDR Piconets with ACL Traffic (Bluetooth Toolbox)
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)