Main Content


Calculate MSDU lengths



msduLengths = wlanMSDULengths(frameLength,macConfig) returns msduLengths, a vector of medium access control (MAC) service data unit (MSDU) lengths for the specified MAC frame length and configuration. The function calculates the MSDU lengths by removing the overhead of MAC headers, frame check sequence (FCS), and subframe overheads (if applicable).


msduLengths = wlanMSDULengths(frameLength,macConfig,phyConfig) returns MSDU lengths for the specified physical layer (PHY) format configuration object. Use this syntax to return MSDU lengths for aggregate MAC protocol data units (A-MPDUs).


collapse all

Generate a QoS Data frame of length 2000 octets.

Create a WLAN MAC frame configuration object.

macConfig = wlanMACFrameConfig('FrameType','QoS Data');

Calculate the MSDU lengths required to generate a 2000-octet QoS Data frame and display the result.

frameLength = 2000;
msduLengths = wlanMSDULengths(frameLength,macConfig);

Create a random payload of the obtained MSDU length.

msdu = randi([0 255],1,msduLengths);

Generate the 2000-octet QoS data frame.

[frame,frameLength] = wlanMACFrame(msdu,macConfig);

Create a MAC frame configuration object.

 cfgMAC = wlanMACFrameConfig(FrameType="QoS Data", ...
     FrameFormat="HT-Mixed", ...

Create an HT PHY configuration object.

cfgPHY = wlanHTConfig(MCS=4);  

Calculate the MSDU lengths required to generate a 5000-octet A-MPDU frame, displaying the result.

msduLengths = wlanMSDULengths(5000,cfgMAC,cfgPHY);
        2302        2302         294

Create MSDUs with random data using the MSDU length vector.

 numMSDUs = numel(msduLengths);
 payload = cell(1,numMSDUs);
  for i = 1:numMSDUs
      payload{i} = randi([0 255],1,msduLengths(i));

Generate the 5000-octet A-MPDU.

[frame,frameLength] = wlanMACFrame(payload,cfgMAC,cfgPHY);

Input Arguments

collapse all

Total length of the MAC frame, specified as an integer in the interval [28, 6,500,631].


The maximum value of this input depends on the MAC and PHY configuration in accordance with Table 9-25 of [2].

For MAC frames in very-high-throughput (VHT) or high-efficiency (HE) format, this input is the A-MPDU pre-end-of-frame padding (APEP) length. For all other formats, this input is the physical layer convergence procedure (PLCP) service data unit PSDU length.


APEP length is always a multiple of four octets due to final subframe padding. If you do not specify this argument as a multiple of four octets for VHT- or HE-format frames, the function rounds the value to the nearest multiple of four.

Data Types: double

MAC frame configuration, specified as a wlanMACFrameConfig object. This object defines the type of MAC frame and its applicable properties.

PHY format configuration, specified as a configuration object of type wlanHESUConfig, wlanVHTConfig, or wlanHTConfig. The value you specify must be compatible with the frame format specified in the macConfig input.

  • If the FrameFormat property of macConfig is 'HE-SU' or 'HE-EXT-SU', then you must specify this argument as a wlanHESUConfig object.

  • If the FrameFormat property of macConfig is 'VHT', then you must specify this argument as a wlanVHTConfig object.

  • If the FrameFormat property of macConfig is 'HT-Mixed', then you must specify this argument as a wlanHTConfig object.

Specify this argument to:

  • Ensure that the frame does not exceed the transmission time limit.

  • Add end-of-frame (EOF) padding to VHT- or HE-format frames.

  • Maintain minimum start spacing between MPDUs in an A-MPDU.

Output Arguments

collapse all

MSDU lengths, returned as a vector of integers. The number of elements in this vector corresponds to the number of MSDUs. Each element is the length of its corresponding MSDU.

Data Types: double


[1] IEEE Std 802.11™-2020 (Revision of IEEE Std 802.11-2016). “Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications.” IEEE Standard for Information Technology — Telecommunications and Information Exchange between Systems— Local and Metropolitan Area Networks — Specific Requirements.

[2] IEEE Std 802.11ax™-2021 (Amendment to IEEE Std 802.11-2020). “Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications. Amendment 1: Enhancements for High Efficiency WLAN.” IEEE Standard for Information technology — Telecommunications and information exchange between systems. Local and metropolitan area networks — Specific requirements.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2018b