Lab · Lesson 5

Leakage and windows

Derive why a tone between two FFT bins leaks into all of them, what a Hann window does about it and the ×2 correction, then work one pump signal both ways on a calculator.

Read the whole lesson as notes · every step, derivation and worked example, on one page

1Goal Where we are going

One clean tone should give one clean line in a spectrum. Often it gives a blurred hill instead. This lesson derives exactly why, and what a window does about it, then works one pump signal through both ways.

By the end of this lesson we will have derived why a tone that falls between two FFT bins leaks into all of them, and by how much:

2 ∣Xk∣≈A ∣sin⁡π(f−k)π (f−k)∣2\,|X_k|\approx A\,\left|\frac{\sin\pi(f-k)}{\pi\,(f-k)}\right|
← no window

what a Hann window does to the same tone (after the ×2 correction every analyser applies):

readingk≈A ∣sin⁡π(f−k)∣π ∣f−k∣  ∣(f−k)2−1∣\text{reading}_k\approx A\,\frac{|\sin\pi(f-k)|}{\pi\,|f-k|\;\big|(f-k)^2-1\big|}
← Hann window

Here ff is the number of cycles of the tone in the record, and kk is the bin. Then we solve one pump signal twice on a calculator, with and without the window.

2What we already know The tools

Five facts, lettered (A) to (E). The one doing most of the work is (C), the sum of a geometric series.

On the board: the terms of that sum are arrows, each turned a little more than the last. Drag the slider. When the total turn is a whole number of circles, the arrows close into a loop and the sum is zero.

From Lesson 4, (25): the DFT of NN samples, and the peak an analyser shows:

Xk=1N∑n=0N−1xn e−i2πkn/N,peak=2 ∣Xk∣X_k=\frac{1}{N}\sum_{n=0}^{N-1}x_n\,e^{-i2\pi kn/N},\qquad \text{peak}=2\,|X_k|
(A)

Euler’s formula, turned round to give a cosine as two arrows:

cos⁡θ=12 eiθ+12 e−iθ\cos\theta=\tfrac12\,e^{i\theta}+\tfrac12\,e^{-i\theta}
(B)

The sum of a geometric series, for any q≠1q\neq1:

∑n=0N−1q n=1−qN1−q\sum_{n=0}^{N-1}q^{\,n}=\frac{1-q^{N}}{1-q}
(C)← multiply both sides by (1 − q) to check

One minus an arrow. Take out eiα/2e^{i\alpha/2}, then use e−iβ−eiβ=−2isin⁡βe^{-i\beta}-e^{i\beta}=-2i\sin\beta:

1−eiα=eiα/2(e−iα/2−eiα/2)=−2i eiα/2sin⁡α21-e^{i\alpha}=e^{i\alpha/2}\big(e^{-i\alpha/2}-e^{i\alpha/2}\big)=-2i\,e^{i\alpha/2}\sin\tfrac{\alpha}{2}
(D)

For a small angle (in radians):

sin⁡x≈x\sin x\approx x
(E)

And for a whole number mm: ei2πm=1e^{i2\pi m}=1, eiπ=−1e^{i\pi}=-1, sin⁡(x±π)=−sin⁡x\sin(x\pm\pi)=-\sin x.

3Derivation A tone into the DFT

Write the tone as two arrows and put one of them into the DFT. Out comes a geometric series: NN arrows, each turned by the same small step.

The step depends on f−kf-k: how far the tone is from the bin you are computing.

Take one tone of amplitude AA that completes ff cycles in the record. ff need not be a whole number:

xn=Acos⁡ ⁣(2πfnN+φ)x_n=A\cos\!\Big(\frac{2\pi f n}{N}+\varphi\Big)
(1)

By (B), it is two arrows turning opposite ways:

xn=A2 eiφ ei2πfn/N+A2 e−iφ e−i2πfn/Nx_n=\tfrac{A}{2}\,e^{i\varphi}\,e^{i2\pi fn/N}+\tfrac{A}{2}\,e^{-i\varphi}\,e^{-i2\pi fn/N}
(2)

