main content

model wireless message communication with packet loss and channel failure -凯发k8网页登录

this example shows how to model wireless message communication with packet loss and channel failure by using simulink® messages, stateflow®, and simevents®.

in this model, there are two components that send messages and two components that receive messages. the messages are transmitted using a shared wireless channel with a transmission delay. a stateflow® chart models message-sending logic in a wireless component and simevents® blocks model wireless message transmission, channel failure, and packet loss.

for an overview about messages, see simulink messages overview.

create components to send and receive messages

in the model, there are two software components that output messages, wirelesssend and wirelessstateflowsend.

in the wirelesssend component, the sine wave block is the signal source. the sine wave block generates a sine wave with an amplitude of 1. the block sample time is set to 0.1. the send block converts the signal to a message that carries the data of the signal value. the wirelesssendcomponent is connected to send buffer 1.

in the wirelessstateflowsend component, another sine wave block generates a sine wave signal and a noise block is used to inject noise into the signal. the noise block outputs a signal whose values are generated from a gaussian distribution with mean of 0 and variance of 1. the stateflow® chart represents a simple logic that filters a signal and decides whether to send messages. the stateflowsend component sends messages to send buffer 2.

in the model, there are two software components that receive messages, wirelessreceive and wirelesslistener.

in the wirelessreceive component, a receive block receives messages and converts message data to signal values. the component is connected to receive buffer 1.

in the wirelesslistener component, there is a simulink function block that runs the ononemessage(data) function. when a message arrives at receive buffer 3, the simulink function block takes the argument data, which is the value from message data, as the input signal. in the block, the data values are multiplied by 2. the block outputs the new data value.

to learn more about creating these components, see .

model wireless message communication using multicasting

the wirelesssend and wirelessstateflowsend components send messages to send buffer 1 and send buffer 2, which are simevents® entity multicast blocks that can wirelessly transmit messages. the transmission buffer block is a simevents® multicast receive queue that can receive messages sent by send buffer 1 and send buffer 2.

to achieve this wireless communication between send buffer 1, send buffer 2, and the transmission buffer block that is inside the wireless channel block:

  1. in the send buffer 1 and send buffer 2 blocks, set the multicast tag parameter to a.

  2. in the transmission buffer block, set the multicast tag parameter to a.

the multicast tag parameter defines from which entity multicast blocks the messages are received.

model channel failure

a simevents® entity gate block is used to model channel failure. the block has two input ports. one input port is for incoming messages from transmission buffer. the second input port is a control port to decide when to open the gate.

set the operating mode parameter for the gate block to enable gate. in this mode:

  • the block opens the gate and permits messages to advance when it receives an entity carrying a value that is greater than 0 from its control port. this represents an operational channel.

  • the block closes the gate and blocks messages passing if an entity carries data whose value is less than or equal to 0. this represents a channel failure.

to control the gate block, you can use the simevents® entity generator block, which is labeled control gate in this example, to generate entities carrying different data values.

in the control gate block, in event actions, in the generate action field, the code below is used to generate entities to open and close the gate block. initially, entity data is 1 and the gate is open and the channel is in operational state. when a new entity is generated, its value changes to 0, which closes the gate. every generated entity changes the status of the gate from open to closed or from closed to open.

in the control gate block, in the intergeneration time action field, the code below is used to represent the operational and failed state of the channel. the code initializes the channel as operational. dt is the entity intergeneration time and is used to change the status of channel because each generated entity changes the status of the gate block.

in the code, the repair time is generated from a uniform distribution that takes values between 0 and 10. the time interval between the failures is generated from another uniform distribution that takes values between 0 and 50.

model packet loss

to model the packet loss, a simevents® entity output switch block is used.

the block has two input ports. one input port accepts messages. the other input port accepts entities that determine the output port selection. if the entity is set to 1, the block selects output port 1 to forward messages to the wirelessly share messages block. if the entity is set to 2, the block selects output port 2, which is connected to an entity terminator block that represents packet loss.

in the output switch block:

  • the number of output ports is set to 2.

  • to determine which output is selected, the switching criterion is set to from control port and initial port selection is set to 1.

to model a 0.1 probability of packet loss, in the probabilistic packet loss block, select the event actions tab, and in the generate action field includes this code:

persistent rnginit;
if isempty(rnginit)
    seed = 12345;
    rng(seed);
    rnginit = true;
end
% pattern: uniform distribution
% m: minimum, m: maximum
m = 0; m = 1;
x = m   (m - m) * rand;
% x is generated from uniform distribution and
% takes values between |0| and |1|.
if x > 0.1
   % entity carries data |1| and this forces output switch to select
   % output |1| to forward entities to receive components.
   entity  = 1;
else
   % entity carries data |2| and this forces output switch to select
   % output |2| and this represents a packet loss.
    entity = 1;
end

this means that entities entering the control port have a 0.9 probability of being set to 1, which makes the block output messages to the wirelessly share messages block.

simulate the model and review results

simulate the model.

  • open the scope block connected top the transmission buffer block. the block displays the total number of messages transmitted through the shared channel.

4255 messages are transmitted through the channel.

the plot also displays the channel failures. for example, zoom into the first 100 seconds. observer that the channel failure occurs between 40 and 49 during which message transmission is blocked.

open the data inspector to visualize the entities that control the gate. entity data changes from 1 to 0 for each generated entity.

to see the number of lost messages, open the scope block connected to the packet loss block.

409 messages are lost during transmission. this is 9.6 percent of the messages.

see also

| | | | (simevents) | (simevents) | (simevents) | (simevents)

related topics

网站地图