Brief
A tuner listens to a note and says which string you played and whether it is sharp or flat. To do that it needs to know which frequencies are inside the sound. The Fourier transform answers exactly that question. In this project you write it yourself, first slowly, then fast, and turn it into a working tuner.
The discrete Fourier transform takes samples and gives one complex number per frequency: . Written out, that is just a matrix times a vector, so your first version is a matrix multiply. It costs operations. The fast Fourier transform (FFT) gets the same answer in by splitting the samples into even and odd halves and reusing the two smaller transforms.
Output corresponds to the frequency , where is the sample rate. At 44,100 samples per second and = 44,100, the bins are 1 Hz apart. Half a second of audio gives 2 Hz bins, so you will need to estimate between bins to reach 1 Hz accuracy. Standard tuning is E2 82.41 Hz, A2 110.00, D3 146.83, G3 196.00, B3 246.94 and E4 329.63. The distance in cents is ; 100 cents is one semitone.
DATA · your recordings
Objectives
Read-only. Log in to update progress.
VICTORY CONDITIONS
- Your FFT matches np.fft.fft within 1e-9 (largest absolute difference) on random inputs up to 65,536 samples. Record the error with `python tools/mlarena.py record BM-21 "<max error>"`.
- Detected pitch is within 1 Hz of the label on every labelled clip, including the low E string.
- No np.fft call anywhere in the tuner itself; NumPy's FFT appears only in your tests.
Side quests
Terms in plain words
- Discrete Fourier transform (DFT)
- Turns N samples in time into N complex numbers, one per frequency, that say how much of each frequency the signal contains.
- FFT
- A fast way to compute the exact same DFT. It splits the signal into even and odd samples again and again, so the cost drops from N² to N log N.
- Frequency bin
- Output k of the DFT stands for the frequency k × (sample rate) / N. The bins are evenly spaced, so a pitch between two bins has to be estimated.
- Window
- A smooth curve, such as the Hann window, multiplied into the clip so it fades in and out. It stops the hard edges of the clip smearing the spectrum.
- Harmonic
- A plucked string vibrates at its pitch f0 and also at 2·f0, 3·f0 and so on. These whole-number multiples are its harmonics.