Skip to content

Window functions compared

Compare five classic windows and the Kaiser family by main lobe, side lobes, scalloping loss, coherent gain and noise bandwidth, then pick one for a measurement.

Before thisOversampling and noise shaping (11.3), The DFT (13.2)

2 more before it

How big is a signal (1.3), Properties of the DTFT (12.3)

Before this11.3 · 13.2 · 2 more
Chapter 15 · Lesson 2 of 6

First, the picture

Five windows, one trade: watch the main lobe widen while the highest side lobe sinks.

Five windows, one trade

Each window's shape, and its spectrum |W| in dB relative to its peak, for N = 1024.

Rectangular: the narrowest main lobe, 2 bins, but side lobes from −13.3 dB that fall only 6 dB each time the distance doubles.

main lobe
2.0 bins
highest side lobe
−13.3 dB
Window
0.00 / 17.00 s
Describe this picture

Two panels. The first is the window’s shape, w[n]w[n] from −0.1-0.1 to 1.11.1 against n/Nn/N from 0 to 1. The second is its spectrum, ∣W∣\lvert W\rvert in dB relative to its peak from −120-120 to 0, against the offset from the tone from 0 to 16 bins, for N=1024N = 1024. A bracket under the spectrum’s axis, from 0 to the first zero, is labelled “half the main lobe”, and a dotted level marks the highest side lobe with its value. The readouts are the main lobe, zero to zero, and the highest side lobe.

The clip plays once, in 17 s, and holds on its last frame. It steps through the five windows, cross-fading between them, and the caption says what each one shows. Rectangular: the narrowest main lobe, 2.0 bins, with side lobes from −13.3 dB that fall only 6 dB each time the distance doubles. Hann: 4.0 bins, side lobes from −31.5 dB, falling 18 dB per doubling. Hamming: the same 4.0 bins and a lower first side lobe, −42.7 dB, after which its side lobes fall only 6 dB per doubling. Blackman: 6.0 bins, side lobes from −58.1 dB, falling 18 dB per doubling. Flat-top: 10.0 bins with a flat top, side lobes below −93 dB (the readout is −93.0), and a shape that dips below 0 near the ends. Once the clip has finished, five buttons, a radio group named “Window”, switch the window and show its caption.

Textbooks list dozens, and they sit on one trade

Windowing & spectral leakage (15.1) met three windows: rectangular, Hann and Blackman. Each one lowered the leakage of a tone, and each paid for it with a wider main lobe in the window’s own spectrum. The list in a textbook runs to dozens of windows. Every one of them is a point on that same trade: a wider main lobe buys lower side lobes.

Five numbers describe a window for measurement. Two are the pair from 15.1, the width of the main lobe and the height of the highest side lobe. Roll-off is how many dB the side lobes fall each time the distance from the tone doubles. Scalloping loss is how much a tone halfway between two bins reads low. Coherent gain and equivalent noise bandwidth say how the window scales a tone and noise. I will take them in that order, then put one knob on the whole trade, and end with which window to use for which measurement.

Every window on this page is the one SciPy makes by default, the periodic window. Hann is w[n]=0.5−0.5cos⁡(2πn/N)w[n]=0.5-0.5\cos(2\pi n/N) for n=0n=0 to N−1N-1, so its main lobe is exactly 4 bins. NumPy’s np.hanning(N) divides by N−1N-1 instead, which is the symmetric form made for filters. For spectra, use the periodic one.

Five windows, one trade

Two more windows join the three. Hamming is w[n]=0.54−0.46cos⁡(2πn/N)w[n]=0.54-0.46\cos(2\pi n/N): Hann lifted off zero, so that the first side lobe nearly cancels. Flat-top (SciPy’s flattop) is a sum of five cosines,

w[n]=∑m=04amcos⁡ ⁣(2πmnN),w[n]=\sum_{m=0}^{4}a_m\cos\!\left(\frac{2\pi mn}{N}\right),

with weights a0a_0 to a4a_4 of 0.21557895, −0.41663158-0.41663158, 0.277263158, −0.083578947-0.083578947 and 0.006947368. It is built for a main lobe with a flat top.

The picture at the top of this page steps through all five. When its clip has finished, press each window in turn and watch the bracket: it grows from 1 bin to 5, half of a main lobe that grows from 2 bins to 10, while the dotted level sinks from −13.3 dB to −93.0 dB. Hamming is the one to watch. Its first side lobe is lower than Hann’s, but its far side lobes are higher: a window trades near leakage for far leakage as well.