Put the first arrow into (A). The exponents add:

Xk=A2N eiφ∑n=0N−1e i2π(f−k)n/NX_k=\frac{A}{2N}\,e^{i\varphi}\sum_{n=0}^{N-1}e^{\,i2\pi(f-k)n/N}
(3)← keep only the +f arrow for now

The second arrow gives the same sum with −(f+k)-(f+k) in place of f−kf-k. For a bin kk near ff, that is far from zero and it adds very little, so we set it aside. (It matters only when ff is close to 0 or to N/2N/2.)

The sum in (3) is a geometric series (C), with

q=e i2π(f−k)/N,qN=e i2π(f−k)q=e^{\,i2\pi(f-k)/N},\qquad q^{N}=e^{\,i2\pi(f-k)}
(4)

On the board: each term is an arrow of length 1, turned a little more than the last. Laid tip to tail, they curl round.

4Derivation A whole number of cycles

If the tone fits the record exactly, the arrows either all line up (in its own bin) or close into a loop (in every other bin).

Slide ff through whole numbers on the board: one bar, nothing else.

First case: ff is a whole number. In the bin k=fk=f, every exponent in (3) is zero, so every term is 1 and the sum is NN:

Xf=A2N eiφ⋅N=A2 eiφ⇒2∣Xf∣=AX_f=\frac{A}{2N}\,e^{i\varphi}\cdot N=\frac{A}{2}\,e^{i\varphi}\qquad\Rightarrow\qquad 2|X_f|=A
(5)← the true amplitude

In any other bin, f−kf-k is a whole number that is not zero. Then q≠1q\neq1, but by (4) qN=ei2π(f−k)=1q^N=e^{i2\pi(f-k)}=1, so (C) gives

∑n=0N−1q n=1−11−q=0⇒Xk=0(k≠f)\sum_{n=0}^{N-1}q^{\,n}=\frac{1-1}{1-q}=0\qquad\Rightarrow\qquad X_k=0\quad(k\neq f)
(6)← the arrows close into a loop

A tone that fits the record exactly lands in one bin and nowhere else. No leakage.

5Derivation Between two bins

If the tone doesn’t fit, the arrows never close, and every bin gets a share. The geometric series gives the share exactly; for large NN it simplifies to sin⁡(πδ)/(πδ)\sin(\pi\delta)/(\pi\delta).

On the board, the open circles are that formula; the bars are the exact FFT of 64 samples. They agree closely, except near the edges where the other arrow matters.

Second case: ff is not a whole number. Write δ=f−k\delta=f-k for the distance from the tone to bin kk. By (C) and (4):

∑n=0N−1q n=1−e i2πδ1−e i2πδ/N\sum_{n=0}^{N-1}q^{\,n}=\frac{1-e^{\,i2\pi\delta}}{1-e^{\,i2\pi\delta/N}}
(7)

Use (D) on the top (with α=2πδ\alpha=2\pi\delta) and on the bottom (with α=2πδ/N\alpha=2\pi\delta/N). The −2i-2i cancels:

∑n=0N−1q n=e iπδsin⁡(πδ)e iπδ/Nsin⁡(πδ/N)\sum_{n=0}^{N-1}q^{\,n}=\frac{e^{\,i\pi\delta}\sin(\pi\delta)}{e^{\,i\pi\delta/N}\sin(\pi\delta/N)}
(8)

NN is large, so πδ/N\pi\delta/N is a small angle: by (E), sin⁡(πδ/N)≈πδ/N\sin(\pi\delta/N)\approx\pi\delta/N and eiπδ/N≈1e^{i\pi\delta/N}\approx1:

∑n=0N−1q n≈N e iπδ sin⁡πδπδ\sum_{n=0}^{N-1}q^{\,n}\approx N\,e^{\,i\pi\delta}\,\frac{\sin\pi\delta}{\pi\delta}
(9)

