You're staring at a waveform. Maybe it's a guitar recording. Also, maybe it's a vibration sensor on a motor. Worth adding: maybe it's EEG data from a sleep study. The signal is messy — noisy, harmonic-rich, possibly clipped — and somewhere in there is the one number you actually need: the fundamental frequency And that's really what it comes down to..
This is where a lot of people lose the thread.
Finding it sounds simple. Real life? Textbooks make it sound simple. Not so much Nothing fancy..
What Is Fundamental Frequency
The fundamental frequency — f₀ if you're feeling academic — is the lowest frequency component of a periodic signal. It's the base rate at which the waveform repeats. Everything else in the signal (harmonics, overtones, noise) sits on top of it Nothing fancy..
A pure sine wave is its own fundamental. That's why a violin note has a fundamental plus a whole forest of harmonics that give it timbre. A square wave has a fundamental plus odd harmonics. The fundamental is what your brain locks onto when you perceive pitch.
But here's the thing: the fundamental isn't always the strongest component. It isn't always even present in the signal. And that's where the trouble starts.
When the fundamental goes missing
This happens more than you'd think. Day to day, telephone bandwidth cuts off below 300 Hz — so a 100 Hz male voice loses its fundamental entirely. Your brain reconstructs it from the harmonic spacing. Yet you still hear the pitch. This is the missing fundamental phenomenon, and it's why naive peak-picking fails Small thing, real impact..
Some instruments — like the clarinet in its lower register — have weak fundamentals relative to their harmonics. A cheap piezo pickup on an acoustic guitar might capture more body resonance than string fundamental. The signal you're analyzing might not contain what you're looking for.
This is the bit that actually matters in practice.
Why It Matters
If you're building a tuner, you need the fundamental to tell the user what note they're playing. If you're doing speech recognition, f₀ carries prosody — stress, intonation, question vs. On top of that, statement. If you're monitoring rotating machinery, the fundamental tells you shaft speed. Harmonics tell you about gear meshing, bearing defects, blade pass frequencies.
Get the fundamental wrong by a few percent and your tuner says "sharp" when the player is dead on. Day to day, miss a subharmonic in vibration analysis and you diagnose the wrong fault. In speech processing, f₀ errors cascade into bad voicing decisions, which wrecks synthesis and recognition downstream.
The stakes are real. The methods are many. Most people reach for the wrong one.
How to Find It
There's no single algorithm that works everywhere. The right choice depends on your signal type, noise level, computational budget, and whether you need real-time performance. Here's the landscape Turns out it matters..
Time-domain methods
These operate directly on the waveform. Think about it: no spectrum. No FFT. They're fast and often surprisingly strong.
Autocorrelation is the classic. You correlate the signal with a delayed version of itself. The first significant peak (after the zero-lag peak) gives you the period. Invert it: f₀ = 1 / T. Simple. But — the autocorrelation of a harmonic-rich signal has peaks at every harmonic period. The fundamental peak isn't always the tallest. You need peak-picking logic that prefers the longest period that explains the data Simple, but easy to overlook..
Average Magnitude Difference Function (AMDF) and Average Squared Difference Function (ASDF) are autocorrelation's cheaper cousins. Instead of multiplying, you subtract. AMDF: D(τ) = (1/N) Σ |x[n] - x[n-τ]|. The minimum corresponds to the period. Computationally lighter, but noisier. ASDF squares the difference — sharper minima, but more sensitive to outliers And that's really what it comes down to..
Zero-crossing rate is the crudest method. Count how many times the signal crosses zero per second. Divide by two for a sine wave. For anything else? Useless. Harmonics create extra zero crossings. Noise creates tons. Don't use this for pitch. Use it for a quick "is this voiced?" check in speech.
YIN algorithm — this is the gold standard for monophonic pitch. It's a refined autocorrelation with a cumulative mean normalized difference function that suppresses subharmonic errors. It handles the missing fundamental better than raw autocorrelation. It's fast enough for real-time. If you're building a guitar tuner or a voice pitch tracker, start here. The original paper (Cheveigné & Kawahara, 2002) is readable and the reference implementation is public domain It's one of those things that adds up. That's the whole idea..
Frequency-domain methods
Take an FFT. Look at the spectrum. Find peaks. The fundamental should be the lowest-frequency peak with harmonic structure above it.
Harmonic Product Spectrum (HPS) — downsample the spectrum by 2, 3, 4... multiply them together. Harmonics align and reinforce; noise and non-harmonic peaks don't. The fundamental emerges. Clever. But it needs enough harmonics to work, and spectral resolution must be sufficient to separate them. Short windows = wide bins = smeared harmonics = failure.
Cepstral analysis — take the log spectrum, then inverse FFT. The result is the cepstrum. Periodicities in the spectrum (harmonic spacing) become peaks in the quefrency domain. The fundamental period shows up as a peak. This handles missing fundamentals beautifully — the harmonic spacing is still there even if the fundamental isn't. But it's computationally heavier and needs careful liftering (yes, that's the term) to separate source from filter in speech.
Spectral peak picking with harmonic matching — find spectral peaks, then test candidate f₀ values by checking how well integer multiples align with observed peaks. Score each candidate. Pick the winner. This is essentially what sophisticated pitch trackers like PYIN (probabilistic YIN) and CREPE (deep learning) do under the hood.
Machine learning approaches
CREPE (Convolutional REpresentation for Pitch Estimation) uses a deep CNN trained on massive datasets. It outputs f₀ with confidence. It's remarkably dependable to noise, reverb, and polyphony (to a point). It runs on GPU or CPU via ONNX/TensorFlow Lite. If you can afford the model size (~20 MB) and compute, it's often the best single choice for general audio.
RAAPT, SWIPE, PEFAC — academic algorithms with implementations floating around. SWIPE uses a sawtooth waveform correlation in the frequency domain. PEFAC uses a harmonic model with phase information. They're excellent but less plug-and-play.
For speech specifically: PYIN (probabilistic YIN) adds a hidden Markov model on top of YIN to smooth pitch contours and handle voiced/unvoiced decisions. It's the default in librosa and many speech toolkits.
The polyphony problem
Everything above assumes one fundamental at a time. Which means real music? Chords. Multiple speakers. Drum bleed.
For polyphonic f₀ estimation, you're in a different world. Deep learning — models like Basic Pitch (Spotify), MT3 (Google), Omnizart. These output multiple f₀ tracks. Constant-Q Transform + harmonic summation. Non-negative Matrix Factorization (NMF) with harmonic templates. In practice, they need training data. Day to day, they're heavier. But they're the only thing that works on mixed audio That alone is useful..
If you're analyzing a single instrument or voice — stick with mon
ophonic methods like YIN or CREPE. If you're tackling a full mix, prepare for a significant jump in complexity Easy to understand, harder to ignore. Nothing fancy..
Choosing your tool
The "best" method is entirely dependent on your constraints:
- Real-time/Low Latency: If you are building a digital instrument or a live vocal tuner, look at YIN or MPM (McLeod Pitch Method). They are fast, lightweight, and highly efficient for single-source signals.
- Accuracy/Robustness: If you are processing studio recordings where noise and reverb are present, CREPE is the gold standard. Its ability to "learn" what a pitch should look like makes it far more resilient than purely mathematical approaches.
- Transcription/Music Information Retrieval (MIR): If you are trying to turn a piano recording into MIDI, you need polyphonic estimation. Use Basic Pitch or Omnizart. These models are designed to disentangle overlapping frequencies, which is a fundamentally different mathematical challenge than tracking a single line.
Conclusion
Pitch estimation is a bridge between the raw, messy physics of sound waves and the structured, mathematical world of music theory. We have moved from simple autocorrelation—looking for repeating patterns in the time domain—to sophisticated deep learning architectures that "understand" the texture of sound.
While the "missing fundamental" remains a persistent ghost in the machine, modern spectral and probabilistic techniques have largely tamed it. Whether you choose the speed of a time-domain correlation or the brute-force intelligence of a CNN, the goal remains the same: finding the singular, invisible thread that defines the melody amidst the chaos of the spectrum.