5.4.7 · D1Scientific Computing (Python)

Foundations — NumPy FFT — np.fft module

1,911 words9 min readBack to topic

This page assumes you have seen nothing. We will meet every symbol the parent NumPy FFT — np.fft module uses — , , , , , , — and earn each one with a picture before it is ever used in a formula.


1. A signal is just a list of numbers

Picture it. Look at Figure 1: the smooth grey curve is the true sound; the magenta dots sitting on it are the samples. The FFT never sees the curve — only the dots.

Figure — NumPy FFT — np.fft module
Question — what does the subscript in tell you?
It is the index: is the sample at position 5 (the sixth sample, since we start at 0).

2. — how many samples, and — how to add them all

Now, the DFT formula adds up many terms. Writing by hand is madness, so mathematicians invented a shorthand.

Question — expand .
.

3. Time between samples: and the sampling rate

Picture it. In Figure 2 the horizontal spacing between neighbouring dots is . Cram the dots closer (smaller ) and you take more samples per second (bigger ).

Figure — NumPy FFT — np.fft module
Question — if you sample every s, what is ?
Hz.

4. Frequency, and the index

The bridge from slot back to real Hz is the parent's key formula

Question — with , Hz, which Hz does bin represent?
Hz.

5. The spinning arrow: , , and

This is the scariest-looking symbol in the parent. We build it in three calm steps.

5a. The imaginary unit

5b. Euler's formula — an arrow on a circle

Picture it. Figure 3 shows the unit circle: the violet arrow sits at angle ; its shadow on the horizontal axis is , its shadow on the vertical axis is . That is all says — "a spinning arrow, here is where it points."

Figure — NumPy FFT — np.fft module

5c. Putting it together: the probe wave

Now read the exponent piece by piece:

  • radians = one full turn around the circle.
  • = a fraction telling you how far around you have spun. As the sample counter runs , this fraction runs , i.e. the arrow makes exactly complete turns.
  • The minus sign means "spin clockwise instead of counter-clockwise." (The parent explains this minus is the conjugate — the measuring version — of the forward probe.)
Question — as goes from to , how many full turns does make?
Exactly full turns (clockwise).

6. The complex output and its size

Question — what does measure physically?
The strength (amplitude-ish size) of frequency bin 3 in the signal.

7. How it all feeds the topic

Samples x_n

DFT sum X_k

Count N

Summation sigma

Imaginary unit i

Spinning probe wave

Euler e to i theta

Magnitude of X_k

Delta t and f_s

Bin to Hz f_k

Frequency index k

FFT and np.fft

Every box on the left is a symbol you now own; together they build the single formula the parent lives on:


Equipment checklist

Can you read out loud and say what it is?
"sample number 7" — the eighth measurement (indices start at 0).
Can you expand ?
.
Do you know the relation between and ?
(samples per second = 1 over the gap).
Can you convert bin to Hz?
.
Do you know what pictures?
A unit-length arrow at angle spinning on the unit circle; equals .
Why does multiplying by matter geometrically?
It rotates a point 90° counter-clockwise.
What does tell you?
The size/strength of frequency bin .
What does the total window length control?
The frequency resolution (finer with longer recordings).

Connections