In analyzing the audio recording of a string instrument, I am struggling with pitch estimation. I am using the pYIN algorithm and every pitch estimation I'm obtaining is off by one octave. I assume that's caused by the fact that they're using the FFT. Looking at a spectrogram I observe that the second harmonic lasts longer and has more power. I assume that this causes the octave error.

My questions therefore are:

  • Under what conditions is the second harmonic more prominent than the fundamental?
  • How can this effect be mitigated in the context of pitch estimation?
  • $\begingroup$ well, I think you answered your question yourself: you mitigate this by not assuming the fundamental (==0. harmonic) is the strongest harmonic. How to then still estimate pitch? I don't know; I guess it's really a hard field, but having identified a wrong assumption, you'll have to work without that assumption. $\endgroup$ Jul 27, 2021 at 17:23
  • 1
    $\begingroup$ This question over at music.SE is very related. Maybe its answers are useful for you. $\endgroup$
    – Matt L.
    Jul 27, 2021 at 19:30
  • $\begingroup$ This question should also shed some light. Basically, what we perceive as a musical pitch is determined by the harmonic structure of the sound; efforts to identify pitch, then, depend on understanding not just the DSP aspects, but the psychoacoustics. $\endgroup$
    – TimWescott
    Jul 28, 2021 at 2:51
  • 2
    $\begingroup$ the "first harmonic" and the "fundamental" are the same frequency component. did you perhaps mean the first overtone (which is the second harmonic)? $\endgroup$ Jul 28, 2021 at 4:07
  • $\begingroup$ Thanks for your answers $\endgroup$
    – HyperToken
    Jul 28, 2021 at 9:24

3 Answers 3


If your input signal features many strong harmonics that are all strict multiples of a (possibly attenuated) fundamental, it seems reasonable to look into cepstrum analysis, as that finds the periodicity of the spectrum.

Pitch analysis has been studied for a long time and it is evidently hard to get generally and robustly «right». I wonder if a panel of music theorists would always agree on pitch of a recording. Probably?



You mention using pYIN, which was considered state-of-the-art in pitch/fundamental frequency estimation up until recently. The little hacks and suggestions here are misplaced - I don't think you'll make pYIN significantly better.

The next step up is CREPE, the current best performing pitch detection algorithm with a deep neural network: https://github.com/marl/crepe, https://arxiv.org/pdf/1802.06182.pdf

Best performing techniques such as the pYIN algorithm, are based on a combination of DSP pipelines and heuristics. [...] we propose a data-driven pitch tracking algorithm, CREPE, which is based on a deep convolutional neural network that operates directly on the time-domain waveform.

I would give CREPE a try on your data.

Also, I maintain a small collection of pitch tracking/fundamental frequency estimation algorithms: https://github.com/sevagh/pitch-detection. Among them are YIN, pYIN, MPM (McLeod pitch method), SWIPE, and a few others. You might want to try those too to check which is the most useful for your data.

  • $\begingroup$ Can you refer us to a paper, with math, not code (or not only code) that describes or derives the CREPE pitch detection algorithm? I have found YIN to be hyped and not particularly impressive (I have written far better deterministic pitch detectors ). I never really groked pYIN but am still not impressed. But I would very much like to read a technical paper describing CREPE. $\endgroup$ Sep 27, 2021 at 19:23
  • $\begingroup$ The arXiv paper was linked above: arxiv.org/pdf/1802.06182.pdf However, I'm pretty sure the details are "neural networks are magic", rather than any specific pitch/math/DSP knowledge. $\endgroup$
    – Sevag
    Sep 27, 2021 at 20:43
  • $\begingroup$ CREPE was trained solely on active frames so, by experience it performs weirdly when the frame is silent and it is not an online algorithm. $\endgroup$
    – HyperToken
    Jun 10, 2022 at 13:34

I need to understand in which conditions the second harmonic is more prominent rather than the fundamental frequency

That's just the way musical instruments are build and how sound propagation works. In fact, this is quite common simply because there is no physical reason of why the fundamental should have the most energy. For example the bridge pick up of an electric guitar is specifically placed to pick up as little fundamental as possible. There are even sounds that have no fundamental at all and you will still perceive the correct pitch.

and how to mitigate this effect.

There are plenty pitch detection algorithms out there. Personally I like phase locked loops or delay locked loops since they can track very accurately in real time.

  • $\begingroup$ Thanks for your answer, I know this is a bit out of scope but could you tell me briefly what phase locked loops is trying to solve here? $\endgroup$
    – HyperToken
    Jul 28, 2021 at 9:23

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.