Sound & music

Find the Note

A sound is a wiggle in the air. Robo splits the wiggle into a rainbow of pitches, then tries to name the note. Can you trick it?

This is a flute playing the note A. See the bars? The tall one on the left is the note, and the little ones are its sparkly overtones. Press Play to hear it, then tap a different key!

  1. Tap a key to pick a note.
  2. Change the instrument, the hiss and the missing note.
  3. Watch Robo's two ears. Do they agree?

Your sound

Sound is quiet on purpose. The microphone is optional: it only starts when you press the button, and nothing is recorded or sent anywhere.

The wiggle (how the air moves, for a split second)

The rainbow of pitches (each bar is how loud one pitch is)

the real noteBiggest-bar earEcho ear

Tip: on a computer you can also use the keys A to K (white) and W E T Y U (black).

Mystery tune

Four notes, shown as a picture over time (a spectrogram). Bright = loud. The dots are where Robo's echo ear thinks the note is. Read the note names on the side, then type your answer below. It uses your instrument, hiss and missing-note settings.

Challenges

Fool the biggest-bar ear. Make it name the wrong note while the echo ear still gets it right.Try this: pick the Violin, or tick "Take away the bottom note".
Spot on in the storm. Set the hiss to 60% or more and put the note out of tune by at least 10 cents. Can the echo ear still land within 5 cents of the real pitch?Try this: drag "Out of tune" to +20, then turn the hiss way up.
Name that tune. Work out all four notes of the mystery tune.Try this: find Robo's dots, follow them across to the note names, and press Play the tune to listen.

What just happened?

How it works

  1. Robo builds the sound out of numbers: one sine wave for the note, one for each overtone, plus random hiss. 16,000 numbers make one second.
  2. It splits 4,096 of those numbers into a rainbow of pitches with a fast maths trick called the FFT. Each bar is about 4 Hz wide.
  3. Biggest-bar ear: pick the tallest bar between 60 and 2,400 Hz.
  4. Echo ear: compare the wiggle with a slid-along copy of itself, find the first slide where it lines up well, and turn that time into a pitch. Then fine-tune it using the exact spots of the overtone bars.
  5. The note name and the cents come from counting keys away from A4 = 440 Hz.
For grown-ups: what's really going on

Everything here is computed in plain JavaScript on generated sample arrays (fs = 16 kHz, frame N = 4096), so it runs identically in Node. Web Audio is used only to play the sound and, if you opt in, to read the microphone.

  • Spectrum. The frame is multiplied by a Hann window w[n] = ½ − ½cos(2πn/(N−1)) to reduce spectral leakage, then transformed with an iterative radix-2 Cooley–Tukey FFT (O(N log N); checked against a naive O(N²) DFT). Bin resolution is fs/N ≈ 3.9 Hz, so a peak is refined by fitting a parabola to the log magnitudes of its three bins.
  • Peak picking returns the loudest bin. It is wrong whenever harmonic 2 or 3 outweighs the fundamental (our violin preset) or the fundamental is absent, giving classic octave errors.
  • Autocorrelation r(τ) = Σ x[n]x[n+τ] is computed via the FFT (Wiener–Khinchin: inverse transform of |X|², zero-padded to avoid wrap-around), made unbiased by dividing by N−τ and normalised by r(0). We take the first local maximum (parabola-interpolated) whose height is at least 85% of the global maximum within 60–1100 Hz; picking the first such peak avoids sub-octave errors. Because every harmonic of f0 is periodic in 1/f0, the peak sits at the true period even when the fundamental is missing. White noise is uncorrelated with itself at non-zero lags, so it mainly lowers the peak rather than moving it.
  • Fine tuning. Lag resolution is coarse at high pitch (1 sample at 16 kHz is ~10 cents at 440 Hz), so the autocorrelation estimate is refined by locating each visible harmonic's interpolated peak near h·f0 and averaging fh/h, weighted by power. Typical error: under 1 cent clean, a few cents at 0 dB SNR.
  • Harmonic product spectrum (the "third opinion"): HPS(f) = Πh=1..5 |X(hf)|, computed as a sum of logs with a floor so a single missing harmonic is a penalty rather than a zero, with ties broken towards the higher candidate. It handles the missing fundamental well but can still be fooled, for example by the buzzy robot with its fundamental removed.
  • Cents: 1200·log2(f/fref), with equal temperament and A4 = 440 Hz (MIDI note 69, f = 440·2(m−69)/12). 100 cents is one semitone; trained listeners notice about 5–10 cents.
  • Spectrogram: a short-time Fourier transform (1024-sample Hann frames, hop 256), drawn on a logarithmic frequency axis like a piano. The pitch track runs the same autocorrelation detector on each frame, skipping quiet or unvoiced frames.

The "missing fundamental" is a real perceptual effect: you hear the pitch of a tone whose fundamental has been removed, which is why small phone speakers can still play bass lines. Production pitch trackers such as YIN, pYIN and the neural CREPE build on exactly these ideas; speech and music systems often feed log-mel spectrograms (like the strip above) into neural networks.