---
title: Windows and leakage
heading: Why a tone that doesn't fit a whole number of cycles in the record spreads across every DFT bin, the rectangular window's sinc-shaped spectrum and its −13 dB sidelobes, tapered windows such as the Hann window that trade a wider main lobe for far less leakage, scalloping loss, and noise bandwidth
eyebrow: D5 · Lesson 3 · Windows and leakage
xp: 40
---

::: hook
Feed a pure tone to an FFT and you'd expect a single spike. You get one only if the tone happens to complete a whole number of cycles in the record. Otherwise the record's abrupt ends cut the wave mid-cycle, and the spectrum shows the tone smeared across every bin, with skirts that can bury a weak signal nearby. Tapering the record smoothly to zero at its ends, multiplying by a **window**, pulls those skirts down by tens of decibels. Choosing a window is the first decision in any spectrum measurement.
:::

::: play
- The spectrum, in decibels, of a tone measured with a rectangular window (no taper) and with a Hann window, against frequency in bins from the tone.
- The rectangular window has the narrowest main lobe, but its sidelobes fall slowly from −13 dB. The Hann window's main lobe is twice as wide, but its sidelobes start at −31 dB and fall three times as fast.
- Slide the tone's offset δ from the nearest bin: the bins sample the curves at δ, δ ± 1, δ ± 2, ... The readouts show the loss at the nearest bin and the leakage five bins away.
:::

```sim plot
view: graph
x: f = -8..8
y: L = -80..3
slider: d = 0..0.5 step 0.01 = 0.5
plot: 20*log(abs(sinc(f)) + 1e-9) | samples: 800 | color: ch3 | label: rectangular window, dB (f in bins)
plot: 20*log(abs(sinc(f)/(1 - f^2 + 1e-12)) + 1e-9) | samples: 800 | label: Hann window
marker: x = d | label: nearest bin
readout: rectangular loss at the nearest bin, dB = -20*log(sinc(d)) | digits: 3
readout: Hann loss at the nearest bin, dB = -20*log(sinc(d)/(1 - d^2)) | digits: 3
readout: rectangular leakage 5 bins away, dB = 20*log(abs(sinc(5 + d)) + 1e-9) | digits: 3
readout: Hann leakage 5 bins away, dB = 20*log(abs(sinc(5 + d)/(1 - (5 + d)^2)) + 1e-9) | digits: 3
```

::: predict
## A tone falls exactly halfway between two DFT bins, and no window is used. How much lower does its nearest bin read than the tone's true level?

- [ ] 0 dB
- [ ] 1.4 dB
- [x] 3.9 dB
- [ ] 13 dB

::: reveal
The rectangular window's spectrum is a sinc, and half a bin off center it's sinc(0.5) = 2/π = 0.637, or −3.92 dB. That's the **scalloping loss**. With a Hann window it's only 1.42 dB, and with a flat-top window under 0.1 dB, which is why calibrated analyzers use one for amplitude measurements.
:::
:::

::: nameit
## Leakage

A DFT treats the record as one period of a repeating signal. A tone that doesn't complete a whole number of cycles in the record has a jump where the end meets the start, and that discontinuity spreads its energy into every bin. Equivalently, the record is the tone times a rectangular window, so its spectrum is the tone convolved with the window's spectrum, a sinc of width one bin: main lobe ±1 bin, first sidelobe −13.3 dB, falling 6 dB per octave.

## Windows

Multiplying the record by a taper that goes smoothly to zero at both ends removes the jump.

| Window | Main lobe (to first null) | First sidelobe | Noise bandwidth | Scalloping loss |
|---|---|---|---|---|
| Rectangular | ±1 bin | −13.3 dB | 1.00 bin | 3.92 dB |
| Hann | ±2 bins | −31.5 dB | 1.50 bins | 1.42 dB |
| Blackman | ±3 bins | −58 dB | 1.73 bins | 1.10 dB |

