I am working with this STFT method to detect pitch in monophonic guitar audio signals.

The method is working correctly for medium pitches (above 150Hz). However, in low notes I have some issues.

For example, I have an audio file that had the A2, A#2 and B2 notes played. So, the pitches detected should be approximately 110, 116, 123. When I ran the STFT with 40000 as a sampling rate, there was an octave error in all of them. The notes detected were A3, A#3 and B3.

I though I should see why this happens and I went in my STFT, and printed, for each note played, the 5 strongest bins in terms of magnitude. Those were the results:

First note: [539.49506, 975.88092, 419.11325, 326.00168, 217.16208]

Second note: [0.0, 0.0, 573.76556, 229.9518, 117.29102]

Third note: [0.0, 240.0067, 0.0, 118.64342, 0.0]

As you can see, for the first note, the correct pitch is not even amongst the 5 max. magnitudes. For the second and third notes, they are amongst the top 3 but not enough to become the selected pitches.

I tried to do the same with a sampling rate of 30000, and I still had the same problem, but this time the correct pitch was in the top 5 for the first note.

I know how to fix this problem, so my question is more theoretical. How can the sampling rate affect this? Why did this happen with 40000 and not 30000? In the end, how should I decide on my SR final value?

As a follow-up question, I see that I can also choose on other parameters like the n_fft (number of FFT bins or FFT size) and hop_length. How should I choose on those? What are upsides and downsides for high/low values (if the answer is too long to answer, then a reference would be great).


1 Answer 1


The octave error is because you are using a spectral frequency estimator (STFT), not a psychoacoustic pitch detection or estimation method. The spectral frequency peaks in the sound are often not the pitch frequency, but instead often one of the many harmonics. As you found, the fundamental pitch frequency can even be completely missing. This is especially true for guitar notes, voices, and sounds from other large stringed instruments.

The solution is not to play with sample rate and STFT FFT window parameters, but to look up more reliable pitch detection and estimation algorithms.

  • $\begingroup$ Sure. What if, from the 5 strongest frequencies, I get the max. common divisor? I think that's the concept of the HPS? However, the question is how the change of the sample rate changed my results, and how other parameters can change it as well. $\endgroup$
    – pavlos163
    May 18, 2017 at 14:22
  • $\begingroup$ HPS is a pitch estimator for some timbres. Changing FFT length changes time/frequency resolution trade-off. Changing sample rate can sometimes change other artifacts (random?). $\endgroup$
    – hotpaw2
    May 18, 2017 at 14:30
  • $\begingroup$ What do you mean HPS is a pitch estimator for some timbres? This question is specifically for the guitar. You mentioned "more reliable pitch detection and estimation algorithms". Is the HPS one of them? $\endgroup$
    – pavlos163
    May 18, 2017 at 16:03
  • $\begingroup$ That's a good question that could be asked as a new separate question. $\endgroup$
    – hotpaw2
    May 18, 2017 at 16:16
  • $\begingroup$ i don't even know what "HPS" is. $\endgroup$ Mar 23, 2018 at 3:39

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.