Substitute (9) in (3). The NN’s cancel:

Xk≈A2 eiφ e iπδ sin⁡πδπδ,δ=f−kX_k\approx\frac{A}{2}\,e^{i\varphi}\,e^{\,i\pi\delta}\,\frac{\sin\pi\delta}{\pi\delta},\qquad \delta=f-k
(10)

Take the size and double it, as in (A). ∣eiφ∣=∣eiπδ∣=1|e^{i\varphi}|=|e^{i\pi\delta}|=1:

2 ∣Xk∣≈A ∣sin⁡π(f−k)π (f−k)∣2\,|X_k|\approx A\,\left|\frac{\sin\pi(f-k)}{\pi\,(f-k)}\right|
(11)← leakage

Every bin gets something. Far from the tone, ∣sin⁡∣≤1|\sin|\leq1, so the leak falls only like 1/(π∣f−k∣)1/(\pi|f-k|): slowly.

The worst case is exactly halfway, δ=±12\delta=\pm\tfrac12, where the two nearest bins both read

A sin⁡(π/2)π/2=2Aπ=0.637 A(−3.9 dB)A\,\frac{\sin(\pi/2)}{\pi/2}=\frac{2A}{\pi}=0.637\,A\qquad(-3.9\ \text{dB})
(12)← the peak can read 36% low

6What it means The jump at the seam

The FFT treats the record as if it repeated. If the tone doesn’t fit, the end of one copy doesn’t meet the start of the next: there is a jump at every seam, and a jump needs many frequencies.

Slide ff, and switch the window on to see the seams close.

Why does a tone that doesn’t fit behave so differently? The DFT treats the record as one period of a repeating signal (Lesson 4). Compare the two ends of the record in (1), with φ=0\varphi=0:

x0=A,xN=Acos⁡(2πf)x_0=A,\qquad x_N=A\cos(2\pi f)
(13)

If ff is a whole number, cos⁡(2πf)=1\cos(2\pi f)=1 and the ends meet. Otherwise there is a jump at every seam. A jump is a sharp edge, and by Lesson 2, (14), sharp edges need harmonics that fall off only like 1/n1/n. That is the same slow 1/∣f−k∣1/|f-k| as in (11).

7Derivation The Hann window is three arrows

A Hann window is a constant minus a cosine, and a cosine is two arrows. Multiplying a signal by an arrow shifts its whole spectrum by one bin.

So windowing never needs a new FFT: each new bin is half the old bin, minus a quarter of each neighbour.

The fix is to fade the record in and out so the ends meet at zero. The Hann window is

wn=12(1−cos⁡2πnN)w_n=\tfrac12\Big(1-\cos\frac{2\pi n}{N}\Big)
(14)← 0 at both ends, 1 in the middle

By (B), the cosine is two arrows, so the window is three terms:

wn=12−14 e i2πn/N−14 e−i2πn/Nw_n=\tfrac12-\tfrac14\,e^{\,i2\pi n/N}-\tfrac14\,e^{-i2\pi n/N}
(15)

What does multiplying a signal by e i2πn/Ne^{\,i2\pi n/N} do to its DFT? Put it into (A):

1N∑nxn e i2πn/N e−i2πkn/N=1N∑nxn e−i2π(k−1)n/N=Xk−1\frac{1}{N}\sum_n x_n\,e^{\,i2\pi n/N}\,e^{-i2\pi kn/N}=\frac{1}{N}\sum_n x_n\,e^{-i2\pi(k-1)n/N}=X_{k-1}
(16)← it shifts everything up one bin

In the same way e−i2πn/Ne^{-i2\pi n/N} gives Xk+1X_{k+1}. So the DFT of the windowed record wnxnw_nx_n, call it YkY_k, is by (15) and (16)

Yk=12 Xk−14 Xk−1−14 Xk+1Y_k=\tfrac12\,X_k-\tfrac14\,X_{k-1}-\tfrac14\,X_{k+1}
(17)← each bin minus half the average of its neighbours

