Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPS method estimation error #9

Open
pavlos163 opened this issue May 30, 2017 · 5 comments
Open

HPS method estimation error #9

pavlos163 opened this issue May 30, 2017 · 5 comments

Comments

@pavlos163
Copy link

I am using freq_from_hps as described here to detect pitch in monophonic guitar samples.

I noticed that the results I get often have a slight estimation error which is always +10-15Hz. For example, when I want to detect pitch for this audio file (see end of post for the correct pitches) I get:

[['F4'], ['F#4'], ['G4'], ['G#4'], ['A4'], ['A4'], ['A#4'], ['B4'], ['C5'], ['C#5'], ['D5'], ['D#5'], ['E5'], ['F5'], ['F#5'], ['G5'], ['G#5'], ['A5'], ['A#5'], ['B5'], ['C6'], ['C#6'], ['F4']]

When I increase every of these pitches by 10Hz I get:

[['E4'], ['F4'], ['F#4'], ['G4'], ['G#4'], ['A4'], ['A#4'], ['B4'], ['C5'], ['C#5'], ['D5'], ['D#5'], ['E5'], ['F5'], ['F#5'], ['G5'], ['G#5'], ['A5'], ['A#5'], ['B5'], ['C6'], ['C#6'], ['E4']]

Which is actually 100% correct.

This basically happens for almost every note below G#4 (and above E2). What could be the issue here? Any ideas about how there is such a fixed estimation error?

Furthermore, as I am designing this application specifically for the guitar, do you have any recommendations/tips as to how I could optimise this method?

Thanks.

@endolith
Copy link
Owner

endolith commented Jun 11, 2017

I cut out 2.4 to 4.0 seconds, which should be E4 = 329.63 Hz:

  • freq_from_fft says 329.366907 Hz (E4 -1 cent)
  • freq_from_crossings says 634.629287 Hz, (which I would expect to be wrong because it's not a sine)
  • freq_from_autocorr says 329.605440 Hz (E3 -0 cent)
  • freq_from_hps says 330.929520 Hz (E3 +6.8 cents)
  • freq_from_hps says 329.405667 Hz (E3 -1 cent) after changing to decimate(X, h, zero_phase=True) (which it probably should be)

So it looks like it's working to me. It's off by 1.3 Hz in the worst case, not 10 Hz.

>>> filename = "E4 only.wav"
>>> signal, fs, channels = load(filename)
>>> freq_from_hps(signal, fs)
329.40566724171208

@endolith
Copy link
Owner

Looks like I should also have de-meaned the spectra before summing them. HPS function was only half-finished

@endolith
Copy link
Owner

endolith commented Jun 11, 2017

With a 1 kHz sqrtsin test wave, and zero_phase=False (default):

1000.462192 Hz

Harmonic product spectra being summed with zero_phase=False

After changing to zero_phase=True:

1000.018354 Hz

Harmonic product spectra being summed with zero_phase=True

So the decimation was making it inaccurate, but your inaccuracy seems a lot higher?

@endolith
Copy link
Owner

Possibly fixed in 12325d5?

@endolith
Copy link
Owner

endolith commented Sep 8, 2018

@pavlos163

Have you tried it since I fixed the bug in HPS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants