# Scrambler Initialization

The `wlanWaveformGenerator`

function performs scrambling as part of the transmit processing chain. You can optionally specify the *scrambler initial state* when you generate a packet using `wlanWaveformGenerator`

, or when you use other functions that scramble data. The 802.11 specification [1] describes scrambling using the concept of a* scrambling sequence *instead of the scrambler initial state. This example shows how to convert initial scrambling sequence bits to the scrambler initial state.

**Scrambling Using Initial Scrambling Sequence**

The EHT data scrambler [2] receives the 11 initial bits of the scrambling sequence and uses them to initialize the state bits in positions $${x}^{1}$$ to $${x}^{11}$$. These bits are also referred to as the scrambler initialization bits in the specification. The scrambler performs an XOR operation between these bits and the first 11 data bits (all zeroes) to generate the first 11 scrambled data out bits. After the first 11 bits are processed, the switch flips, and the remaining bits of the scrambling sequence are generated. These generated bits are used to scramble the data in from bit 12 onwards.

### Scrambling Using Initial Scrambler State

In this alternative representation of the scrambler, bits in $${x}^{1}$$ to $${x}^{11}$$initialize the scrambler before feeding in the data. The bits in $${x}^{1}$$ to $${x}^{11}$$ is called the scrambler initial state. As data bits are fed in, the scrambling sequence is generated from this initial scrambler state. The scrambler performs an XOR operation between the generated scrambler sequence and the data bits going in to produce the scrambled data out.

### Convert Initial Scrambling Sequence Bits to Scrambler Initial State

In WLAN Toolbox™, you can optionally specify the scrambler initial state when you generate an EHT, HE, S1G, VHT, HT, or non-HT OFDM packet with bandwidth signaling disabled using `wlanWaveformGenerator`

.

Generate an EHT SU packet with an initial scrambler state of 2047 ($${x}^{1}$$ to $${x}^{11}$$ all 1s).

% Create configuration for 20 MHz EHT single-user transmission cfgEHT = wlanEHTMUConfig("CBW20"); % Create a random PSDU psdu = randi([0 1],psduLength(cfgEHT)*8,1,"int8"); % Generate packet txA = wlanWaveformGenerator(psdu,cfgEHT,ScramblerInitialization=2047);

Generate an EHT SU packet given 11 initial scrambling sequence bits by converting the initial scrambling bits to an integer initial scrambler state.

% 11 EHT initial scrambling sequence bits (top-most bit MSB) initSeqBits = [1 1 1 1 1 1 1 1 1 1 1]'; % Convert 11 EHT initial scrambling sequence bits to initial scrambler state initialStateBits = mod([sum(initSeqBits([1 2 3 5 7 9 11])) sum(initSeqBits([1 2 4 6 8 10])) sum(initSeqBits([2 3 5 7 9 11])), ... sum(initSeqBits([1 4 6 8 10])) sum(initSeqBits([2 5 7 9 11])) sum(initSeqBits([1 6 8 10])), ... sum(initSeqBits([2 7 9 11])) sum(initSeqBits([1 8 10])) sum(initSeqBits([2 9 11])) sum(initSeqBits([1 10])), ... sum(initSeqBits([2 11]))],2)'; % Convert bits to integer (top-most bit MSB) initialStateInteger = bit2int(initialStateBits,11); % Generate waveform txB = wlanWaveformGenerator(psdu,cfgEHT,ScramblerInitialization=initialStateInteger);

For HE, VHT, and non-HT OFDM data scrambling, the same principle applies, but the scrambler initial state consists of only seven bits, and only seven initial bits of the scrambling sequence are required [2].

Generate an HE SU packet given seven initial scrambling sequence bits by converting initial scrambling sequence bits to an integer initial scrambler state. IEEE Std 802.11-2020 Section 17.3.5.5 [1] describes the scrambler for HE, VHT, HT, and non-HT OFDM.

% 7 initial scrambling sequence bits (top-most bit MSB) initSeqBits = [0 0 0 0 1 1 1]'; % Convert 7 initial scrambling sequence bits to initial scrambler state initialStateBits = mod([sum(initSeqBits([1 3 4 7])); initSeqBits(2:4)+initSeqBits(1:3)+initSeqBits(5:7); initSeqBits(1:3)+initSeqBits(5:7)],2); % Convert bits to integer (top-most bit MSB) initialStateInteger = bit2int(initialStateBits,7); % Create configuration for 20 MHz HE single-user transmission cfgHE = wlanHESUConfig(); % Create a random PSDU psdu = randi([0 1],getPSDULength(cfgHE)*8,1,"int8"); % Generate packet txC = wlanWaveformGenerator(psdu,cfgHE,ScramblerInitialization=initialStateInteger);

Confirm that the conversion of the initial scrambling sequence bits to the initial scrambler state is correct. Generate the scrambling sequence from the initial state by scrambling all zero data bits. This operation is correct because $$XOR(x,0)=x$$ for any bit $$x$$.

s = wlanScramble(zeros(50,1),initialStateBits);

Confirm that the first seven bits at the output match the desired scrambling sequence bits.

isequal(s(1:7),initSeqBits)

`ans = `*logical*
1

### References

[1] IEEE Std 802.11-2020, Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications, Section 17.3.5 PHY DATA scrambler and descrambler.

[2] IEEE P802.11be/D5.0, Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications, Amendment 8: Enhancements for extremely high throughput (EHT), Section 36.3.13.2 EHT PHY DATA scrambler and descrambler.