Mathematics · Explainer
How does Shazam identify a song in a noisy room?
Shazam never compares your recording to the studio track. It splits the clip into the pure tones inside it, keeps only the loudest at each moment, and matches that short list against over a million songs. Avery Wang published the method in 2003. The tone pattern survives noise that wrecks the raw recording.
Why matching the recording itself never works
The obvious idea is that your phone captures a few seconds of audio and looks for the same few seconds in a library. That fails immediately. A microphone in a bar picks up the song plus conversation, glasses, footsteps, the room's echo and whatever the speaker does to the bass. Line that recording up against the studio master and compare them moment by moment, and the two barely resemble each other.
The problem is that a recording is stored as a single wiggling line: air pressure measured tens of thousands of times a second. Adding any noise at all changes almost every one of those numbers. A comparison built on the line itself is fragile in exactly the situations where you actually want to identify a song.
Every sound is a stack of pure waves
Strike a tuning fork and the air moves in one smooth, endlessly repeating wiggle: a single pitch. Strike three forks at once and the air still moves along one line, because it can only be in one place at a time. The three smooth curves add together into a jagged one. Yet your ear still hears three separate pitches.
Nothing was destroyed when the waves were added. For a recording of fixed length, exactly one set of pure waves adds up to that line, and it can be recovered from the line alone. The rule is called Fourier decomposition, and it works because pure waves of different frequencies do not blur into one another. Test a recording against one frequency at a time and each answer comes out clean: a large total if that frequency is present, near zero if it is not.
Testing thousands of frequencies one by one was once far too slow to be useful. In 1965 James Cooley and John Tukey published a shortcut that reuses work across the tests. For a clip of a thousand samples, about a million steps drop to about ten thousand. That single change is why a phone can pull a sound apart while you hold it up in a bar.
From pure waves to a fingerprint
Shazam chops your clip into short slices, splits each slice into its pure waves, and stacks the results side by side. Time runs across, pitch runs up, brightness is loudness. That picture is called a spectrogram, and the loudest notes of the actual music show up in it as bright peaks.
Those peaks are the part worth keeping. Chatter and a poor speaker add plenty of energy, but they rarely land on the same frequencies as the melody, so the peaks stay roughly where they were. Wang's method throws away everything else. Each pair of nearby peaks becomes one short number, and those numbers are what get looked up. Identifying a song becomes a database lookup over a few numbers per second rather than a comparison of audio, which is why the answer comes back in seconds.
The same trick has a hard limit worth knowing. A fingerprint belongs to one specific recording. A live performance or a cover version writes a different set of peaks, so it usually will not match. That is the honest cost of matching something exact, and it is also the reason the method is dependable when it does fire.
The same idea, well beyond music
Once you can describe something by which frequencies it contains, the move generalises. Swap time for distance across an image and a photograph splits the same way, into slow waves for broad areas and fast waves for edges and fine detail. The 1992 JPEG standard does exactly this, cutting each image into 8 by 8 pixel blocks and rewriting them with the discrete cosine transform, a close relative of the Fourier transform, then discarding the fast waves your eye barely notices.
An MRI scanner goes further and never records a picture at all. It collects a grid of frequencies called k-space, and the image of your knee appears only when those waves are added back together. Your own inner ear does a version of it too, sorting sound by pitch along a strip a few centimetres long before a single nerve fires.
Sources & further reading
Free to start. Sign in with Google, no card.