Lab · Lesson 4

An FFT by hand

Derive the FFT from the Fourier series, line by line, then solve two examples on a calculator: real and imaginary parts, size, phase and the mirror.

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

1Goal Where we are going

An analyser turns 8, 1024 or 65 536 samples into a spectrum. This lesson derives the formula it uses, from scratch, the way you would in a maths class.

Then we solve two examples on a calculator, every operation written out, and you try one yourself.

By the end of this lesson we will have derived, line by line, the formula an FFT computes for every frequency bin:

Xn=1N∑k=0N−1xk e−i 2πnk/NX_n=\frac{1}{N}\sum_{k=0}^{N-1}x_k\,e^{-i\,2\pi nk/N}
← where we are heading

and what its two parts mean for a vibration: the real and imaginary parts, the size you read on an analyser, and the phase.

Xn=12 (an−i bn),2∣Xn∣=cn,θn=arg⁡XnX_n=\tfrac12\,(a_n-i\,b_n),\qquad 2|X_n|=c_n,\qquad \theta_n=\arg X_n

Then we use it twice on a calculator, with every operation shown.

2What we already know The tools

Four facts carry the whole derivation: the Fourier series (1), three product-to-sum identities (2)–(4), zero net area over whole cycles (5)–(6), and Euler’s formula (7).

On the board: any whole number of cycles has as much area above the line as below. Change the number of cycles.

As we know, any signal that repeats every TT seconds can be written as a Fourier series: a constant plus cosines and sines at whole multiples of the running speed:

x(t)=a0+∑m=1∞[amcos⁡(mω0t)+bmsin⁡(mω0t)],ω0=2πTx(t)=a_0+\sum_{m=1}^{\infty}\big[a_m\cos(m\omega_0 t)+b_m\sin(m\omega_0 t)\big],\qquad \omega_0=\frac{2\pi}{T}
(1)← the harmonics

From trigonometry, a product of two cosines or sines turns into a sum:

cos⁡Acos⁡B=12[cos⁡(A−B)+cos⁡(A+B)]\cos A\cos B=\tfrac12\big[\cos(A-B)+\cos(A+B)\big]
(2)
sin⁡Acos⁡B=12[sin⁡(A+B)+sin⁡(A−B)]\sin A\cos B=\tfrac12\big[\sin(A+B)+\sin(A-B)\big]
(3)
sin⁡Asin⁡B=12[cos⁡(A−B)−cos⁡(A+B)]\sin A\sin B=\tfrac12\big[\cos(A-B)-\cos(A+B)\big]
(4)

Over one period, a whole number p≠0p\neq0 of cosine or sine cycles has zero net area (the board shows it):

∫0Tcos⁡(p ω0t) dt=0,∫0Tsin⁡(p ω0t) dt=0(p=±1,±2,… )\int_0^T\cos(p\,\omega_0 t)\,dt=0,\qquad \int_0^T\sin(p\,\omega_0 t)\,dt=0\qquad (p=\pm1,\pm2,\dots)
(5)← ups and downs cancel

And for p=0p=0, cos⁡0=1\cos 0=1 and sin⁡0=0\sin 0=0:

∫0Tcos⁡(0) dt=∫0T1 dt=T\int_0^T\cos(0)\,dt=\int_0^T 1\,dt=T
(6)

Finally, Euler’s formula:

eiθ=cos⁡θ+isin⁡θ,e−iθ=cos⁡θ−isin⁡θe^{i\theta}=\cos\theta+i\sin\theta,\qquad e^{-i\theta}=\cos\theta-i\sin\theta
(7)

3Derivation Orthogonality

The key fact: multiply two different harmonics and the result has zero net area over a period. Multiply a harmonic by itself and you get T/2T/2.

Set nn and mm on the board. The orange curve is their product; the green and red areas cancel unless n=mn=m.

Take two harmonics, nn and mm (whole numbers, both at least 1), and integrate their product over one period. Using (2) with A=nω0tA=n\omega_0t, B=mω0tB=m\omega_0t:

∫0Tcos⁡(nω0t)cos⁡(mω0t) dt=12∫0Tcos⁡((n−m)ω0t)dt+12∫0Tcos⁡((n+m)ω0t)dt\int_0^T\cos(n\omega_0t)\cos(m\omega_0t)\,dt=\tfrac12\int_0^T\cos\big((n-m)\omega_0t\big)dt+\tfrac12\int_0^T\cos\big((n+m)\omega_0t\big)dt
(8)