The Hann window, $w_n = \frac{1}{2}\left(1 - \cos\frac{2\pi n}{N}\right)$, has spectrum $\frac{1}{2}\operatorname{sinc}(f)/(1 - f^2)$ in bins (for large N), and its sidelobes fall at 18 dB per octave.

## Noise bandwidth

A window also widens each bin's effective bandwidth for noise: the **equivalent noise bandwidth** in hertz is the value in the table times $f_s/N$. A wider ENBW lets more noise into each bin, raising the noise floor.
:::

::: example
## A strong tone sits 5.5 bins from a weak one. How far down is the strong tone's leakage at the weak tone's bin with each window?

::: solution
1. **Rectangular window.**
   $$\begin{aligned} &20\log_{10}\left|\text{sinc}(5.5)\right| \\ &= -24.8\ \text{dB} \end{aligned}$$
   enough to hide a tone 25 dB weaker.
2. **Hann window.**
   $$\begin{aligned} &20\log_{10}\left|\frac{\text{sinc}(5.5)}{1 - 5.5^2}\right| \\ &= -54.1\ \text{dB} \end{aligned}$$
   so the weak tone stands clear unless it's 50 dB down.

**Answer:** the leakage is 24.8 dB down with a rectangular window and 54.1 dB down with a Hann window.
:::
:::

::: example
## A 1024-point FFT at 48 kHz uses a Hann window. What's each bin's noise bandwidth?

::: solution
1. **No window.** Each bin's noise bandwidth is the bin spacing:
   $$\frac{48\,000\ \text{Hz}}{1024} = 46.9\ \text{Hz}$$
2. **Hann window.** It widens the noise bandwidth to 1.5 bins:
   $$\begin{aligned} B &= 1.5 \times \frac{48\,000\ \text{Hz}}{1024} \\ &= 70.3\ \text{Hz} \end{aligned}$$
3. **Noise floor.** The wider bins collect more noise, so the floor reads higher by
   $$10\log_{10} 1.5 = 1.76\ \text{dB}$$

**Answer:** each bin's noise bandwidth is 70.3 Hz, against 46.9 Hz with no window, so the noise floor reads 1.76 dB higher.
:::
:::

::: example
## A tone falls exactly halfway between two bins. How much lower does it read with a Hann window than when centered on a bin?

::: solution
1. **Hann response half a bin off center.**
   $$\begin{aligned} W(0.5) &= \frac{\text{sinc}(0.5)}{1 - 0.25} \\ &= \frac{0.637}{0.75} \\ &= 0.849 \end{aligned}$$
2. **Scalloping loss.**
   $$-20\log_{10} 0.849 = 1.42\ \text{dB}$$
   against 3.92 dB for the rectangular window.
3. **Flat-top windows.** They cut the loss to a few hundredths of a decibel, for measuring amplitudes.

**Answer:** the tone reads 1.42 dB lower with a Hann window, against 3.92 dB with a rectangular one.
:::
:::

::: check
given: d = 0.1 | 0.25 | 0.4 | 0.5
answer: -20*log(sinc(d))
unit: dB
tolerance: 0.5%

## A tone falls {d} of a bin from the nearest DFT bin, with a rectangular window. By how much does that bin underread?

::: right
Right. $-20\log_{10}\operatorname{sinc}(\delta)$ = {answer} dB.
:::

::: misses
- [-10*log(sinc(d))] Use 20 log for an amplitude.
- [any] Not yet. The sinc-shaped window spectrum, δ from its peak.
:::
:::

::: check
given: d = 0.1 | 0.25 | 0.4 | 0.5
answer: -20*log(sinc(d)/(1 - d^2))
unit: dB
tolerance: 0.5%

## The same tone, {d} of a bin off, is measured through a Hann window. By how much does its nearest bin underread?

::: right
Right. $-20\log_{10}[\operatorname{sinc}(\delta)/(1 - \delta^2)]$ = {answer} dB.
:::

