3

I am developing a flash guitar, and the only apparent method to discover the frequency of the mic's data looks to be using FFT. Nevertheless, after something like 30 hours of research I could not discover the best way to do that. Should I use Harmonic Product Spectrum (HPS), Cepstrum or Maximum Likelihood? The tuner will have to show frequencys from 25 to 3000Hz.

Also, if someone knows about some open source code ready to find the fundamental frequency, please tell me. I can translate it to ActionScript.

Thanks!

Lucas Speranza
  • 149
  • 1
  • 3
  • 5

3 Answers3

7

The simplest technique I've had success with is to use FFT and then perform a Harmonic Product Spectrum. It is simple to implement and not very resource intensive, you just need to correctly downsample your result FFT and make products.

The following question should also be useful: Detecting the fundamental frequency

Community
  • 1
  • 1
shams
  • 3,460
  • 24
  • 24
1

I try to reply with my basic remembrance: when ytou have the FFT of your signal, the fundamental isn't te one with the maximum amplitude ?

Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • 3
    No, it ain't. It's the first harmonic of the spectrum. – Nemeth Feb 06 '11 at 17:22
  • 1
    @Nemeth: "first harmonic" is a synonym for "fundamental" as far as I know, and it generally does have the maximum amplitude. – Jim Lewis Feb 06 '11 at 17:34
  • 1
    @Jim: for many instruments the fundamental does *not* have the highest amplitude - I'm not sure about guitars, but it may depend on the note and the type of guitar. Either way, it's better to use a proper *pitch detection* algorithm, rather than arbitrarily looking at single components such as the fundamental. – Paul R Feb 06 '11 at 17:46
  • @Paul: For a plucked guitar string, the max amplitude in the harmonic series will be the fundamental. For brass instruments, it's true that many notes are produced as 2nd, 3rd, 4th etc. overtones of the fundamental. Guitar is usually notated an octave higher than it actually sounds, which can also confuse things a bit... – Jim Lewis Feb 06 '11 at 18:25
  • @Jim: bowed instruments, e.g. violin and cello, typically have very little energy at the fundamental. Note that pitch perception works pretty well even when the fundamental is completely absent. – Paul R Feb 06 '11 at 18:27
  • @Paul: Thanks for the examples! I had never heard of "Helmholtz motion" before...there's some interesting physics going on there. – Jim Lewis Feb 06 '11 at 19:48
  • @Jim You are right, it is the definition, so it is a synonym.The average spectrum have the maximum amplitude at the first harmonic, as you can see here https://kb.osu.edu/dspace/bitstream/handle/1811/45171/EMR000084a_Plazak_Huron_Williams.pdf;jsessionid=D973DB4DC6D871B301AA4EA2AFE6C881?sequence=1 but it ain't necessary so, as well explained by @Paul. Actually, it is hard to define a fundamental tone for musical instruments, as they are actually semi-periodic. – Nemeth Feb 07 '11 at 18:57
0

The FFT it's not the best way to find a fundamental frequency of a musical instrument. Actually, yes, it would be a better idea to use cepstrum. You can find a similar questions here: Algorithm to determine fundamental frequency from potential harmonics and here : MATLAB - Missing fundamental from an FFT

Community
  • 1
  • 1
Nemeth
  • 1,070
  • 1
  • 11
  • 16
  • What should I use instead of FFT? – Lucas Speranza Feb 07 '11 at 18:28
  • You could use autocorrelation : http://en.wikipedia.org/wiki/Autocorrelation But, as you are working with a guitar, it seems to me that pitch it's a more important concept than fundamental tone here. So you should see RAPT (robust algorithm for pitch tracking) here : http://www.ee.columbia.edu/~dpwe/papers/Talkin95-rapt.pdf – Nemeth Feb 07 '11 at 19:00
  • According to articles RAPT is a very good algorithm. However I have seen one opensource implementation of this in C and it had hundreds of lines. – mmatloka Feb 07 '11 at 19:52
  • Cepstrum is slow and complicated. You should use bitstream autocorrelation: http://www.cycfi.com/2018/03/fast-and-efficient-pitch-detection-bitstream-autocorrelation/ – AldaronLau Jun 12 '18 at 03:18