n+m≥2n+m\geq2, so the second integral is 0 by (5). The first is also 0 by (5), unless n=mn=m: then it is cos⁡0\cos 0, which gives TT by (6). So

∫0Tcos⁡(nω0t)cos⁡(mω0t) dt={T/2,n=m0,n≠m\int_0^T\cos(n\omega_0t)\cos(m\omega_0t)\,dt=\begin{cases}T/2, & n=m\\ 0, & n\neq m\end{cases}
(9)

Exactly the same steps with (4) and (3):

∫0Tsin⁡(nω0t)sin⁡(mω0t) dt={T/2,n=m0,n≠m\int_0^T\sin(n\omega_0t)\sin(m\omega_0t)\,dt=\begin{cases}T/2, & n=m\\ 0, & n\neq m\end{cases}
(10)
∫0Tsin⁡(nω0t)cos⁡(mω0t) dt=0for all n,m\int_0^T\sin(n\omega_0t)\cos(m\omega_0t)\,dt=0\quad\text{for all }n,m
(11)← by (3): both terms are sines, 0 by (5)

This is called orthogonality: two different harmonics, or a sine and a cosine, multiply to zero net area. Only a harmonic times itself survives.

4Derivation Picking out one harmonic

Multiply the whole signal by cos⁡(nω0t)\cos(n\omega_0t) and integrate. By orthogonality, every harmonic except the nnth drops out, which leaves ana_n.

On the board, the signal from example 1 times cos⁡(nω0t)\cos(n\omega_0t) or sin⁡(nω0t)\sin(n\omega_0t). The net area, times 2/T2/T, is the coefficient.

Multiply both sides of (1) by cos⁡(nω0t)\cos(n\omega_0t), for one chosen n≥1n\geq1, and integrate over one period:

∫0Txcos⁡(nω0t) dt=a0 ⁣∫0T ⁣cos⁡(nω0t) dt+∑m[am ⁣∫0T ⁣cos⁡(mω0t)cos⁡(nω0t) dt+bm ⁣∫0T ⁣sin⁡(mω0t)cos⁡(nω0t) dt]\int_0^T x\cos(n\omega_0t)\,dt=a_0\!\int_0^T\!\cos(n\omega_0t)\,dt+\sum_m\Big[a_m\!\int_0^T\!\cos(m\omega_0t)\cos(n\omega_0t)\,dt+b_m\!\int_0^T\!\sin(m\omega_0t)\cos(n\omega_0t)\,dt\Big]
(12)

Term by term: the a0a_0 term is 0 by (5). Every bmb_m term is 0 by (11). Every ama_m term is 0 by (9), except m=nm=n, which gives an⋅T/2a_n\cdot T/2:

∫0Tx(t)cos⁡(nω0t) dt=an T2\int_0^T x(t)\cos(n\omega_0t)\,dt=a_n\,\frac{T}{2}
(13)← one term survives

Divide both sides by T/2T/2:

an=2T∫0Tx(t)cos⁡(nω0t) dta_n=\frac{2}{T}\int_0^T x(t)\cos(n\omega_0t)\,dt
(14)

Multiplying (1) by sin⁡(nω0t)\sin(n\omega_0t) instead, (10) and (11) leave only bnb_n:

bn=2T∫0Tx(t)sin⁡(nω0t) dtb_n=\frac{2}{T}\int_0^T x(t)\sin(n\omega_0t)\,dt
(15)

And integrating (1) as it is, (5) removes every harmonic and (6) leaves a0Ta_0T:

a0=1T∫0Tx(t) dta_0=\frac{1}{T}\int_0^T x(t)\,dt
(16)← the average (DC)

5Derivation One complex number

Euler’s formula combines the cosine integral and the sine integral into one complex number, XnX_n. Its real part is half of ana_n; its imaginary part is minus half of bnb_n.

Written as one cosine, cncos⁡(nω0t+θn)c_n\cos(n\omega_0t+\theta_n), the harmonic’s size is twice the arrow’s length and its phase is the arrow’s angle.

That is two integrals per harmonic. Euler’s formula packs them into one complex number. Define

Xn=1T∫0Tx(t) e−i nω0t dtX_n=\frac{1}{T}\int_0^T x(t)\,e^{-i\,n\omega_0 t}\,dt
(17)← the winding machine from the video

Substitute e−iθe^{-i\theta} from (7) with θ=nω0t\theta=n\omega_0t, and split the integral:

Xn=1T∫0Tx(t)cos⁡(nω0t) dt  −  i 1T∫0Tx(t)sin⁡(nω0t) dtX_n=\frac{1}{T}\int_0^T x(t)\cos(n\omega_0t)\,dt\;-\;i\,\frac{1}{T}\int_0^T x(t)\sin(n\omega_0t)\,dt
(18)

Compare with (14) and (15): 1T\tfrac1T is half of 2T\tfrac2T, so each integral is half a coefficient:

Xn=12 an−i 12 bn=12 (an−i bn)X_n=\tfrac12\,a_n-i\,\tfrac12\,b_n=\tfrac12\,(a_n-i\,b_n)
(19)← Re: cosine, Im: minus sine

Now the size and the phase. Write the nnth harmonic as one cosine with amplitude cnc_n and phase θn\theta_n, and expand it with cos⁡(A+B)=cos⁡Acos⁡B−sin⁡Asin⁡B\cos(A+B)=\cos A\cos B-\sin A\sin B:

cncos⁡(nω0t+θn)=cncos⁡θncos⁡(nω0t)−cnsin⁡θnsin⁡(nω0t)c_n\cos(n\omega_0t+\theta_n)=c_n\cos\theta_n\cos(n\omega_0t)-c_n\sin\theta_n\sin(n\omega_0t)
(20)

Match the cosine and sine terms with ancos⁡+bnsin⁡a_n\cos+b_n\sin in (1):

an=cncos⁡θn,bn=−cnsin⁡θna_n=c_n\cos\theta_n,\qquad b_n=-c_n\sin\theta_n
(21)

Square and add (using cos⁡2+sin⁡2=1\cos^2+\sin^2=1), then divide the second by the first, and compare with (19):

cn=an2+bn2=2 ∣Xn∣,tan⁡θn=−bnan=Im⁡XnRe⁡Xnc_n=\sqrt{a_n^2+b_n^2}=2\,|X_n|,\qquad \tan\theta_n=\frac{-b_n}{a_n}=\frac{\operatorname{Im}X_n}{\operatorname{Re}X_n}
(22)← θₙ is the angle of Xₙ

6Derivation From the integral to a sum

An analyser has samples, not a curve. Replace the integral by NN thin rectangles, one per sample, and it becomes the DFT, the formula every FFT computes.

On the board, the area under x(t)cos⁡(ω0t)x(t)\cos(\omega_0t) and the 8 rectangles give the same answer.

An analyser never has the curve, only samples. Take NN equally spaced samples in one period:

tk=kTN,xk=x(tk),dt→TN,k=0,1,…,N−1t_k=\frac{kT}{N},\qquad x_k=x(t_k),\qquad dt\to\frac{T}{N},\qquad k=0,1,\dots,N-1
(23)

In (17), the integral becomes a sum of NN thin rectangles, each T/NT/N wide:

Xn=1T∑k=0N−1xk e−i nω0 kT/N⋅TNX_n=\frac{1}{T}\sum_{k=0}^{N-1}x_k\,e^{-i\,n\omega_0\,kT/N}\cdot\frac{T}{N}
(24)

The TT’s cancel, and ω0T=2π\omega_0T=2\pi from (1):

Xn=1N∑k=0N−1xk e−i 2πnk/NX_n=\frac{1}{N}\sum_{k=0}^{N-1}x_k\,e^{-i\,2\pi nk/N}
(25)← the DFT. An FFT is a fast way to compute it.

If every harmonic in the signal lies below N/2N/2, sampled sines and cosines are orthogonal too, and (25) gives exactly the same XnX_n as the integral.

Split (25) with (7), as in (18), into two sums you can do on a calculator, with θk=2πk/N\theta_k=2\pi k/N:

Re⁡Xn=1N∑kxkcos⁡(nθk)\operatorname{Re}X_n=\frac{1}{N}\sum_k x_k\cos(n\theta_k)
(26)
Im⁡Xn=−1N∑kxksin⁡(nθk)\operatorname{Im}X_n=-\frac{1}{N}\sum_k x_k\sin(n\theta_k)
(27)← note the minus sign

7Derivation Why half is a mirror

Bin N−nN-n is bin nn wound the other way: the complex conjugate. It carries no new information, so analysers drop the top half and double the rest.

Slide through the bins: 7 mirrors 1, 6 mirrors 2.

What about the bins above N/2N/2? Put n→N−nn\to N-n in (25) and split the exponent:

XN−n=1N∑kxk e−i2π(N−n)k/N=1N∑kxk e−i2πk e+i2πnk/NX_{N-n}=\frac{1}{N}\sum_k x_k\,e^{-i2\pi(N-n)k/N}=\frac{1}{N}\sum_k x_k\,e^{-i2\pi k}\,e^{+i2\pi nk/N}
(28)

kk is a whole number, so by (7) e−i2πk=cos⁡2πk−isin⁡2πk=1−0=1e^{-i2\pi k}=\cos2\pi k-i\sin2\pi k=1-0=1:

XN−n=1N∑kxk e+i2πnk/NX_{N-n}=\frac{1}{N}\sum_k x_k\,e^{+i2\pi nk/N}
(29)

The samples xkx_k are real, so this is (25) with the sign of ii flipped: the complex conjugate.

XN−n=Xn‾X_{N-n}=\overline{X_n}
(30)← same size, opposite angle

So the top half adds nothing new. Each harmonic’s size cnc_n is shared between XnX_n and its mirror, which is why the peak is 2∣Xn∣2|X_n| in (22). Bin 0 is its own partner, so it is not doubled: by (16) and (17), X0=a0X_0=a_0.

8What it means Wind the samples

Equation (25) as a picture. Each sample becomes an arrow at angle −2πnk/8-2\pi nk/8, and the orange dot is their average: XnX_n.

Try n=1n=1 and n=2n=2 (the signal has those), then n=3n=3 (it doesn’t).

Read (25) as a picture: each sample xkx_k becomes an arrow of length xkx_k at angle −2πnk/N-2\pi nk/N, and XnX_n is the average of the NN arrows (the orange dot).

When nn matches a harmonic in the signal, the arrows pile up on one side and the dot moves out. Otherwise orthogonality, (9) to (11), makes them cancel.

9Worked example 1 Take the samples

A signal with a 1X part (cosine and sine) and a 2X cosine. Sample it 8 times per turn, at 45° steps.

Every sample is worked out in full below the board.

Worked example 1. Find the spectrum of

x(t)=0.6cos⁡(ω0t)+0.8sin⁡(ω0t)+0.5cos⁡(2ω0t)x(t)=0.6\cos(\omega_0 t)+0.8\sin(\omega_0 t)+0.5\cos(2\omega_0 t)
(31)← a₁ = 0.6, b₁ = 0.8, a₂ = 0.5

Use N=8N=8. By (23), θk=2πk/8\theta_k=2\pi k/8: steps of 45°.

θk=0∘, 45∘, 90∘, 135∘, 180∘, 225∘, 270∘, 315∘\theta_k=0^\circ,\ 45^\circ,\ 90^\circ,\ 135^\circ,\ 180^\circ,\ 225^\circ,\ 270^\circ,\ 315^\circ
(32)

Put each angle into (31): xk=0.6cos⁡θk+0.8sin⁡θk+0.5cos⁡2θkx_k=0.6\cos\theta_k+0.8\sin\theta_k+0.5\cos2\theta_k. Every operation (4 decimal places):

x0=0.6(1)+0.8(0)+0.5(1)=0.6+0+0.5=1.1x_0=0.6(1)+0.8(0)+0.5(1)=0.6+0+0.5=1.1
θ = 0°, 2θ = 0°
x1=0.6(0.7071)+0.8(0.7071)+0.5(0)=0.4243+0.5657+0=0.9899x_1=0.6(0.7071)+0.8(0.7071)+0.5(0)=0.4243+0.5657+0=0.9899
θ = 45°, 2θ = 90°
x2=0.6(0)+0.8(1)+0.5(−1)=0+0.8+(−0.5)=0.3x_2=0.6(0)+0.8(1)+0.5(-1)=0+0.8+(-0.5)=0.3
θ = 90°, 2θ = 180°
x3=0.6(−0.7071)+0.8(0.7071)+0.5(0)=−0.4243+0.5657+0=0.1414x_3=0.6(-0.7071)+0.8(0.7071)+0.5(0)=-0.4243+0.5657+0=0.1414
θ = 135°, 2θ = 270°
x4=0.6(−1)+0.8(0)+0.5(1)=−0.6+0+0.5=−0.1x_4=0.6(-1)+0.8(0)+0.5(1)=-0.6+0+0.5=-0.1
θ = 180°, 2θ = 0°
x5=0.6(−0.7071)+0.8(−0.7071)+0.5(0)=−0.4243+(−0.5657)+0=−0.9899x_5=0.6(-0.7071)+0.8(-0.7071)+0.5(0)=-0.4243+(-0.5657)+0=-0.9899
θ = 225°, 2θ = 90°
x6=0.6(0)+0.8(−1)+0.5(−1)=0+(−0.8)+(−0.5)=−1.3x_6=0.6(0)+0.8(-1)+0.5(-1)=0+(-0.8)+(-0.5)=-1.3
θ = 270°, 2θ = 180°
x7=0.6(0.7071)+0.8(−0.7071)+0.5(0)=0.4243+(−0.5657)+0=−0.1414x_7=0.6(0.7071)+0.8(-0.7071)+0.5(0)=0.4243+(-0.5657)+0=-0.1414
θ = 315°, 2θ = 270°

10Worked example 1 Bin 1, by hand

Multiply each sample by cos⁡θk\cos\theta_k and sin⁡θk\sin\theta_k, add the columns, divide by 8. Out come the real and imaginary parts, then the size and the phase.

The board shows the same result as the average of 8 arrows.

Bin n=1n=1. Multiply each sample by cos⁡θk\cos\theta_k and by sin⁡θk\sin\theta_k:

kθkxkcos⁡sin⁡xkcos⁡xksin⁡00∘1.1101.10145∘0.98990.70710.70710.70.7290∘0.30100.33135∘0.1414−0.70710.7071−0.10.14180∘−0.1−100.105225∘−0.9899−0.7071−0.70710.70.76270∘−1.30−101.37315∘−0.14140.7071−0.7071−0.10.1\begin{array}{c|c|r|r|r|r|r} k & \theta_k & x_k & \cos & \sin & x_k\cos & x_k\sin \\ \hline 0 & 0^\circ & 1.1 & 1 & 0 & 1.1 & 0 \\ 1 & 45^\circ & 0.9899 & 0.7071 & 0.7071 & 0.7 & 0.7 \\ 2 & 90^\circ & 0.3 & 0 & 1 & 0 & 0.3 \\ 3 & 135^\circ & 0.1414 & -0.7071 & 0.7071 & -0.1 & 0.1 \\ 4 & 180^\circ & -0.1 & -1 & 0 & 0.1 & 0 \\ 5 & 225^\circ & -0.9899 & -0.7071 & -0.7071 & 0.7 & 0.7 \\ 6 & 270^\circ & -1.3 & 0 & -1 & 0 & 1.3 \\ 7 & 315^\circ & -0.1414 & 0.7071 & -0.7071 & -0.1 & 0.1 \end{array}

Add each product column, term by term:

∑kxk$trigθk=1.1+0.7+0+(−0.1)+0.1+0.7+0+(−0.1)=2.4\sum_k x_k\${trig} \theta_k=1.1+0.7+0+(-0.1)+0.1+0.7+0+(-0.1)=2.4
(33)
∑kxk$trigθk=0+0.7+0.3+0.1+0+0.7+1.3+0.1=3.2\sum_k x_k\${trig} \theta_k=0+0.7+0.3+0.1+0+0.7+1.3+0.1=3.2
(34)

Divide by N=8N=8 using (26) and (27). Mind the minus sign in (27):

Re⁡X1=2.48=0.3,Im⁡X1=−3.28=−0.4\operatorname{Re}X_1=\frac{2.4}{8}=0.3,\qquad \operatorname{Im}X_1=-\frac{3.2}{8}=-0.4
(35)
X1=0.3−0.4 iX_1=0.3-0.4\,i
(36)← one bin, two numbers

The size, by (22):

2∣X1∣=20.32+(−0.4)2=20.09+0.16=20.25=2(0.5)=1.02|X_1|=2\sqrt{0.3^2+(-0.4)^2}=2\sqrt{0.09+0.16}=2\sqrt{0.25}=2(0.5)=1.0
(37)← the 1X peak

The phase, by (22). Re is positive and Im is negative, so the arrow is in the fourth quadrant and the calculator’s answer is the right one:

θ1=tan⁡−1(−0.40.3)=tan⁡−1(−1.3333)=−53.13∘\theta_1=\tan^{-1}\Big(\frac{-0.4}{0.3}\Big)=\tan^{-1}(-1.3333)=-53.13^\circ
(38)

Check with (19), using a1=0.6, b1=0.8a_1=0.6,\ b_1=0.8 from (31):

12 (0.6−0.8 i)=0.3−0.4 i ✓\tfrac12\,(0.6-0.8\,i)=0.3-0.4\,i\ \checkmark
← the FFT found a₁ and b₁

So the 1X part of (31) is 1.0cos⁡(ω0t−53.13∘)1.0\cos(\omega_0t-53.13^\circ): size from (37), timing from (38).

11Worked example 1 Bins 2, 3 and 7

Bin 2 finds the 2X cosine. Bin 3 finds nothing, because the products cancel. Bin 7 needs no work at all: it is the mirror of bin 1.

Slide through all eight bins.

Bin n=2n=2: the angles are now 2θk2\theta_k, steps of 90°.

k2θkxkcos⁡sin⁡xkcos⁡xksin⁡00∘1.1101.10190∘0.98990100.98992180∘0.3−10−0.303270∘0.14140−10−0.141440∘−0.110−0.10590∘−0.9899010−0.98996180∘−1.3−101.307270∘−0.14140−100.1414\begin{array}{c|c|r|r|r|r|r} k & 2\theta_k & x_k & \cos & \sin & x_k\cos & x_k\sin \\ \hline 0 & 0^\circ & 1.1 & 1 & 0 & 1.1 & 0 \\ 1 & 90^\circ & 0.9899 & 0 & 1 & 0 & 0.9899 \\ 2 & 180^\circ & 0.3 & -1 & 0 & -0.3 & 0 \\ 3 & 270^\circ & 0.1414 & 0 & -1 & 0 & -0.1414 \\ 4 & 0^\circ & -0.1 & 1 & 0 & -0.1 & 0 \\ 5 & 90^\circ & -0.9899 & 0 & 1 & 0 & -0.9899 \\ 6 & 180^\circ & -1.3 & -1 & 0 & 1.3 & 0 \\ 7 & 270^\circ & -0.1414 & 0 & -1 & 0 & 0.1414 \end{array}
∑kxk$trig2θk=1.1+0+(−0.3)+0+(−0.1)+0+1.3+0=2\sum_k x_k\${trig} 2\theta_k=1.1+0+(-0.3)+0+(-0.1)+0+1.3+0=2
(39)
∑kxk$trig2θk=0+0.9899+0+(−0.1414)+0+(−0.9899)+0+0.1414=0\sum_k x_k\${trig} 2\theta_k=0+0.9899+0+(-0.1414)+0+(-0.9899)+0+0.1414=0
(40)
X2=28−i 08=0.25,2∣X2∣=0.5,θ2=0∘X_2=\frac{2}{8}-i\,\frac{0}{8}=0.25,\qquad 2|X_2|=0.5,\qquad \theta_2=0^\circ
(41)← a pure cosine of 0.5 at 2X, as in (31) ✓

Bin n=3n=3: steps of 135°. There is no 3X in (31), so the products cancel, exactly as orthogonality (9) to (11) says:

∑kxk$trig3θk=1.1+(−0.7)+0+0.1+0.1+(−0.7)+0+0.1=0\sum_k x_k\${trig} 3\theta_k=1.1+(-0.7)+0+0.1+0.1+(-0.7)+0+0.1=0
∑kxk$trig3θk=0+0.7+(−0.3)+0.1+0+0.7+(−1.3)+0.1=0\sum_k x_k\${trig} 3\theta_k=0+0.7+(-0.3)+0.1+0+0.7+(-1.3)+0.1=0
X3=08−i 08=0X_3=\frac{0}{8}-i\,\frac{0}{8}=0
(42)

Bin n=7=N−1n=7=N-1: no need to add anything up. By the mirror rule (30), with (36):

X7=X1‾=0.3+0.4 iX_7=\overline{X_1}=0.3+0.4\,i
(43)← same size, opposite angle

The one-sided spectrum an analyser shows: a peak of 1.0 at 1X with phase −53.13°, and 0.5 at 2X with phase 0°.

12Worked example 2 An offset and a phase

This time the signal comes as an amplitude and a phase, plus a small offset, the way a sensor often reads. First rewrite it in the form (1), then sample it.

Worked example 2. A sensor with a small offset reads

x(t)=0.4+2cos⁡(ω0t−60∘)x(t)=0.4+2\cos(\omega_0 t-60^\circ)
(44)← offset, plus 1X with a phase

This is not yet in the form (1). Expand with cos⁡(A−B)=cos⁡Acos⁡B+sin⁡Asin⁡B\cos(A-B)=\cos A\cos B+\sin A\sin B:

2cos⁡(ω0t−60∘)=2cos⁡60∘cos⁡(ω0t)+2sin⁡60∘sin⁡(ω0t)=2(0.5)cos⁡(ω0t)+2(0.8660)sin⁡(ω0t)2\cos(\omega_0t-60^\circ)=2\cos60^\circ\cos(\omega_0t)+2\sin60^\circ\sin(\omega_0t)=2(0.5)\cos(\omega_0t)+2(0.8660)\sin(\omega_0t)
(45)
x(t)=0.4+1.0cos⁡(ω0t)+1.7321sin⁡(ω0t)x(t)=0.4+1.0\cos(\omega_0t)+1.7321\sin(\omega_0t)
(46)← a₀ = 0.4, a₁ = 1.0, b₁ = 1.7321

So, before doing any sums, (19) and (16) predict

X0=0.4,X1=12(1.0−1.7321 i)=0.5−0.8660 iX_0=0.4,\qquad X_1=\tfrac12(1.0-1.7321\,i)=0.5-0.8660\,i
(47)← now check it the hard way

Sample at the angles (32): xk=0.4+2cos⁡(θk−60∘)x_k=0.4+2\cos(\theta_k-60^\circ). Every operation:

x0=0.4+2cos⁡(−60∘)=0.4+2(0.5)=0.4+1=1.4x_0=0.4+2\cos(-60^\circ)=0.4+2(0.5)=0.4+1=1.4
x1=0.4+2cos⁡(−15∘)=0.4+2(0.9659)=0.4+1.9319=2.3319x_1=0.4+2\cos(-15^\circ)=0.4+2(0.9659)=0.4+1.9319=2.3319
x2=0.4+2cos⁡(30∘)=0.4+2(0.866)=0.4+1.7321=2.1321x_2=0.4+2\cos(30^\circ)=0.4+2(0.866)=0.4+1.7321=2.1321
x3=0.4+2cos⁡(75∘)=0.4+2(0.2588)=0.4+0.5176=0.9176x_3=0.4+2\cos(75^\circ)=0.4+2(0.2588)=0.4+0.5176=0.9176
x4=0.4+2cos⁡(120∘)=0.4+2(−0.5)=0.4+(−1)=−0.6x_4=0.4+2\cos(120^\circ)=0.4+2(-0.5)=0.4+(-1)=-0.6
x5=0.4+2cos⁡(165∘)=0.4+2(−0.9659)=0.4+(−1.9319)=−1.5319x_5=0.4+2\cos(165^\circ)=0.4+2(-0.9659)=0.4+(-1.9319)=-1.5319
x6=0.4+2cos⁡(210∘)=0.4+2(−0.866)=0.4+(−1.7321)=−1.3321x_6=0.4+2\cos(210^\circ)=0.4+2(-0.866)=0.4+(-1.7321)=-1.3321
x7=0.4+2cos⁡(255∘)=0.4+2(−0.2588)=0.4+(−0.5176)=−0.1176x_7=0.4+2\cos(255^\circ)=0.4+2(-0.2588)=0.4+(-0.5176)=-0.1176

13Worked example 2 Bins 0 and 1

Bin 0 is just the average: the offset. It has no mirror, so it isn’t doubled. Bin 1 gives back the size 2.0 and the phase −60°.

Bin n=0n=0: every angle is 0, cos⁡0=1\cos0=1 and sin⁡0=0\sin0=0, so (26) is just the average of the samples:

X0=18(1.4+2.3319+2.1321+0.9176+(−0.6)+(−1.5319)+(−1.3321)+(−0.1176))=3.28=0.4X_0=\frac{1}{8}\big(1.4+2.3319+2.1321+0.9176+(-0.6)+(-1.5319)+(-1.3321)+(-0.1176)\big)=\frac{3.2}{8}=0.4
(48)← the offset a₀ (no mirror, not doubled)

Bin n=1n=1:

kθkxkcos⁡sin⁡xkcos⁡xksin⁡00∘1.4101.40145∘2.33190.70710.70711.64891.6489290∘2.13210102.13213135∘0.9176−0.70710.7071−0.64890.64894180∘−0.6−100.605225∘−1.5319−0.7071−0.70711.08321.08326270∘−1.33210−101.33217315∘−0.11760.7071−0.7071−0.08320.0832\begin{array}{c|c|r|r|r|r|r} k & \theta_k & x_k & \cos & \sin & x_k\cos & x_k\sin \\ \hline 0 & 0^\circ & 1.4 & 1 & 0 & 1.4 & 0 \\ 1 & 45^\circ & 2.3319 & 0.7071 & 0.7071 & 1.6489 & 1.6489 \\ 2 & 90^\circ & 2.1321 & 0 & 1 & 0 & 2.1321 \\ 3 & 135^\circ & 0.9176 & -0.7071 & 0.7071 & -0.6489 & 0.6489 \\ 4 & 180^\circ & -0.6 & -1 & 0 & 0.6 & 0 \\ 5 & 225^\circ & -1.5319 & -0.7071 & -0.7071 & 1.0832 & 1.0832 \\ 6 & 270^\circ & -1.3321 & 0 & -1 & 0 & 1.3321 \\ 7 & 315^\circ & -0.1176 & 0.7071 & -0.7071 & -0.0832 & 0.0832 \end{array}
∑kxk$trigθk=1.4+1.6489+0+(−0.6489)+0.6+1.0832+0+(−0.0832)=4\sum_k x_k\${trig} \theta_k=1.4+1.6489+0+(-0.6489)+0.6+1.0832+0+(-0.0832)=4
(49)
∑kxk$trigθk=0+1.6489+2.1321+0.6489+0+1.0832+1.3321+0.0832=6.9282\sum_k x_k\${trig} \theta_k=0+1.6489+2.1321+0.6489+0+1.0832+1.3321+0.0832=6.9282
(50)
Re⁡X1=48=0.5,Im⁡X1=−6.92828=−0.866\operatorname{Re}X_1=\frac{4}{8}=0.5,\qquad \operatorname{Im}X_1=-\frac{6.9282}{8}=-0.866
(51)

Size and phase by (22). Fourth quadrant again (Re > 0, Im < 0):

2∣X1∣=20.52+(−0.866)2=20.25+0.75=21=2.02|X_1|=2\sqrt{0.5^2+(-0.866)^2}=2\sqrt{0.25+0.75}=2\sqrt{1}=2.0
(52)
θ1=tan⁡−1(−0.8660.5)=tan⁡−1(−1.7321)=−60∘\theta_1=\tan^{-1}\Big(\frac{-0.866}{0.5}\Big)=\tan^{-1}(-1.7321)=-60^\circ
(53)

Both match (44): from 8 numbers the FFT recovers the offset 0.4, the 1X size 2.0 and the phase −60°. ✓

14Your 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.

15Summary On one card

Four boxed results, each derived above: the DFT, what its real and imaginary parts are, how size and phase come out of it, and why half of it is a mirror.

Next lesson: what happens when the signal doesn’t fit a whole number of times in the record. That is leakage.

Everything in this lesson on one card:

Xn=1N∑k=0N−1xk e−i2πnk/NX_n=\frac{1}{N}\sum_{k=0}^{N-1}x_k\,e^{-i2\pi nk/N}
← the DFT, from (25)
Xn=12(an−i bn),X0=a0X_n=\tfrac12(a_n-i\,b_n),\qquad X_0=a_0
← from (19) and (16)
peak=2∣Xn∣=an2+bn2,θn=arg⁡Xn\text{peak}=2|X_n|=\sqrt{a_n^2+b_n^2},\qquad \theta_n=\arg X_n
← from (22)
XN−n=Xn‾X_{N-n}=\overline{X_n}
← the mirror, from (30)

Size tells you how much. Phase tells you where and why.