0
$\begingroup$

I've seen many posts here that state that an FFT is almost all you need to get the fundamental frequency from an input stream. The problem is that, with sound, this doesn't work; we need to look for periodicity as well. I know that autocorrelation is useful in this arena, but even then, I am unfamiliar with how one would extract the fundamental frequency from the data after autocorrelation. Also, I am aware that there are alternative methods as well.

I am not interested in the easiest solution; I am interested in 1: the most efficient solution and 2: the most accurate solution, especially if these are mutually exclusive.

$\endgroup$
  • 1
    $\begingroup$ Are you interested in human speech, a musical instrument, or something else ? $\endgroup$ – Paul R Oct 13 '12 at 12:50
  • $\begingroup$ You might also want to look into f0-estimation as this is another name for this topic. $\endgroup$ – CyberMen Oct 15 '12 at 19:51
4
$\begingroup$

FFTs alone are lousy at pitch estimation for many really common sound sources, including male voices, and low piano or guitar notes. Thus, the comments that an FFT is all you need are false and misleading. (Although FFTs can be used as components of a more accurate composite pitch detection algorithm.)

When using autocorrelation, after you remove or discount subharmonic lag peaks, the pitch frequency may be around or close to the reciprocal of the time lag corresponding to the autocorrelation peak.

Pitch often refers to the human perception of such, and thus an estimate sometimes needs to include psycho-acoustics effects and illusions. There are multiple methods for, and lots of book chapters and research papers on this problem of pitch detection. How well each algorithm works might depend on your particular sound source and requirements.

Pitch detection/estimation methods include lag estimators, such as autocorrelation, weighted autocorrelation, AMDF and ASDF; and frequency domain analysis methods based on initial FFTs, such as cepstral/cepstrum methods, and the harmonic product spectrum algorithm. Composite methods, and ones that use some decision analysis are less easy, but can be more accurate or robust for some sound sources. Look for YIN, RAPT and YAAPT. This list is by no means exhaustive.

$\endgroup$
2
$\begingroup$

Auto-correlation is a very good start. I've written a brief blog post with an illustration comparing auto-correlation to a simple Fourier transform of the same data.

If the input signal is periodic, the Fourier transform will have a peak at the corresponding frequency. However, as I describe in the post linked above, it is not a very accurate estimate of that frequency. Auto-correlation gives you a better estimate.

A third method that I've heard about but haven't tried yet is to use overlapping windows. I think the basic algorithm is this: 1) Do a Fourier transform of the input, find the strongest peak (absolute value). 2) Shift the window forward by exactly one wavelength of that strongest peak 3) Compare the phase (i.e. angle of the complex number) for that frequency in the two Fourier transforms. 4) Compute a better estimate of wavelenth/phase.

I think it would be something like this:

$p_0, p_1 $ : Phase of the two frequency components in Radians

$l$ : Wavelength of the selected frequency component

$l_{est}$ : Estimate of the wavelength of the true frequency

$l_{est} = l * (1+\frac{(p_1 - p_0)}{2\pi}) $

If you shift the window by one wavelength, and it exactly matches the underlying wavelength, then $p_0 = p_1$, and $l$ is a good estimate of the true wavelength. This happens when the window size is a multiple of the fundamental wavelength. If the fundamental wavelength is slightly less than that, when you shift the window, the phase of the signal will be greater. The fundamental is shorter than distinace you've shifted the window, so the phase is greater than it was before, so $p_1 > p_0$

Note: It's important that you shift the window in the original sample. If you just rotate the buffer (bringing in the first few samples and putting them at the end), then your fourier transform will be identical and the phase will be shifted by exactly the amount you've rotated the buffer.

$\endgroup$

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.