THE PITCH DETECTION

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.

source de Cheveigné & Kawahara, YIN, a Fundamental Frequency Estimator for Speech and Music, JASA 111, 1917–1930 (2002) — doi:10.1121/1.1458024 Rendered, not quoted.
Blue Team · builds & defends
3

The Model

A periodic signal repeats every P samples. The (biased) autocorrelation at lag τ measures self-similarity:

r[τ] = Σn x[n]·x[n+τ]

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:

d(τ)=Σ(x[n]−x[n+τ])² ,  d′(τ)=d(τ)·τ / Σj≤τd(j) ,  d′(0)=1

Pick the first τ with d′(τ) below threshold. AMBER: the cumulative-mean normalisation suppresses — does not eliminate — octave errors.

5

The Lineage

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.

7

The Witness

Re-runs selfcheck() live and confirms the peak-at-the-period. It flips red the instant the TAMPER (window 6) is armed.

witness idle…
The Machine
4

Data In in ↓

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.

0

The Panel LIT

Signal x[n] — one period spans 200 samples.
Autocorrelation r[τ] — first peak = period P, peak at 2P = the octave-low trap.
8

Data Out out ↓

Detected from the live autocorrelation:

computing…
Red Team · attacks & breaks
1

The Adversary WALL

Octave halving/doubling: a strong 2nd harmonic makes r peak near P/2 (pitch too high); the periodic peak at 2P makes it too low.
Biased-autocorrelation bias: the triangular window inflates short lags, tilting naive picks toward low periods.
Period quantisation: f0 = sr/P with integer P has coarse resolution at high pitch — YIN adds parabolic interpolation.
Noise & non-stationarity blur the peak; formant structure adds spurious maxima. Real defeats need thresholds, not a bare argmax.
2

The Graveyard

"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.

6

The Tamper

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.