This link provides code for an autocorrelation-based pitch detection algorithm but says:

Cons: Not as accurate, doesn't work for inharmonic things like musical instruments, this implementation has trouble with finding the true peak

Why is that? What implications will it have if I want to create a guitar pitch detector (let's assume that I am only working with monophonic audio for now). Is it the noise that creates those implications? I thought that musical instruments are harmonic things, not inharmonic.

Is the YIN algorithm an improvement in this aspect? If not, what does it improve?

  • 2
    $\begingroup$ Why is that? well, it's not a good method, because it doesn't work well for anything that isn't "statically" periodic, as the text says (haven't used "inharmonic", but I think what they want to say is periodic with one, fixed, period"). So, in short: not the right tool; asking why it's not the right tool is like saying "I tried to unscrew a screw with a spoon, but it didn't seem very effective. Why?" I think comparing a more complex algorithm with this isn't really worthwhile, as it's asking for a very broad answer that first introduces theory of cyclostationary signal analysis and then YIN. $\endgroup$ Commented May 9, 2017 at 19:12

3 Answers 3


Cons: Not as accurate

This is just compared to the other methods. I was measuring frequency very accurately to look for clock drift, etc: 1000.000004 Hz for 1000 Hz, for instance. For guitar pitch detection it will be fine.

doesn't work for inharmonic things like musical instruments

I should have said "it can't find an accurate fundamental if there is inharmonicity". It will be shifted up because the plucked string partials are slightly sharp.

In your case, you don't want to find the fundamental, though, you want to find the perceived pitch, which is what autocorrelation is good at. (though I don't know how accurate, and if it needs weighting, etc.)



this implementation has trouble with finding the true peak

because autocorrelation will produce peaks at the correct frequency but also at all its sub-harmonics, and this function just naively chooses the highest peak. You need to plot the correlation curve and find a way to choose the correct results for your waveforms.

  • 4
    $\begingroup$ It's always great to get the author of a software comment on it directly, when you have a question about its capabilities! $\endgroup$ Commented May 10, 2017 at 4:46

Because guitar strings have non-zero stiffness, non-zero diameter, and non-zero displacement, the physical vibration frequency of the string's overtones can be slightly sharp. Thus inharmonic. But this slight inharmonicity might be part of what makes certain real stringed instruments sound more "interesting" than some simplistic additive and waveform sampling synthesizers.

However musical pitch perception can be different from the vibration mode. There is some experimental evidence that the perceived pitch, for stringed instruments notes with weak fundamentals, is more related to the distance between certain harmonics, rather than the fundamental vibration mode. Note that this frequency distance is different for slightly inharmonic musical instruments than for more purely harmonic ones.

Autocorrelation may or may not be closer to estimating this human perceived pitch period than other methods, but is certainly better than naively picking the FFT magnitude peak.

Interpolating the autocorrelation peak result may improve the pitch estimate.


Alternatively, if you look into the class of parametric model-based methods for pitch estimation [1], you'll find that it's fairly straight-forward to take inharmonicity [2] into account. In [3], a multi-pitch estimator for guitar signals is presented.

Some references that you can look into:

[1] M. G. Christensen and A. Jakobsson, "Multi-Pitch Estimation, ser. Synthesis lectures on speech and audio processing". Morgan & Claypool Publishers, 2009.

[2] H. Fletcher, "Normal vibration frequencies of a stiff piano string", in J. Acoust. Soc. Amer., vol. 36(1), 1962.

[3] T. Nilsson, S. I. Adalbjörnsson, N. R. Butt, and A. Jakobsson - "Multi-Pitch Estimation of Inharmonic Signals", in Proc. European Signal Processing Conf., 2014.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.