CodeRigor

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.

Free to useLessons & exercises6 authored lessons2 units
Start with the first lesson.

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

Python
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.

UNIT 013 lessons Samples and spectra
  1. 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
  2. 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
  3. 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
UNIT 023 lessons Working with real sound
  1. 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
  2. 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
  3. 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

  1. 01Samples, aliasing and quantization

  2. 02A Fourier transform by hand

  3. 03The fast Fourier transform

  4. 04Windows and spectrograms

    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.

  5. 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.