At a short length the numbers move a little. For N=32N=32 the highest side lobes are −13.2-13.2, −31.5-31.5, −41.8-41.8, −58.1-58.1 and −83.2-83.2 dB for rectangular, Hann, Hamming, Blackman and flat-top, against −13.3-13.3, −31.5-31.5, −42.7-42.7, −58.1-58.1 and −93.0-93.0 at N=1024N=1024. The pictures and the table below use N=1024N=1024, which is the textbook large-NN case.

Between two bins, the peak bar sags

A tone does not sit on a bin unless it is lucky. Say a tone is dd bins from the nearest bin, with dd from 0 to 0.5. By Properties of the DTFT (12.3), the window’s spectrum WW stands in place of the tone’s arrow, so the tallest bar reads the main lobe at dd, not at its top. The drop is the scalloping loss:

20log⁡10∣W(ej2πd/N)∣W(ej0),20\log_{10}\frac{\lvert W(e^{j2\pi d/N})\rvert}{W(e^{j0})},

worst at d=0.5d=0.5, halfway between two bins. A picket fence in front of a hill shows the same thing. The tallest picket is lower than the hilltop, unless the top is flat.

Watch the flat-top curve: it stays on 0 dB. Halfway between two bins, rectangular reads 3.92 dB low and Hann 1.42 dB.

Between two bins, the peak bar sags

The tallest bar of a tone of amplitude 1, read through three windows, as the tone moves from a bin to halfway between two.

On a bin, every window reads the full amplitude: 0 dB.

offset d
0.00 bins
rectangular
0.00 dB
Hann
0.00 dB
flat-top
0.00 dB
0.00 / 11.00 s
Describe this picture

One panel: the tallest bar of a tone of amplitude 1, in dB from −4.5-4.5 to 0.5, against the tone offset dd from 0 to 0.5 bins, read through three windows. Rectangular is solid with a filled dot, Hann dashed with a filled square and flat-top dotted with a filled diamond; each curve is traced up to the current dd and labelled at its end. The readouts are the offset dd and each window’s tallest bar.

The clip plays once, in 11 s, and holds on its last frame. On a bin every window reads the full amplitude, 0 dB, and every readout is 0.00. The tone then slides off the bin, each tallest bar sliding down its window’s main lobe. At a quarter bin, rectangular has lost 0.91 dB, Hann 0.35 dB and flat-top nothing you can see (0.00 dB). The clip ends halfway between bins, the worst case: rectangular reads 3.92 dB low (0.64 of the amplitude), Hann 1.42 dB (0.85) and flat-top 0.01 dB. Afterwards, dragging across the plot or the arrow keys move the tone from 0 to 0.5 bins; the slider is named “Tone offset d”.

The full curve is in numbers too. At d=0.1d=0.1, 0.2, 0.25, 0.3 and 0.4, rectangular loses 0.14, 0.58, 0.91, 1.33 and 2.42 dB, and Hann loses 0.06, 0.22, 0.35, 0.51 and 0.91 dB. Flat-top stays within 0.01 dB all the way. At d=0.5d=0.5 Hamming loses 1.75 dB and Blackman 1.10 dB.

Two scale factors

A tone of amplitude AA exactly on a bin reads ∣X[k]∣=A∑nw[n]/2\lvert X[k]\rvert=A\sum_nw[n]/2 (The DFT, 13.2, gave AN/2AN/2 for the plain cut, where every w[n]w[n] is 1). The window’s average is its coherent gain:

CG=1N∑n=0N−1w[n].\mathrm{CG}=\frac1N\sum_{n=0}^{N-1}w[n].

For Hann it is 0.5. Divide a bin by N CG/2N\,\mathrm{CG}/2 and you read AA.

Noise is spread evenly over frequency (Oversampling and noise shaping, 11.3), so a bin collects noise in proportion to the area under ∣W∣2\lvert W\rvert^2. In bins, that area is the equivalent noise bandwidth:

ENBW=N∑n=0N−1w[n]2(∑n=0N−1w[n])2.\mathrm{ENBW}=\frac{N\sum_{n=0}^{N-1}w[n]^2}{\big(\sum_{n=0}^{N-1}w[n]\big)^2}.

It is 1 bin for the rectangular window and 1.5 bins for Hann. The figure shows why.

-4-2024offset (bins)10|W|² ÷ |W(0)|²ENBW = 1.5 binsHann |W|² (solid)
Fig. A bin collects noise from every frequency its window’s main lobe and side lobes reach. For Hann that is as much as a perfect bin 1.5 bins wide: the equivalent noise bandwidth. A Hann bin collects 1.5 times the noise of a rectangular one, 1.76 dB more.