8Derivation A tone on a bin, through the window

Even a tone that fits perfectly is changed by the window: its bin reads half, and its two neighbours each pick up a quarter. Analysers multiply by 2 to put the peak right.

The board shows the corrected spectrum: the right peak, with two neighbours at half height.

Try (17) on a tone that fits the record, f=mf=m. By (5) and (6), Xm=A2eiφX_m=\tfrac{A}{2}e^{i\varphi} and every other Xk=0X_k=0:

Ym=12Xm=A4 eiφ,Ym±1=−14Xm=−A8 eiφ,all others 0Y_m=\tfrac12X_m=\tfrac{A}{4}\,e^{i\varphi},\qquad Y_{m\pm1}=-\tfrac14X_m=-\tfrac{A}{8}\,e^{i\varphi},\qquad\text{all others }0
(18)

Two things happened. First, the peak reads half what it should:

2 ∣Ym∣=A22\,|Y_m|=\tfrac{A}{2}
(19)← the window removed half the signal

So an analyser multiplies a Hann-windowed spectrum by 2, the amplitude correction. (2 is one over the average height of the window, which is 12\tfrac12 by (14).) After correction:

readingm=A,readingm±1=A2\text{reading}_m=A,\qquad \text{reading}_{m\pm1}=\tfrac{A}{2}
(20)← right peak, but two neighbours at −6 dB

Second, the tone now occupies three bins, not one. That is the price of a window: a wider peak.

9Derivation Why the far leak collapses

Without a window, neighbouring bins of a leaking tone are nearly equal. The window subtracts half the average of the neighbours from each bin, so far from the tone almost everything cancels.

Switch between the two on the board. Open circles are the formulas.

Now the tone between bins. Look again at (10). Moving one bin changes δ\delta by 1, which by the tools flips the sign of eiπδe^{i\pi\delta} and of sin⁡πδ\sin\pi\delta: two flips, so their product does not change. So across the bins

Xk≈cδ,c=A2π eiφ e iπδsin⁡πδ(the same for every bin)X_k\approx\frac{c}{\delta},\qquad c=\frac{A}{2\pi}\,e^{i\varphi}\,e^{\,i\pi\delta}\sin\pi\delta\quad\text{(the same for every bin)}
(21)

The neighbours are Xk−1≈c/(δ+1)X_{k-1}\approx c/(\delta+1) and Xk+1≈c/(δ−1)X_{k+1}\approx c/(\delta-1). Substitute in (17):

Yk≈c[12δ−14(δ+1)−14(δ−1)]Y_k\approx c\Big[\frac{1}{2\delta}-\frac{1}{4(\delta+1)}-\frac{1}{4(\delta-1)}\Big]
(22)

Combine the last two fractions: 1δ+1+1δ−1=2δδ2−1\frac{1}{\delta+1}+\frac{1}{\delta-1}=\frac{2\delta}{\delta^2-1}. Then put everything over 2δ(δ2−1)2\delta(\delta^2-1):

Yk≈c[12δ−δ2(δ2−1)]=c (δ2−1)−δ22δ(δ2−1)=−c2 δ (δ2−1)Y_k\approx c\Big[\frac{1}{2\delta}-\frac{\delta}{2(\delta^2-1)}\Big]=c\,\frac{(\delta^2-1)-\delta^2}{2\delta(\delta^2-1)}=\frac{-c}{2\,\delta\,(\delta^2-1)}
(23)← the big terms cancel

Take the size, double it as in (A), and apply the ×2 correction of (20):

readingk≈A ∣sin⁡πδ∣π ∣δ∣ ∣δ2−1∣,δ=f−k\text{reading}_k\approx A\,\frac{|\sin\pi\delta|}{\pi\,|\delta|\,|\delta^2-1|},\qquad \delta=f-k
(24)← Hann

