802.11 presets, knob by knob¶
A preset is one number: --wlan N, the 20 MHz data rate in Mb/s. It picks the
constellation and the code rate, and everything else has a default.
Does the first command ask for --data?
If wfmgen --type ofdm --wlan 54 -o ppdu.cf32 fails with
give --data FIELD or --data-from-file PATH, your doppler is older than
this page, and some of its commands and code won't run. To use them all,
build main from source. Follow
Build from Source, but leave --branch and the
version out of its git clone command, because they select a release.
In that older version, --wlan N doesn't supply the data, --mac
defaults to none, and Python's Wlan(mbps=N) doesn't exist. Giving the
settings yourself works in both:
This renders one PPDU (a frame) in the 802.11a/g format:
The plots show what each knob does, not that the signal meets IEEE 802.11. See what has been checked.
This guide turns one knob at a time and shows what changes. In Python, most
options are keywords with the same name, so --scrambler-init is
scrambler_init. These are different:
--offisoff_samples.data,mac_headerandfilltake arrays of bits, not text.--data-from-filehas no keyword. Read the file and pass its bits asdata.
The code blocks run in order and come from the example
wlan_presets_demo.py, which also checks the results and draws every figure
(run it yourself). Start here:
from itertools import product
import numpy as np
from doppler.spectral import FFT, PSD
from doppler.wfm import Composer, Segment, Synth
from doppler.wlan import Wlan
# The presets: every data rate the library's table has, in Mb/s at 20 MHz
PAIRS = product(
("bpsk", "qpsk", "qam16", "qam64"), ("r12", "r23", "r34", "r56")
)
RATES = sorted(
{Wlan(constellation=c, code_rate=r).rate_mbps for c, r in PAIRS} - {0}
)
def render(**knobs):
"""An 802.11 scene: every default, except the knobs you name."""
return Composer([Segment(type="ofdm", **knobs)]).compose()
def octets(n):
"""`n` payload octets as the bits a data source takes (a ramp)."""
return np.unpackbits(np.arange(n, dtype=np.uint8))
x = render(wlan=54) # a whole PPDU: 100-octet PSDU, 20 MHz, no noise
Find your knob¶
| You want to change | Knob | Default |
|---|---|---|
| the data rate | --wlan N, or --constellation with --code-rate |
36 Mb/s |
| what the frame carries | --data or --data-from-file, with --data-len |
96 octets of PN15 |
| the MAC header and FCS | --mac, --mac-header |
fcs |
| the scrambler's start | --scrambler-init |
0: drawn for each PPDU from --seed |
| the spectrum's skirts | --window |
100 ns |
| the sample rate | --fs |
the bandwidth |
| the channel width | --bandwidth |
20 MHz |
| the spacing of PPDUs | --gap |
0: back to back |
| noise | --snr, --snr-mode fs, --seed |
100 dB: none |
| where and how strong | --freq, --level |
0 Hz, 0 dBFS |
Anything you leave out keeps its default. A combination that can't work is
refused, with the reason. An --fs of exactly 1 or 1e6 counts
as left out, so it becomes the bandwidth.
What a preset renders¶
The L-STF and L-LTF are training fields, the same in every PPDU. SIGNAL gives the rate and the PSDU's length. Data carries the PSDU (the frame's octets) in 4 µs OFDM symbols. The preamble and SIGNAL always take 20 µs at 20 MHz. At a 20 MHz sample rate, that is 400 samples, then 80 for each Data symbol, then a 2-sample tail from the default window.
Rate: --wlan N¶
Use one of 6, 9, 12, 18, 24, 36, 48 or 54. Wlan(mbps=N) gives each one's
numbers:
>>> for mbps in RATES:
... w = Wlan(mbps=mbps)
... print(f"{mbps:2d} Mb/s: {w.n_bpsc} bits a subcarrier, "
... f"{w.n_dbps:3d} data bits a symbol")
6 Mb/s: 1 bits a subcarrier, 24 data bits a symbol
9 Mb/s: 1 bits a subcarrier, 36 data bits a symbol
12 Mb/s: 2 bits a subcarrier, 48 data bits a symbol
18 Mb/s: 2 bits a subcarrier, 72 data bits a symbol
24 Mb/s: 4 bits a subcarrier, 96 data bits a symbol
36 Mb/s: 4 bits a subcarrier, 144 data bits a symbol
48 Mb/s: 6 bits a subcarrier, 192 data bits a symbol
54 Mb/s: 6 bits a subcarrier, 216 data bits a symbol
Two presets share each constellation. The faster of the two sends fewer coding bits, so it has less protection against errors. A denser constellation also needs a better SNR.
A faster preset takes less time, but the 20 µs preamble and SIGNAL never get shorter. For a 100-octet PSDU at 54 Mb/s, they take longer than its 16 µs of Data. At 1000 octets, Data takes most of the time at every rate:
PREAMBLE_US = 20.0 # L-STF 8, L-LTF 8, SIGNAL 4
def data_us(mbps, psdu):
"""The Data field's airtime at 20 MHz: 4 us an OFDM symbol."""
return 4.0 * Wlan(mbps=mbps).n_sym(psdu)
airtime = {mbps: PREAMBLE_US + data_us(mbps, 1000) for mbps in RATES}
The same rate, spelled out. --wlan 36 means
--constellation qam16 --code-rate 3/4. Give one form or the other, never
both, and always give the pair together. Both give the same samples:
wfmgen --type ofdm --wlan 36 -o preset.cf32
wfmgen --type ofdm --constellation qam16 --code-rate 3/4 -o pair.cf32
cmp preset.cf32 pair.cf32
Payload: --data and --data-len¶
--data-len is each frame's payload in bits (a whole number of octets).
The source is cut into frames of that length, and each becomes one PPDU.
If the data doesn't fill the last frame, it is refused unless you give
--fill to pad it. With
--mac none, the payload is the PSDU. Otherwise, the
MAC option adds to it. Either way, the PSDU is 1 to 4095 octets.
# a generated payload: 100 octets of PN15
wfmgen --type ofdm --wlan 54 --data pn:800:15 --data-len 800 -o pn.cf32
# your own octets, 4 a frame: one PPDU
printf 'abcd' > body.bin
wfmgen --type ofdm --wlan 54 --data-from-file body.bin --data-len 32 \
-o file.cf32
In Python, data is an array of bits, with each octet's most significant bit
first. octets() above makes one. A longer PSDU doesn't make a smooth
difference to the airtime, because the Data field is padded to a whole number
of symbols:
The steps are wider at faster presets, because each symbol holds more bits.
MAC header and FCS: --mac¶
--mac |
What you give | What the PSDU holds |
|---|---|---|
none |
the whole PSDU | your octets |
fcs (default) |
everything before the FCS | your octets and a 4-octet FCS |
data |
the body, and --mac-header |
the header, your octets and the FCS |
HEADER = bytes.fromhex("08020000ffffffffffff0200000000010200000000020000")
BODY = 96 # octets
payload = {
"wlan": 36,
"data": octets(BODY),
"data_len": 8 * BODY,
"scrambler_init": 93,
}
as_is = render(mac="none", **payload) # the payload is the PSDU
with_fcs = render(mac="fcs", **payload) # payload + FCS: the default
with_header = render( # header + payload + FCS
mac="data",
mac_header=np.unpackbits(np.frombuffer(HEADER, np.uint8)),
**payload,
)
If your octets already end with an FCS, use --mac none, or a second one
is added. --mac-header takes 24 or 30 octets. The library sends them as
given and doesn't check the header's fields:
wfmgen --type ofdm --wlan 36 --mac data \
--mac-header 0x08020000ffffffffffff0200000000010200000000020000 \
--data pn:768:15 --data-len 768 -o header.cf32
Scrambler: --scrambler-init¶
The scrambler mixes the Data bits before they are coded. Its starting state is 1 to 127. Changing the state changes the Data symbols, and so the waveform's peaks, even when the payload stays the same:
zeros = {"data": np.zeros(800, np.uint8), "data_len": 800}
def peak_db(x):
"""Peak over mean power, dB."""
p = np.abs(x) ** 2
return 10 * np.log10(p.max() / p.mean())
by_state = {
state: render(wlan=36, fs=80e6, scrambler_init=state, **zeros)
for state in range(1, 128)
}
peaks = {state: peak_db(x) for state, x in by_state.items()}
This is one all-zero, 100-octet payload at 36 Mb/s, at 4 times the 20 MHz rate. The peak is 7.2 to 10.5 dB above the mean, so one frame doesn't tell you how much headroom to leave.
0(the default) draws a new state for each PPDU from--seed. The same seed gives the same samples, and each PPDU gets its own draw.- 1 to 127 uses that state for every PPDU. Use it to compare two signals bit for bit, or to reproduce a known frame.
The number is the register's contents, not the first seven bits it sends. If a document gives those first seven bits, convert them: the design page shows why 54 in one form is 93 in the other.
Window: --window¶
Each OFDM symbol is cut off sharply at its ends, which spreads power outside
the channel. --window cross-fades neighboring symbols instead. It is
counted in output samples. Here, M is fs / bandwidth:
M = 4 # fs over bandwidth
long_psdu = {"data": octets(4000), "data_len": 32000, "scrambler_init": 93}
windowed = {
w: render(wlan=54, fs=M * 20e6, window=w, **long_psdu)
for w in (0, 2 * M, 8 * M) # none, the default, longer
}
The next helper reads the Data symbols and measures the spectrum. The
Blackman-Harris window in spectrum() is only for the measurement.
--window is part of the signal:
PILOTS = (-21, -7, 7, 21)
DATA = [k for k in range(-26, 27) if k and k not in PILOTS]
def data_points(x, n_sym, m=1):
"""Each Data symbol's 48 points: a transform of its last 64 m samples.
The signal here has no channel and no offset, so nothing is corrected.
A receiver has to find the start, the frequency and the channel first.
"""
size = 64 * m
fft = FFT(n=size)
rows = []
for s in range(n_sym):
start = m * (400 + 80 * s + 16) # preamble + SIGNAL, then the prefix
body = np.ascontiguousarray(x[start : start + size], np.complex64)
bins = fft.execute_cf32(body).copy()
rows.append(bins[DATA] * np.sqrt(52) / size)
return np.concatenate(rows).astype(np.complex64)
def spectrum(x, fs, n=1024):
"""Frequency in MHz, and averaged density in dB relative to its peak."""
psd = PSD(n=n, fs=fs, window="blackman-harris", hop=n // 2)
psd.accumulate(np.ascontiguousarray(x, np.complex64))
db = np.asarray(psd.psd_db())
f = (np.arange(len(db)) - len(db) // 2) * fs / len(db)
return f / 1e6, db - db.max()
- Left out: 100 ns, or
2 Msamples. It stays 100 ns when you change--fs. Off 20 MHz, it is still2 Msamples, so it is 200 ns at 10 MHz and 400 ns at 5 MHz. 0: no cross-fade. The skirts are highest, but it is useful for comparing samples exactly.- Up to
16 M: lower skirts, and no change to the 64Msamples a receiver uses, if it takes the last 64Mof each symbol, as here. It does use up some of the guard interval, which is there to absorb echoes and timing error. - Above
16 M: the cross-fade reaches the data itself. The right-hand plot shows how fast the error grows. The limit is80 M, one whole symbol.
The spectrum uses 78.1 kHz bins, with a noise bandwidth of about 157 kHz. It isn't a transmit mask test, which needs each mask's own limits and measurement settings.
Sample rate: --fs¶
--fs is a whole multiple M of the bandwidth, from 1 to 128. Left out, it
is the bandwidth itself. The signal is made with a larger transform, not a
resampler. Without a window, every M-th sample is the original one, to
float rounding:
coarse = render(wlan=36, window=0, scrambler_init=93)
fine = render(wlan=36, window=0, scrambler_init=93, fs=8 * 20e6)
A higher fs shows peaks that fall between the 20 MHz samples, and leaves
room to see the skirts or to add another channel. It doesn't change
the bit rate or the airtime. Give --gap and --window in output samples,
so multiply any count you set by M to keep the same time.
Bandwidth: --bandwidth¶
20e6, 10e6 or 5e6. The samples of each PPDU stay the same at the same
M, but they are played more slowly. Each step down halves the width and the
rate, and doubles the airtime:
narrow = {
bandwidth: render(
fs=40e6,
bandwidth=bandwidth,
constellation="qam16",
code_rate="3/4",
**long_psdu,
)
for bandwidth in (20e6, 10e6, 5e6)
}
All three use the same 156 kHz bins, with a noise bandwidth of about 313 kHz. That blurs the edges of the 5 MHz signal most, relative to its width.
--wlan names a 20 MHz rate, so it is refused at 10 and 5 MHz. Use the
pair instead. qam16 and 3/4 carry 36, 18 or 9 Mb/s:
Gaps and bursts: --gap¶
--gap N adds N output samples after each PPDU. A source with three
frames gives three PPDUs and three gaps:
GAP = 600 # samples after each PPDU, at fs
burst = render(
wlan=54,
data=np.tile(octets(100), 3), # three frames of 100 octets
data_len=800,
gap=GAP,
snr=15.0,
seed=1,
)
If the source has noise, the noise runs through the gaps, as it would in a
real channel. Without noise, the gaps are exactly zero. --off is different:
it adds its gap after the whole segment, each time the segment plays. It
also follows --gap-noise, and --gap-noise off makes it zero. The gaps from
--gap keep the source's noise.
--repeats sets how many times
the segment plays.
Noise: --snr¶
Left at 100 or more, there is no noise. Below that, it is the signal power
over the noise power across the whole sampled band. --snr-mode auto and
fs mean the same here. --seed picks the noise, so the same seed gives the
same samples:
SNRS = (10.0, 20.0, 30.0) # dB, over the whole sampled band
psdu_2000 = {
"wlan": 36,
"data": octets(2000),
"data_len": 16000,
"scrambler_init": 93,
}
noisy = {
snr: render(snr=snr, snr_mode="fs", seed=3, **psdu_2000) for snr in SNRS
}
data_points() has no channel to correct here. A real receiver also has to
find the timing, the frequency and the channel, and it will do worse than
this.
The SNR on each subcarrier is higher than --snr. All of the signal is
on 52 of the 64 M subcarriers, but the noise is spread across all of them:
That adds 0.9 dB at M = 1 and 6.9 dB at M = 4. The example checks both, at
all three SNRs, by comparing each noisy point with the same point without
noise. So the same --snr is
an easier signal at a higher fs. To keep the same noise on each
subcarrier, lower --snr by 10 log10(M) dB.
ebno and esno are refused, because a PPDU has no single symbol rate for
them to use.
Place it in a scene: --freq and --level¶
--freq moves the carrier, and --level sets its power (0 dBFS is unit
power). In Python, add up several sources with Segment.sum. Choose an fs
wide enough for all of them:
def two_channels(fs):
"""Two channels 30 MHz apart, the second 20 dB lower."""
return Composer(
[
Segment.sum(
Synth(type="ofdm", fs=fs, freq=-15e6, wlan=54, **long_psdu),
Synth(
type="ofdm",
fs=fs,
freq=15e6,
wlan=54,
level=-20.0, # dB below the first
**long_psdu,
),
fs=fs,
)
]
).compose()
FS = 160e6 # leaves room for the skirts, not only the channels
channels = two_channels(FS)
The spectrum uses 78.1 kHz bins. Leave room for the skirts as well as the
channels. At fs = 80e6, the first channel's skirt wraps around, making a
bump near +40 MHz. At 160 MHz there is no visible bump there. The skirt still
wraps, but only faintly, near the edges of the plot at about -88 dB.
Sources keep their own rates, payloads and windows. A segment has one fs,
which must be a whole multiple of every OFDM source's bandwidth. It also has
one noise floor. Scenes explains how the sources set it,
and how to play segments in order.
What is refused¶
A combination that can't work raises ValueError in Python. On the command
line it is an error, with a non-zero exit. The message says why:
REFUSED = {
"not one of the eight rates": {"wlan": 7},
"a rate given twice": {
"wlan": 36,
"constellation": "qam16",
"code_rate": "3/4",
},
"half of a rate": {"constellation": "qam16"},
"wlan away from 20 MHz": {"wlan": 36, "bandwidth": 10e6},
"fs is not a multiple of the bandwidth": {"fs": 30e6},
"a window longer than a symbol": {"window": 81},
"mac=data with no header": {"mac": "data"},
"a scrambler state over 7 bits": {"scrambler_init": 128},
"an SNR per symbol": {"snr": 10.0, "snr_mode": "esno"},
"data that does not fill its last frame": {
"data": octets(150),
"data_len": 800,
},
}
reasons = {}
for what, knobs in REFUSED.items():
try:
render(**knobs)
except ValueError as err:
reasons[what] = str(err) # says what to change
| This is refused | Use instead |
|---|---|
--wlan 7 |
one of the eight rates |
--wlan with --constellation or --code-rate |
one form or the other |
--constellation or --code-rate alone |
both of them |
--wlan at 10 or 5 MHz |
the pair |
--fs 30e6 at 20 MHz |
a whole multiple, such as 40e6 |
--window above 80 M |
a shorter window |
--mac data without --mac-header |
a 24- or 30-octet header |
--scrambler-init above 127 |
1 to 127, or 0 |
--snr-mode esno or ebno |
fs or auto |
| data that doesn't fill its last frame | --fill, or a --data-len that divides it |
One PPDU without a scene: Wlan¶
To turn a PSDU into samples without a scene, call
Wlan directly. It has fewer knobs and adds nothing to
your PSDU:
psdu = np.arange(100, dtype=np.uint8)
one = Wlan(mbps=36, oversample=2).ppdu(psdu, 93) # 93: the scrambler state
same = render(
wlan=36, fs=40e6, mac="none", scrambler_init=93,
data=octets(100), data_len=800,
)
assert np.allclose(one, same, atol=1e-5)
| Scene knob | Wlan |
|---|---|
wlan, or the pair |
mbps, or constellation and code_rate ("r34" for 3/4) |
fs / bandwidth |
oversample |
window |
window |
data, mac |
the PSDU you pass to ppdu(); mpdu() adds a header and an FCS |
scrambler_init |
the state you pass to ppdu(), 1 to 127 (there is no 0) |
| gaps, noise, frequency, level | none: use a scene |
Keep or repeat a run¶
Write the scene with --record, then play it back with --from-file. The
record saves the rate, payload, MAC option, window, fs, SNR and seed. An
option it doesn't list uses the default of the version playing it back.
Here that includes bandwidth, gap, level and scrambler_init. The
record also saves snr_mode as auto, so that version decides what auto
means:
wfmgen --type ofdm --wlan 54 --seed 7 --record scene.json -o a.cf32
wfmgen --from-file scene.json -o b.cf32
cmp a.cf32 b.cf32
What this guide doesn't show¶
The figures show what each knob does. They don't show that a signal meets IEEE 802.11. The 802.11 guide and the design page say what has been checked, and what hasn't.
Reproduce the figures¶
Your doppler must include wlan_presets_demo. If the note at the top
applies to you, installing the current release won't add it. Build main as
that note says, including the make pyext step. Then, from the checkout's
root, use the checkout's own Python:
If you installed a release that includes it, use:
Both check the results, then write all twelve figures to the current
directory. To update the copies on this page, run
make gallery GALLERY_SCRIPTS=src/doppler/examples/wlan_presets_demo.py from
a checkout.
See also¶
- 802.11 non-HT OFDM: the stages, from the MAC to the samples
- wfmgen's OFDM type: the option reference
- OFDM: build your own layout
- Power spectra: the
PSDused here











