Music●●●●●Difficulty 3 of 5

How can a machine find a note's pitch just from its sound wave?

A guitar tuner knows nothing about music, yet it can tell you you're flat. The trick is comparing a sound wave with a slightly delayed copy of itself.

▶ Start the story

By comparing the sound wave with a delayed copy of itself. This technique, autocorrelation, measures the correlation of a signal with a shifted version of its own waveform, and it's a mathematical tool for finding repeating patterns or hidden periodicities hiding inside a signal, even one buried in noise.

A guitar tuner, a pitch-detection app, or the software behind Auto-Tune all face the same basic problem: estimate the pitch, or fundamental frequency, of a quasiperiodic signal like a plucked string or a sung note. The usual strategy is to find the signal's period, how long it takes the wave to repeat itself, and then flip that number upside down to get the frequency. Autocorrelation finds that period by sliding a copy of the wave against itself and checking, at each possible delay, how closely the two line up; when the delay matches the wave's true repeating period, the match is strongest. Algorithms with names like AMDF and ASMDF work this way, as do two of today's standard tools, the YIN algorithm and the MPM algorithm, both still built on autocorrelation.

How autocorrelation finds a pitch
  1. Step 1: Record the sound wave

    A plucked string or sung note

  2. Step 2: Make a delayed copy

    Shift the wave by a small amount

  3. Step 3: Compare the two

    Check how closely they line up

  4. Step 4: Find the best match

    That delay reveals the wave's repeating period

  5. Step 5: Flip it over

    Period inverted gives the pitch

For a long time it looked too expensive to run. Music engineers considered autocorrelation impractical because of the sheer amount of computation it needs, until Andy Hildebrand, building the pitch detector for Auto-Tune, realized most of that arithmetic was redundant and found a shortcut that, in his words, changed a million multiply-adds into just four.

It isn't flawless. These algorithms can be quite accurate on highly periodic signals, but they're prone to 'octave errors', mistaking a note for one an octave too high or low, they can struggle with noisy recordings, and in their simplest forms they get confused by polyphonic sounds, several notes playing at once with different pitches.

The same trick works at different timescales for different jobs. Applied to stretches shorter than a second, autocorrelation finds the pitch, which is how tuners and Auto-Tune work. Applied to stretches longer than a second, the exact same technique can pick out the beat of a song instead, which is how software estimates tempo. The method isn't limited to music, either: astronomers use autocorrelation to work out the frequency of pulsars.

Quiz me

0/3

  1. 1.Why does comparing a sound wave with a delayed copy of itself reveal its pitch?
  2. 2.What is a known weakness of autocorrelation-based pitch detection algorithms like YIN and MPM?
  3. 3.How does autocorrelation detect a song's tempo instead of its pitch?

Recap

To find how often a wave repeats, compare it with a delayed copy of itself; the delay where they match best reveals the period, and flipping that period over gives the pitch.

Surprising fact · Pitch-detection algorithms built on autocorrelation, like YIN and MPM, can still mistake a note for one an octave too high or low, a known weakness called an octave error.

Sources (3)

No source, no claim. Every fact in this lesson (11 claims) cites at least one of these.

  1. [1]Autocorrelation · Wikipedia
  2. [2]Pitch detection algorithm · Wikipedia
  3. [3]Auto-Tune · Wikipedia
More lessons in 🎵 Music (3) See all music lessons →

One more light on your map.

Get one lesson like this every day, about the things you love. Free, in two or five minutes.

Get the share card for this lesson ↗