Far from the tone this falls like 1/∣δ∣31/|\delta|^3, not 1/∣δ∣1/|\delta|. Five bins away it is about 25 times smaller than without the window.

And the worst case, halfway (δ=12\delta=\tfrac12), is much milder than (12):

A 1π⋅12⋅∣14−1∣=A0.375 π=0.849 A(−1.4 dB)A\,\frac{1}{\pi\cdot\tfrac12\cdot\big|\tfrac14-1\big|}=\frac{A}{0.375\,\pi}=0.849\,A\qquad(-1.4\ \text{dB})
(25)← 15% low at worst, not 36%

10Worked example 1 A pump at 1490 rpm, no window

A 5 mm/s vibration at 24.83 Hz, a 1-second record, no window. Bin by bin on a calculator: where the peak appears, how low it reads, and how far the leak reaches.

Worked example 1. A pump runs at 1490 rpm with a 1X vibration of A=5A=5 mm/s. The analyser takes a 1-second record with no window. What does the spectrum show?

The bins are 1/T=11/T=1 Hz apart, so the number of cycles in the record equals the frequency in hertz. From Lesson 1, (13):

f=149060=24.83 cycles in the recordf=\frac{1490}{60}=24.83\ \text{cycles in the record}
(26)← between bins 24 and 25

The top of (11) is the same for every bin, since moving one bin only flips the sign of the sine. Work it out once (calculator in radians, or 0.17×180∘=30.6∘0.17\times180^\circ=30.6^\circ):

∣sin⁡π(24.83−25)∣=∣sin⁡(−0.17π)∣=sin⁡(30.6∘)=0.509|\sin\pi(24.83-25)|=|\sin(-0.17\pi)|=\sin(30.6^\circ)=0.509
(27)

Now (11), bin by bin:

k=24:δ=24.83−24=0.83,2∣X24∣≈5×0.509π×0.83=5×0.5092.6075=0.976 mm/sk=24:\quad \delta=24.83-24=0.83,\qquad 2|X_{24}|\approx5\times\frac{0.509}{\pi\times0.83}=5\times\frac{0.509}{2.6075}=0.976\ \text{mm/s}
k=25:δ=24.83−25=−0.17,2∣X25∣≈5×0.509π×0.17=5×0.5090.5341=4.766 mm/sk=25:\quad \delta=24.83-25=-0.17,\qquad 2|X_{25}|\approx5\times\frac{0.509}{\pi\times0.17}=5\times\frac{0.509}{0.5341}=4.766\ \text{mm/s}
← the tallest bin
k=26:δ=24.83−26=−1.17,2∣X26∣≈5×0.509π×1.17=5×0.5093.6757=0.692 mm/sk=26:\quad \delta=24.83-26=-1.17,\qquad 2|X_{26}|\approx5\times\frac{0.509}{\pi\times1.17}=5\times\frac{0.509}{3.6757}=0.692\ \text{mm/s}
k=30:δ=24.83−30=−5.17,2∣X30∣≈5×0.509π×5.17=5×0.50916.242=0.157 mm/sk=30:\quad \delta=24.83-30=-5.17,\qquad 2|X_{30}|\approx5\times\frac{0.509}{\pi\times5.17}=5\times\frac{0.509}{16.242}=0.157\ \text{mm/s}
← 5 bins away

So the analyser shows its tallest peak at 25 Hz, reading

4.77 mm/s instead of 5.00:4.766−55=−4.7%4.77\ \text{mm/s instead of }5.00:\qquad \frac{4.766-5}{5}=-4.7\%
(28)← low, and at the wrong frequency

with false peaks of 0.98 and 0.69 mm/s beside it, and 0.16 mm/s still showing five bins away. A small real component near 30 Hz would be hidden under that.

11Worked example 2 The same pump, with a Hann window

Same signal, same record, Hann window on. The peak reads closer to 5 mm/s and the far bins drop out, at the cost of a wider peak.

Worked example 2. The same pump and the same record, now with a Hann window (and the analyser’s ×2 correction).