Three more rows of the same measure. Read through Hann, Blackman and flat-top windows, the same white noise lands 1.76, 2.37 and 5.76 dB above its level through a rectangular window, when each tone is read with its own coherent gain. The bill for a wide, flat top is a bigger noise bin.

The maths behind it · effective sample size

ENBW is to spectra what the effective sample size is to weighted averages: uneven weights waste data. The ratio N(∑w)−2∑w2N(\sum w)^{-2}\sum w^2 is the same one that measures how much a weighted mean’s variance grows over an equal-weight one.

One knob: Kaiser’s β

The Kaiser window puts the whole trade on one dial. With the shape parameter β\beta,

w[n]=I0 ⁣(β1−(2n/N−1)2)I0(β)w[n]=\frac{I_0\!\left(\beta\sqrt{1-(2n/N-1)^2}\right)}{I_0(\beta)}

for n=0n=0 to N−1N-1, where I0(u)=∑m≥0((u/2)m/m!)2I_0(u)=\sum_{m\ge0}\big((u/2)^m/m!\big)^2 is the modified Bessel function of order 0, a series that converges quickly. In SciPy it is get_window(('kaiser', beta), N). At β=0\beta=0 the square root does not matter, because I0(0)=1I_0(0)=1, and the window is the rectangular one.

Raising β\beta narrows the window in time, widens the main lobe and sinks the side lobes, smoothly. A camera’s aperture ring does the same with one ring: depth of field against light.

Watch the main lobe widen slowly while the side lobes fall fast. At β=8.6\beta=8.6 the main lobe is close to Blackman’s width, with side lobes 5 dB lower.

One knob: Kaiser's β

The Kaiser window for N = 1024. β = 0 is the rectangular window.

β = 0: the rectangular window. Main lobe 2 bins, side lobes from −13.3 dB.

β
0.0
main lobe
2.00 bins
highest side lobe
−13.3 dB
0.00 / 13.00 s
Describe this picture

The two panels of the first picture, for the Kaiser window with N=1024N = 1024: the shape (here from 0 to 1.1) and the spectrum with its bracket and dotted level. The readouts are β\beta, the main lobe and the highest side lobe. β=0\beta = 0 is the rectangular window.

The clip plays once, in 13 s, and holds on its last frame. At β=0\beta=0 the main lobe is 2.00 bins and the side lobes start at −13.3 dB. As β\beta rises the window narrows in time, the main lobe widens and the side lobes sink. At β=4\beta=4 the window bows: main lobe 3.24 bins, side lobes from −29.9 dB. The clip ends at β=8.6\beta=8.6: main lobe 5.83 bins, side lobes from −63.3 dB, close to Blackman’s width with 5 dB lower side lobes; one knob slides along the whole trade. Afterwards, dragging across the spectrum or the arrow keys set β\beta from 0 to 12; the slider is named “Kaiser β”. At β=6.0\beta=6.0 the caption reads “β = 6.0: main lobe 4.31 bins, highest side lobe −43.8 dB.”

For a side-lobe level you want, there is a rule. For a highest side lobe aa dB below the peak, Kaiser and Schafer give

β=0.76609 (a−13.26)0.4+0.09834 (a−13.26)\begin{aligned} \beta&=0.76609\,(a-13.26)^{0.4}\\ &\quad+0.09834\,(a-13.26) \end{aligned}

for aa from 13.26 to 60, and

β=0.12438 (a+6.3)\beta=0.12438\,(a+6.3)

for aa above 60. The main lobe is then close to 21+(β/π)22\sqrt{1+(\beta/\pi)^2} bins.

For 40 dB the rule gives β=5.48\beta=5.48, and the window it makes reaches −40.1-40.1 dB with a main lobe of 4.02 bins. For 60 dB it gives β=8.16\beta=8.16 and −59.9-59.9 dB. For 80 dB it gives β=10.73\beta=10.73, −79.9-79.9 dB and a main lobe of 7.12 bins.

The window table

Everything so far goes into one table for N=1024N=1024 and periodic windows as SciPy makes them.

WindowMain lobe (bins)Highest side lobe (dB)Roll-off (dB per doubling)CGENBW (bins; dB)Scalloping loss (dB)
Rectangular2−13.361.0001.00; 0.00−3.92
Hann4−31.5180.5001.50; 1.76−1.42
Hamming4−42.760.5401.36; 1.34−1.75
Blackman6−58.1180.4201.73; 2.37−1.10
Flat-top10−93.0none: stays near −930.2163.77; 5.76−0.01
Kaiser, β = 8.65.83−63.360.4211.72; 2.36−1.11

