1
$\begingroup$

What I am trying to achieve is getting the fundamental frequency of a note played by an instrument. What I have already done is performing an FFT on a samples of audio file, and here's what I get:

FFT

After that I just tried to find the maximum value in that dataset and I get "4138". Unfortunately, the note being played in the audio file is an E and from internet I know that the E note should have 5274.04 Hz or 2637.02 Hz.
I continued reading some additional info on the internet and found interesting info that in some cases fundamental frequencies could be missing from the sound, so I have tried doing some autocorrelation on the samples I got from the audio file to find the fundamental frequency and I got something like this:

autocorrelation

It looked like a frequency domain for me so I performed FFT on that dataset but got similar results.
Also I have read that some people suggest using HPS (Harmonic Product Spectrum) for finding the fundamental frequency, I have tried that but obviously the result was the same, as the FFT itself didn't change.
P.S. Of course I use Hamming windowing function for samples. The library I use for FFT is JTransforms.

$\endgroup$
0
$\begingroup$

Ok, everything was working quite fine, the only thing that I have missed is another formula that is used to get the "real" frequency from the FFT power spectrum. And the formula is as follows:

frequency = indexMax * Fs / L;
where:
indexMax - index of the maximum in power spectrum;
Fs - sampling rate of an audio file;
L - length of the power spectrum array.

UPDATE
This approach is working fine for such trivial tasks as making a tuner or something like that, but as

robert bristow-johnson

pointed out, this implementation will, in some cases, ignore the fundamental frequency and potentially show you frequency of one of the harmonics. So a better approach would be

  • Autocorrelation
  • AMDF
  • ASDF
  • YIN
  • Mcleod Pitch method
$\endgroup$
  • 1
    $\begingroup$ hmmm. i wonder how well this will work for a note with a very low amplitude for the fundamental or 1st harmonic. $\endgroup$ – robert bristow-johnson May 8 '16 at 17:32
  • $\begingroup$ @robertbristow-johnson I have tried this one which looks like it doesn't have high amplitude, and the algorithm told me that the fundamental frequency is 131, while here it says that C3 = 130.81, seems legit :) As for the harmonics (or rather overtones) so far I haven't read enough information on implementing something to find number of overtones yet, maybe you could point out some algorithms/techniques for this purpose ? $\endgroup$ – Юрій Кравець May 8 '16 at 17:53
  • 1
    $\begingroup$ well, i wouldn't bother with an FFT-based pitch detection algorithm for musical notes. probably the best method i can quickly point to is described in this answer . about getting the values of the amplitudes of harmonics, my recommendation is to (using interpolation and the results of the pitch detection alg) mark off each period epoch and resample each period, from whatever number of samples long it is, to $N$ points and run the FFT on that. (wavetables) $\endgroup$ – robert bristow-johnson May 8 '16 at 21:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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