Finding the note inside the waveform. The lag at which a signal best matches a delayed copy of itself is its period; the fundamental is f0 = sr / period. And the octave trap that catches naive methods: the autocorrelation peaks again at twice the period, so a lazy peak-pick reports a pitch an octave too low.
A periodic signal repeats every P samples. The (biased) autocorrelation at lag τ measures self-similarity:
It is maximal at τ=0 (perfect self-match) and peaks again at τ = P, 2P, 3P… The period is the first non-trivial peak; the pitch is f0 = sr / P.
YIN instead minimises the difference function and normalises it:
Pick the first τ with d′(τ) below threshold. AMBER: the cumulative-mean normalisation suppresses — does not eliminate — octave errors.
The note inside the noise. Autocorrelation's peak at the period is the time-domain twin of the-fourier: by Wiener–Khinchin the autocorrelation is the inverse transform of the power spectrum. This sphere threads past the octave error the naive spectral/temporal pick makes.
Re-runs selfcheck() live and confirms the peak-at-the-period. It flips red the instant the TAMPER (window 6) is armed.
A synthetic tone at f0 = 220.5 Hz, sampled at 44.1 kHz → exact period P = 200 samples. Three harmonics (1, ½, ⅓) plus optional fixed-seed noise for the display.
Detected from the live autocorrelation:
"The global maximum of the autocorrelation gives the pitch."
→ The global max is always lag 0 (a signal matches itself perfectly). Search lag>0 for the first significant peak.
"Autocorrelation never makes octave errors."
→ It peaks at 2P (an octave low) and near P/2 for harmonic-rich tones (an octave high). Both are classic failures.
"The recovered period is exact."
→ AMBER: period is quantised to whole samples; f0 resolution is limited by sr. Interpolation refines it.
The disclosed planted void: pick the global maximum of r instead of the first non-trivial peak. The global max is lag 0 → period 0 → f0 = sr/0 = ∞. The Witness (7) catches it live.