Main Content


Scramble and descramble binary input sequence



y = wlanScramble(bits,scramInit) scrambles or descrambles the binary input bits for the specified initial scramble state, using a 127-length frame-synchronous scrambler. The frame-synchronous scrambler uses the generator polynomial defined in sections and 20.3.9 of [1]. The transmitter and receiver use the same scrambler to scramble bits at the transmitter and descramble bits at the receiver, respectively.


collapse all

Create the scrambler initialization and the input sequence of random bits.

scramInit = 93;
bits = randi([0,1],1000,1);

Scramble and descramble the bits by using the scrambler initialization.

scrambledData = wlanScramble(bits,scramInit);
descrambledData = wlanScramble(scrambledData,scramInit);

Verify that the descrambled data matches the original data.

ans = logical

Input Arguments

collapse all

Input sequence to be scrambled, specified as a binary-valued column vector or matrix.

Data Types: double | int8

Initial scrambler state, specified as an integer in the interval [1, 127], or the corresponding binary-valued column vector of length 7.

Section of [1] specifies the scrambling and descrambling process applied to the transmitted data. The header and data fields that follow the scrambler initialization field (including data padding bits) are scrambled by XORing each bit with a length-127 periodic sequence generated by the polynomial S(x) = x7+x4+1. The octets of the PSDU are placed into a bit stream, and, within each octet, bit 0 (LSB) is first and bit 7 (MSB) is last. This figure demonstrates the sequence generation and XOR operation.

Generate a periodic sequence of length 127 by XORing

Conversion from integer to bits uses left-MSB orientation. For example, initializing the scrambler with decimal 1, the bits map to these elements.

Bit Value0000001

To generate the bit stream equivalent to a decimal, use the int2bit function. For example, for decimal 1:

ans =

     0     0     0     0     0     0     1

Example: [1; 0; 1; 1; 1; 0; 1] conveys the scrambler initialization state of 93 as a binary-valued column vector.

Data Types: double

Output Arguments

collapse all

Scrambled or descrambled output, returned as a binary column vector or matrix with the same size and type as bits.


[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.

Extended Capabilities

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

Version History

Introduced in R2017b