Low-pass, high-pass, and convolution - shaping signals
Bass boost, noise reduction, and photo sharpening all work the same way: turn some frequencies up, turn others down. Here you do it by hand, and hear the result.
The grey hills are the spectrum of the sound; the yellow line is a gain for every frequency. Drag across the spectrum to draw your own curve, or start from a preset. Press play and flip between the original and the filtered sound while it loops. Try the notch on the noisy sine, then a band-pass on the voice to hear a telephone.
The whole two-second clip is transformed at once (32,768-point FFT at 16,384 samples per second). Each frequency bin is multiplied by the curve's gain, and its negative-frequency mirror by the same gain, then an inverse FFT gives the filtered sound. Because the gain is applied to the whole clip, the filter has no delay: it sees the future as well as the past, which a live filter cannot.
A filter selectively removes or enhances frequencies. In the frequency domain that is the simplest operation there is: multiply each frequency's amplitude by a number between 0 and 1. The yellow curve is that list of numbers, called the filter's frequency response.
The desk does it literally. The two-second clip is turned into a spectrum with one FFT, each bin is multiplied by the curve's gain at its frequency, and one inverse FFT turns the result back into sound. The violet spectrum is the grey one with your curve applied, and the violet trace underneath is what comes out.
Each bin has a mirror image at the matching negative frequency, and the two must get the same gain. Give them different gains and the output would no longer be a real-valued sound.
Low-pass keeps low frequencies and blocks high ones: bass through a wall, or a blurred photo. On the voice it removes the bright upper formants and leaves a muffled vowel.
High-pass keeps high frequencies: it removes rumble, and in images it keeps edges. The voice turns thin and hissy.
Band-pass keeps one range. Radio tuning is a band-pass; so is the telephone, which keeps roughly 300 to 3,400 Hz.
Notch removes one narrow range and keeps everything else. It is the standard cure for 50 or 60 Hz mains hum. Centre it on 440 Hz with the noisy sine and the tone disappears while the hiss stays.
Real filters are described by their passband (what gets through), stopband (what is blocked), cutoff (where the change happens) and roll-off (how steeply). The presets here have soft edges; a hand-drawn cliff gives a brick-wall filter, and you may hear faint ringing from it, the same Gibbs effect that shows up at a square wave's corners.
Audio equalisers are this desk with a few fixed sliders. Noise reduction measures the spectrum of the noise alone, then turns down the bins where noise dominates. Image sharpening boosts high spatial frequencies to make edges crisper.
One thing the desk does that live equipment cannot: it filters the whole clip at once, so the output at each moment depends on the future as well as the past. Real-time filters must be causal, and they pay for it with delay or phase distortion.
In the time-domain panel the kernel is flipped and slid along the signal; at each position the overlapping values are multiplied and added into one output dot. In the frequency-domain panel the two spectra are simply multiplied bin by bin. Transform that product back and you get the violet line, which passes through every dot.
Sliding, multiplying and adding is called convolution, written x * h. The convolution theorem says
Convolution in the time domain (*) is pointwise multiplication (×) in the frequency domain.
The reason: a pure frequency e2πikn/N slid through any kernel comes out as the same frequency, scaled by the number H[k]. Write the signal as a sum of pure frequencies, and convolution scales each one by its own H[k], which is multiplication of spectra. The "largest difference" readout is pure rounding error, around 10⁻¹⁶.
The demo uses circular convolution: a kernel that slides off the right end comes back on the left, because the FFT treats every signal as one period of a repeating one. Practical code pads with zeros first so the wrap-around falls on empty space.
Sliding a kernel across every point costs O(n²) multiplications. The theorem gives a shortcut:
That is O(n log n). For the desk's 32,768-sample clip it is the difference between about a billion multiplications and about a million. Every long reverb, large blur and fast polynomial multiplication relies on it.
Spot a mistake or have an idea?