Short answer: autocorrelation finds pitch by looking for the time lag at which a sound best matches a shifted copy of itself. The YIN algorithm (de Cheveigné and Kawahara, 2002) starts from the same idea but uses a squared difference function, cumulative mean normalisation, an absolute threshold and parabolic interpolation, which removes most octave errors and gives finer pitch. YIN is usually the better choice for singing voice.
Both methods estimate the fundamental frequency (F0) of a monophonic sound, such as one voice or one instrument, in the time domain. You can watch this kind of detector work live in our online pitch detector, which uses a close relative of both methods (the McLeod pitch method, covered below). This guide explains each algorithm step by step, compares them, and shows what matters when you track a singing voice.

How autocorrelation pitch detection works
Autocorrelation multiplies a frame of audio by a copy of itself shifted by a lag τ (tau) and adds up the products: r(τ) = Σ x(j) · x(j + τ). When τ equals one period of the waveform, the peaks line up and r(τ) is large. The lag of the best peak (after the one at τ = 0) gives the period, and frequency = sample rate ÷ lag.
Example: at a 44,100 Hz sample rate, an A4 at 440 Hz repeats every 100.23 samples, so the detector looks for a strong peak near lag 100. Think of it as an echo matcher: it measures how well the waveform lines up with itself one cycle later.
Strengths: simple to code, robust on harmonic-rich voices and instruments (it follows the repetition, not the loudest harmonic), and cheap enough for real time, especially when computed with an FFT.
Weaknesses: the function also peaks at 2τ, 3τ and so on, and sometimes near τ/2 when the second harmonic is strong, so a naive peak picker makes octave errors (reading half or double the true pitch). The big peak at τ = 0 has to be skipped, the peak height shrinks with lag because fewer samples overlap, and accuracy drops in noisy recordings. The harmonics behind these errors are explained in why tuners show multiple notes.
How the YIN algorithm works, step by step
The original paper, “YIN, a fundamental frequency estimator for speech and music” by Alain de Cheveigné and Hideki Kawahara (Journal of the Acoustical Society of America, 2002), builds YIN in six steps. Each one fixes a specific weakness of plain autocorrelation:
| Step | What it does | Why it helps |
|---|---|---|
| 1. Autocorrelation | Starts from the autocorrelation idea above | Baseline: finds repeating periods |
| 2. Difference function | d(τ) = Σ (x(j) − x(j + τ))²: looks for the lag with the smallest difference | Dips at the period instead of peaks; less sensitive to changes in loudness |
| 3. Cumulative mean normalised difference | d′(τ) = d(τ) ÷ [(1/τ) Σ d(1…τ)], with d′(0) = 1 | Removes the dip at τ = 0 and stops very short lags winning, which cuts “too high” errors |
| 4. Absolute threshold | Take the first lag whose d′ falls below a threshold (the paper uses about 0.1), then its local minimum | Picks the true period before its multiples, which cuts “too low” (subharmonic) errors |
| 5. Parabolic interpolation | Fit a parabola through the dip and its two neighbours | Gives a fractional lag, so pitch is not limited to whole samples |
| 6. Best local estimate | Search nearby frames for a better dip and keep the most reliable one | Removes isolated wrong frames |
The value of d′ at the chosen lag is also useful as a confidence measure: close to 0 means a clean, periodic note; close to 1 means noise, breath or silence. Many implementations use it to decide whether a frame is voiced at all.
Why parabolic interpolation matters (worked example)
Without interpolation the lag is a whole number of samples. At 44,100 Hz, lag 100 means 441.0 Hz (+3.9 cents from A4) and lag 101 means 436.6 Hz (-13.3 cents). The true A4 period of 100.23 samples falls between them, so integer lags alone can be off by several cents, and the error grows for higher notes, where the period is only a few dozen samples. A parabola through the three points around the dip finds the fractional lag and brings the error well below one cent on clean tones. Cents are explained in what cents mean in tuning.
Autocorrelation vs YIN: side-by-side comparison
| Feature | Autocorrelation | YIN |
|---|---|---|
| Core measure | Similarity (peaks at the period) | Normalised difference (dips at the period) |
| Octave errors | Common without extra peak-picking rules | Much rarer thanks to normalisation and threshold |
| Pitch resolution | Whole-sample lag unless you add interpolation | Fractional lag by design (parabolic interpolation) |
| Voicing / confidence | Needs a separate measure | d′ value doubles as a confidence score |
| Noise robustness | Moderate | Better, but still hurt by heavy noise |
| Cost | Low; O(N log N) with an FFT | Similar; the difference function can also use an FFT |
| Ease of coding | Very simple | A few more steps, still compact |
| Typical use | Simple tuners, teaching, quick prototypes | Singing trainers, speech, music research |
YIN for singing voice (and pYIN)
Singing is harder than a tuning fork: notes glide, vibrato moves the pitch several times a second, onsets are breathy and consonants are not periodic at all. YIN’s confidence value helps skip unvoiced frames, but frame-by-frame estimates still jump now and then. pYIN (probabilistic YIN, Mauch and Dixon, 2014) keeps several candidate pitches per frame with probabilities and uses a hidden Markov model to choose the smoothest likely path, which gives cleaner melody lines and a voiced/unvoiced decision. It is available in the Python library librosa as librosa.pyin.
For singing assessment, the pitch curve is then compared with target notes in cents. That is what our pitch accuracy checker does, and the difference between frame-level detection and a smoothed curve is covered in pitch tracking vs pitch detection.
Other pitch detection algorithms worth knowing
- McLeod pitch method (MPM): Philip McLeod and Geoff Wyvill’s normalised square difference function (2005). Like YIN it normalises autocorrelation, then picks the first peak above a fraction of the highest one. It is fast and stable for real-time instruments and voice, and it is what our browser detector uses.
- FFT-based methods such as harmonic product spectrum work in the frequency domain; see how FFT works in pitch detection. You can see the harmonics they use in a spectrogram viewer.
- Neural networks such as CREPE (2018) learn pitch from data and can be very robust, at a higher computing cost; see machine learning in pitch detection.
Frame size, latency and the lowest note
A time-domain detector needs at least two periods of the lowest pitch in each frame. For an 80 Hz bass voice (12.5 ms per period) that is at least 25 ms of audio, plus room for the lag search, which is why real-time detectors typically analyse frames of around 40 to 90 ms. Shorter frames react faster but miss low notes; longer frames are steadier but lag behind fast passages. The trade-off in a browser is explained in real-time browser pitch detection.
Which should you use?
- Choose autocorrelation for a basic guitar or ukulele tuner, a class demo, or when you control the input (clean, loud, one note).
- Choose YIN for a singing trainer, speech analysis, wide vocal ranges, or anywhere octave errors would confuse users. Use pYIN when you need a smooth melody line from a recording.
- Either way, add a loudness gate for silence, a band-pass or high-pass filter against hum and rumble, and a short median filter to remove single-frame jumps. Noise is the main enemy of both; see noise and background interference.
To test an implementation, run it on recordings with known notes and compare the results in cents. Our audio file pitch detector exports a note list as CSV, which makes a handy reference, and our accuracy tests page shows how we check our own detector. For more articles on how pitch detection works, see the knowledge hub.
Frequently asked questions
Why is YIN more accurate than autocorrelation?
Because the cumulative mean normalisation and absolute threshold stop it from picking the zero-lag region or a multiple of the period, and parabolic interpolation gives a fractional period. Together these remove most octave errors and improve fine resolution.
Is YIN fast enough for real time?
Yes. It needs roughly the same work as autocorrelation and runs comfortably in real time on phones and in browsers, especially when the difference function is computed with an FFT.
Which is better in noisy rooms?
YIN usually copes better, and its confidence value lets you ignore unreliable frames, but neither method can recover a note buried in loud noise. Filter the input and move the microphone closer.
Can autocorrelation still be useful?
Yes. For simple tuners, teaching and quick prototypes it is easy to write and works well on clean single notes, especially with a sensible peak-picking rule.
What threshold should I use for YIN?
The original paper uses about 0.1. Implementations commonly use values between about 0.1 and 0.2: lower is stricter (fewer false notes, more dropouts), higher accepts noisier frames.
Ornella is a music technology writer and vocal tools specialist at Pitch Detector. She creates practical content around pitch detection, note recognition, vocal analysis, and singing education tools for beginners, singers, and audio creators.
