A long coding adventure on digital sound: sound files, waveforms, generating signals and the Nyquist rate, before it moves on to the Fourier transform. Watch the first half for the sampling ideas this lesson turns into code.
COURSE / REAL PRACTICE
Sound and the Fourier transform
Work with sound as numbers in NumPy: sampling and aliasing, a Fourier transform written by hand, a fast one, windows and spectrograms, filters, and rebuilding a sound from its partials. Lessons pair with public videos by Sebastian Lague, 3Blue1Brown and Reducible. Unofficial practice material, not affiliated with the videos’ authors.
Read the explanation and diagrams, then work through the practice. Your browser profile supplies your saved progress.
What you’ll work toward
Write a Fourier transform that matches NumPy, read pitch and timing from a spectrum, filter a signal on purpose, and resynthesize a sound from measured partials.
Read an explanation, inspect the diagrams and work through the available checks, debugging exercises and builds. Feedback and prerequisite links guide the next step.
Before you start
This course builds on these skills:
Individual lessons can add prerequisites. Your lesson progress shows your actual readiness.
A look inside the first lesson
Samples, aliasing and quantization
import numpy as np
i = np.arange(10)
loud = np.cos(2 * np.pi * 8 * i / 10)
slow = np.cos(2 * np.pi * 2 * i / 10)
print(np.allclose(loud, slow), round(float(loud[1]), 4))
f = abs(23) % 10
print(f, 10 - f if f > 5 else f)Your lesson sequence
Follow the same units and lessons in either view. Prerequisite links and your practice progress stay with each lesson.
Samples and spectra
- LESSON 01.01
Samples, aliasing and quantization
Generate sampled sines, fold frequencies into the Nyquist band, quantize to n bits, measure the noise in decibels, and write and read a 16-bit WAV file.
Open lesson - LESSON 01.02
A Fourier transform by hand
Build the discrete Fourier transform as a matrix product, read amplitude, phase and frequency from it, and check it against NumPy and Parseval's identity.
Open lesson - LESSON 01.03
The fast Fourier transform
Split a transform into halves, combine them with butterflies in log n stages, and use the result to convolve long signals and count the saved work.
Open lesson
Working with real sound
- LESSON 02.01
Windows and spectrograms
Cut a signal into Hann-windowed frames, build a spectrogram, invert it by overlap-add, and measure what the window does to leakage and onsets.
Open lesson - LESSON 02.02
Filters you can measure
Build moving averages, windowed-sinc, one-pole and biquad filters, then measure each one: gain at a frequency, the minus 3 dB point, and linear phase.
Open lesson - LESSON 02.03
Capstone: rebuild a sound from its partials
Pick the sinusoids out of a windowed frame with interpolated peaks, find the pitch even without its fundamental, and synthesize the sound again.
Open lesson
WATCH ALONG
Videos for these lessons
One hand-picked talk, lecture or tutorial per lesson, in course order. They play here when you press play; nothing loads from the video provider before that.
5 videos· 2 h 30 min
01Samples, aliasing and quantization
-
A visual introduction to the transform: winding a signal around a circle at each trial frequency and watching where the average lands. Watch it before the sum below, so that each term of the sum has a picture.
-
Covers sampling, comparing a signal with test frequencies, the linear algebra view of the transform and the phase problem. Watch it for the matrix that this lesson's algorithm computes faster.
-
Covers the short-time Fourier transform, the trade between time and frequency resolution, the Hann window, hop and segment size, and turning a spectrogram back into sound. Watch it first, then build the same pieces here.
05Capstone: rebuild a sound from its partials
Builds sounds by adding sine waves, with envelopes for the loudness of each note and sets of harmonics for the timbre of instruments. The synthesis half of this lesson: watch it for the idea, then write synthesize here.