Use (24) with the same δ\delta values, and ∣sin⁡πδ∣|\sin\pi\delta| from (27). The only new part is ∣δ2−1∣|\delta^2-1|:

k=24:reading≈5×0.509π×0.83×∣0.6889−1∣=5×0.5090.8112=3.138 mm/sk=24:\quad \text{reading}\approx5\times\frac{0.509}{\pi\times0.83\times|0.6889-1|}=5\times\frac{0.509}{0.8112}=3.138\ \text{mm/s}
k=25:reading≈5×0.509π×0.17×∣0.0289−1∣=5×0.5090.5186=4.908 mm/sk=25:\quad \text{reading}\approx5\times\frac{0.509}{\pi\times0.17\times|0.0289-1|}=5\times\frac{0.509}{0.5186}=4.908\ \text{mm/s}
← the tallest bin
k=26:reading≈5×0.509π×1.17×∣1.3689−1∣=5×0.5091.356=1.877 mm/sk=26:\quad \text{reading}\approx5\times\frac{0.509}{\pi\times1.17\times|1.3689-1|}=5\times\frac{0.509}{1.356}=1.877\ \text{mm/s}
k=30:reading≈5×0.509π×5.17×∣26.7289−1∣=5×0.509417.8897=0.0061 mm/sk=30:\quad \text{reading}\approx5\times\frac{0.509}{\pi\times5.17\times|26.7289-1|}=5\times\frac{0.509}{417.8897}=0.0061\ \text{mm/s}
← 5 bins away

Compare with example 1:

peak: 4.91 mm/s,4.908−55=−1.8%\text{peak: }4.91\ \text{mm/s},\qquad \frac{4.908-5}{5}=-1.8\%
(29)← was -4.7%
5 bins away: 0.15670.0061=26 times lower(−28 dB)\text{5 bins away: }\frac{0.1567}{0.0061}=26\ \text{times lower}\qquad(-28\ \text{dB})
(30)← the far leak is gone

The price shows in bins 24 and 26: 3.14 and 1.88 mm/s, higher than before. The peak is wider, as (20) said it would be. For reading a machine spectrum that is a good trade: the amplitude is closer and nothing is buried.

12Your turn Try it with a calculator

Your turn. In the interactive lesson above, this step gives you a new signal each time, checks your answers and writes out the full working, line by line.

13Summary On one card

Four boxed results, each derived above. A tone on a bin is exact; a tone between bins leaks like 1/δ1/\delta; a Hann window turns that into 1/δ31/\delta^3 and is corrected by ×2.

Next: Lesson 6, wavelets, for signals that change over time.

Everything in this lesson on one card (δ=f−k\delta=f-k is the distance from the tone to the bin, in bins):

δ a whole number ⇒ one bin reads A, the rest read 0\delta\ \text{a whole number}\ \Rightarrow\ \text{one bin reads }A,\ \text{the rest read }0
← from (5), (6)
no window:2∣Xk∣≈A ∣sin⁡πδπδ∣worst case 0.637A\text{no window:}\quad 2|X_k|\approx A\,\left|\frac{\sin\pi\delta}{\pi\delta}\right|\qquad\text{worst case }0.637A
← from (11), (12)
Hann:Yk=12Xk−14Xk−1−14Xk+1,correct by ×2\text{Hann:}\quad Y_k=\tfrac12X_k-\tfrac14X_{k-1}-\tfrac14X_{k+1},\qquad \text{correct by }\times2
← from (17), (20)
Hann:readingk≈A ∣sin⁡πδ∣π∣δ∣ ∣δ2−1∣worst case 0.849A\text{Hann:}\quad \text{reading}_k\approx A\,\frac{|\sin\pi\delta|}{\pi|\delta|\,|\delta^2-1|}\qquad\text{worst case }0.849A
← from (24), (25)

Leakage falls like 1/δ1/\delta without a window and like 1/δ31/\delta^3 with a Hann window. The price is a peak three bins wide.