::: misses
- [-20*log(sinc(d))] That's the rectangular window.
- [any] Not yet. The Hann window's spectrum.
:::
:::

::: check
given: k = 3 | 5 | 10; d = 0.3 | 0.5
answer: 20*log(abs(sinc(k + d)))
unit: dB
tolerance: 0.5%

## With a rectangular window, how far below a tone's peak is its leakage {k} + {d} bins away?

::: right
Right. $20\log_{10}|\operatorname{sinc}(k + \delta)|$ = {answer} dB.
:::

::: misses
- [any] Not yet. The sinc's level that far out.
:::
:::

::: check
given: s = 8 | 48 | 1000; N = 512 | 4096; e = 1.5 | 1.73 | 3.77
answer: e*s*1000/N
unit: Hz
tolerance: 0.5%

## A {N}-point FFT at {s} kHz uses a window with a noise bandwidth of {e} bins. What's each bin's noise bandwidth in hertz?

::: right
Right. ENBW × $f_s/N$ = {answer} Hz.
:::

::: misses
- [s*1000/N] Multiply by the window's ENBW in bins.
- [any] Not yet. Bins times the bin spacing.
:::
:::

::: check
kind: parts
given: d = 0.25 | 0.4 | 0.5

## A tone sits {d} bin from a bin's center.

::: part
answer: -20*log(abs(sin(pi*d)/(pi*d)))
unit: dB
tolerance: 1%

### How much lower does it read with a rectangular window?

::: misses
- [any] $\text{sinc}(\delta)$.
:::
:::

::: part
answer: -20*log(abs(sin(pi*d)/(pi*d))/(1 - d^2))
unit: dB
tolerance: 1%

### And with a Hann window?

::: misses
- [any] $\text{sinc}(\delta)/(1 - \delta^2)$.
:::
:::
:::

::: check
kind: parts
given: N = 512 | 1024 | 4096; fs = 8 | 48; b = 1 | 1.5

## An {N}-point FFT at {fs} kHz uses a window whose noise bandwidth is {b} bins.

::: part
answer: b*fs*1000/N
unit: Hz
tolerance: 0.5%

### What is each bin's noise bandwidth in hertz?

::: misses
- [any] ENBW × bin spacing.
:::
:::

::: part
answer: 10*log(N/(2*b))
unit: dB
tolerance: 0.5%

### What processing gain does the FFT give a tone over white noise (against the full band up to $f_s/2$)?

::: misses
- [any] $10\log_{10}(N/2/\text{ENBW})$.
:::
:::
:::

::: explain
## Why does windowing reduce leakage but blur the spectrum?

::: model
Leakage comes from the sharp edges of the record: a tone that doesn't fit a whole number of cycles is chopped off abruptly at the ends, and a sudden jump contains a broad spread of frequencies, which shows up as skirts reaching every bin. A window tapers the record smoothly to zero at both ends, removing the jump, so the skirts fall away quickly. But tapering effectively shortens the record, since the samples near the ends count for less, and a shorter record has coarser frequency resolution. So the window's main lobe gets wider, blurring tones that are only a bin or two apart, in exchange for much lower leakage far from each tone.
:::
:::

::: practice

::: check
given: d = 0.05 | 0.1 | 0.2 | 0.25 | 0.3 | 0.4 | 0.5
answer: -20*log(sinc(d))
unit: dB
tolerance: 0.5%

## Rectangular scalloping loss at δ = {d}?

::: misses
- [any] $-20\log\operatorname{sinc}\delta$.
:::
:::

::: check
given: s = 1 | 10000; N = 128 | 256 | 1024 | 8192 | 65536; e = 1 | 1.5 | 1.73 | 3.77
answer: e*s*1000/N
unit: Hz
tolerance: 0.5%

## Noise bandwidth: {N} points, {s} kHz, {e} bins?

::: misses
- [any] ENBW × $f_s/N$.
:::
:::
:::
