主要内容

wirelessPacket

Create empty wireless packet structure

Since R2026a

    Description

    packet = wirelessPacket creates an empty wireless packet structure.

    This structure serves as a template for representing packets within the simulator. wnet.Node uses this packet in functions such as pullTransmittedPacket, pushReceivedPacket, and isPacketRelevant. By default, the structure does not contain any information. You must assign values to the fields of the structure using the syntax structure.field=value to define packet properties as needed for their simulation.

    Examples

    collapse all

    Create and use a wireless packet within a custom wireless node class. This class demonstrates how a node generates a packet, fills in key transmission details, and stores the packet for use in a network simulation.

    % CustomNode.m
    % Example MATLAB class: Demonstrates how a wireless node creates and uses a wireless packet structure.
    % This class simulates a simple wireless node that can transmit packets in a network simulation.
    
    classdef CustomNode < wnet.Node
        properties
            % IsTransmitter True if this node is a transmitter
            % Logical value. If true, node transmits packets.
            IsTransmitter = true
        end
    
        properties (SetAccess = private)
            % TransmitterBuffer Buffer that holds packet for transmission
             TransmitterBuffer
        end 
    
        methods
            function nextInvokeTime = run(node,currentTime)
                % run Run the custom node. Main method called by the wirelessNetworkSimulator at each time step.
                %   This custom node is a transmitter creating a wireless packet at each time step.
    
                if node.IsTransmitter
                    packet = wirelessPacket;
    
                    packet.TransmitterID = node.ID;
                    packet.TransmitterPosition = node.Position;
                    packet.TechnologyType = wnet.TechnologyType.Custom1;
                    packet.Power = 23;
                    packet.CenterFrequency = 2.4e9;
                    packet.Bandwidth = 20e6;
                    packet.SampleRate = 20e6;
                    packet.StartTime = currentTime;
                    packet.Duration = 0.1;
                    packet.NumTransmitAntennas = 1;
    
                    packet.Data = complex( ...
                        rand(packet.Duration*packet.SampleRate,packet.NumTransmitAntennas,"single"), ...
                        rand(packet.Duration*packet.SampleRate,1,"single"));
                    node.TransmitterBuffer = packet;
                end
    
                nextInvokeTime = currentTime + 1;
            end
    
            function packet = pullTransmittedPacket(node)
                % pullTransmittedPacket Retrieve the packet ready for transmission
                packet = node.TransmitterBuffer;
                node.TransmitterBuffer = [];
            end
        end
    end

    Output Arguments

    collapse all

    Wireless packet, returned as a structure. The structure packet contains these fields:

    Field NameDescription
    TechnologyType

    Technology type of the packet. This field identifies the technology associated with the packet. Accepted values are the constants present in wnet.TechnologyType. The default value is 0, indicating an invalid packet.

    TransmitterID

    Transmitter node identifier. The value of this field must be a positive integer. The default value is [], which leaves the field undefined. You must always set this field to a positive integer.

    TransmitterPosition

    Position of the transmitter. The value of this field must be a real-valued vector representing Cartesian x-, y-, and z- coordinates in meters. The default value is [], which leaves the field undefined. You must always set this field to a real-valued vector.

    TransmitterVelocity

    Velocity of the transmitter in the x-, y-, and z-directions. The value of this field must be a real-valued vector of the form [vx vy vz], in meters per second. The default value is [0 0 0], which indicates no mobility.

    NumTransmitAntennas

    Number of antennas at the transmitter. The value of this field must be a positive integer. The default value is [], which leaves the field undefined. You must always set this field to a positive integer.

    StartTime

    Packet transmission start time at the transmitter, or packet arrival time at the receiver. Units are in seconds. The default value is [], which leaves the field undefined. You must always set this field.

    Duration

    Duration of the packet. Units are in seconds. The default value is [], which leaves the field undefined. You must always set this field.

    Power

    Power of the packet. Units are in dBm. The default value is [], which leaves the field undefined. You must always set this field.

    CenterFrequency

    Center frequency of the carrier. Units are in Hz. The default value is [], which leaves the field undefined. You must always set this field.

    Bandwidth

    Carrier bandwidth. Units are in Hz. This value is the bandwidth around the center frequency. The default value is [], which leaves the field undefined. You must always set this field.

    Abstraction

    Abstraction type. The value of this field is a logical 1 (true) or 0 (false). A value of true indicates an abstracted physical layer (PHY), while false indicates a full PHY. The default value is false.

    SampleRate

    Sample rate of the signal transmitted in the Data field, in samples per second. This field is applicable only when the value of the Abstraction field is false. The default value is [], which leaves the field undefined. You must always set this field.

    DirectToDestination

    Flag that controls whether to apply the channel. The value of this field must be one of the following options.

    • 0 — Applies a channel model to the packet.

    • Positive integer — Does not apply a channel model to the packet. The value specifies the destination node ID. The node sends a special packet directly to this node, bypassing the channel.

    The default value is 0.

    Data

    Time samples (for full PHY) or frame information (for abstracted PHY). If Abstraction is false, this field contains the time-domain samples of the packet, represented as a T-by-R matrix of complex values, where T is the number of time-domain in-phase and quadrature (IQ) samples and R is the number of transmitter antennas (for a transmitted packet) or receiver antennas (for a received packet). When Abstraction is true, this field contains standard-specific information organized as a structure with the necessary fields.

    The default value is [], which leaves the field undefined. You must always set this field.

    Metadata

    Information about the technology, abstraction, and channel of the packet, represented as a structure. The structure contains this field:

    • Channel — Channel information, represented with these fields:

      • PathGains— Complex path gains at each snapshot in time, represented as an array of size Ncs-by-Np-by-Nt-by-Nr. The default value is [].

      • PathDelays — Delays, in seconds, for each path, represented as a vector of size 1-by-Np. The default value is [].

      • PathFilters — Filter coefficients for each path, represented as a matrix of size Np-by-Nf. The default value is [].

      • SampleTimes — Simulation time, in seconds, for each path gain snapshot, represented as a vector of size Ncs-by-1. The default value is [].

      Ncs, Np, Nt, Nr, and Nf represent the number of channel snapshots, paths, transmit antennas, receive antennas, and filter coefficients, respectively.

      Note that the default Free Space Path Loss (FSPL) channel model in the simulator update these fields:

      • Power — Includes large-scale effects.

      • Data — Includes small and large-scale effects by scaling the data if the value of Abstraction is false.

      • Metadata.Channel — Includes update about channel information such as PathGains, PathDelays, PathFilters and SampleTimes.

      • Duration — Includes the final transient in the calculation of the duration of the channel-impaired packet. The final transient equals delay spread + filter length – implementation delay, and the resulting channel-impaired packet equals the actual packet duration + the final transient. Updating this field is optional.

      For custom channels, you must update these fields.

      In addition to the Channel field, the Metadata structure can include additional fields for custom information.

    Tags

    Optional information, represented as an array of structures, where each structure contains these fields:

    • Name — Name of the tag. The value of this specified a character vector or string scalar.

    • Value — Data associated with the tag. The value of this field can be of any data type.

    • ByteRange — Specific range of bytes within the packet to which the tag applies. The value of this field must be a two-element vector of integers.

    Note

    The Tags field can contain any optional information about the whole packet or about a sequence of contiguous bytes of the packet, as indicated by ByteRange. The default value is[], which indicates that the Tags field does not contain any information.

    Data Types: struct

    Version History

    Introduced in R2026a

    See Also

    Classes