I do not understand the formulation of the cumulative mean normalised difference function (CMNDF)
19:50 20 Jan 2026

I am working on a pitch detection project, I was previously using the FFT which produced inaccurate results in my own testing.

I came across the YIN algorithm, which effectively builds on the autocorrelation function and expresses a difference function to find the period T of the signal. This difference is squared and a sum is taken on both sides:

Difference function

The sum can be expressed in terms of the auto-correlation function but that is not important for the question. My understanding of the paper is that the difference function is susceptible to picking the lags near to the zero-lag dip and the frequency that is detected will be too high. To combat this problem, the paper suggests the CMNDF:

CMNDF

If the lag is 0, we return 1. I understand this as this removes the trivial solution to the difference function. However I do not understand the formulation for lags that are greater than 0? How is it preventing the algorithm from picking lags that are close to 0?

pitch-detection