Fig. The five numbers for six windows (N = 1024, periodic windows as SciPy makes them). No row wins every column.

Choosing a window

Use the rule that fits the question.

  • Tones exactly on bins, or a transient shorter than the record: rectangular. Nothing leaks when every tone is on a bin, and it has the narrowest main lobe and the lowest noise.
  • A first look at an unknown signal: Hann.
  • Weak tones near strong ones: Blackman, or Kaiser with β\beta from the side-lobe rule.
  • Reading a tone’s amplitude: flat-top, with 0.01 dB of scalloping, at the cost of 3.77 bins of noise.
  • Two close tones of similar size: the narrowest main lobe that the side lobes allow, so rectangular or Hann.

The maths behind it · banded matrices

A sum-of-cosines window (Hann, Hamming, Blackman, flat-top) is a short vector of weights on the DFT’s columns. Windowing, in the bins, is then a small banded matrix acting on the rectangular window’s bins. Hann’s weights 0.5, −0.25, −0.250.5,\,-0.25,\,-0.25 make a three-point filter run along the bins.

Worked example

  1. Reading a 1 V tone halfway between bins. Through a rectangular window it reads 0.637 V, through Hann 0.849 V and through flat-top 0.999 V. Each is 10loss/2010^{\text{loss}/20} for the loss at d=0.5d=0.5.
  2. Noise per bin. The ENBWs 1.5, 1.727 and 3.770 are 1.76, 2.37 and 5.76 dB.
  3. Kaiser targets. β\beta of 0, 2, 4, 6, 8.6, 10 and 12 give main lobes of 2.00, 2.37, 3.24, 4.31, 5.83, 6.67 and 7.90 bins. Their highest side lobes are −13.3-13.3, −18.4-18.4, −29.9-29.9, −43.8-43.8, −63.3-63.3, −74.1-74.1 and −89.9-89.9 dB.
  4. Short windows. At N=32N=32 the highest side lobes are −13.2-13.2, −31.5-31.5, −41.8-41.8, −58.1-58.1 and −83.2-83.2 dB. At N=1024N=1024 they are −13.3-13.3, −31.5-31.5, −42.7-42.7, −58.1-58.1 and −93.0-93.0.

Where you’ll meet this

Zero-padding and resolution (15.3) separates the reading of the bars from the resolution of the window. Reading a spectrum: scaling and units (15.4) uses CG\mathrm{CG} and ENBW\mathrm{ENBW} to put numbers on a spectrum. Kaiser windows return in Window-method FIR design (19.1), where NumPy’s symmetric windows belong, and tapers for spectral estimation in The periodogram (25.1).

Reference card

QuantityFormulaNotes
Hammingw[n]=0.54−0.46cos⁡(2πn/N)w[n]=0.54-0.46\cos(2\pi n/N)−42.7 dB, then 6 dB per doubling
Kaiserw[n]=I0(β1−(2n/N−1)2)/I0(β)w[n]=I_0\big(\beta\sqrt{1-(2n/N-1)^2}\big)/I_0(\beta)β=0\beta=0: rectangular
Kaiser main lobe≈21+(β/π)2\approx2\sqrt{1+(\beta/\pi)^2} bins
Kaiser β\beta for aa dB side lobes0.76609(a−13.26)0.4+0.09834(a−13.26)0.76609(a-13.26)^{0.4}+0.09834(a-13.26) for a≤60a\le60; 0.12438(a+6.3)0.12438(a+6.3) for a>60a>60Kaiser and Schafer
Coherent gainCG=1N∑n=0N−1w[n]\mathrm{CG}=\frac1N\sum_{n=0}^{N-1}w[n]tone on a bin reads A N CG/2A\,N\,\mathrm{CG}/2
ENBWN∑w[n]2/(∑w[n])2N\sum w[n]^2\big/\big(\sum w[n]\big)^2 binsnoise per bin
Scalloping loss20log⁡10(∣W(ejπ/N)∣/W(ej0))20\log_{10}\big(\lvert W(e^{j\pi/N})\rvert/W(e^{j0})\big)worst case, d=0.5d=0.5
Choosebins exact: rectangular; default: Hann; dynamic range: Blackman, Kaiser; amplitude: flat-top

End of lesson 15.2

Where to go next.

Phasorium
LibraryEvery lesson, in order

Parts

About Phasorium
Look