1
$\begingroup$

Sorry if this is a stupid question but so far i have learned that after getting the results of a FFT (an array of complex numbers) you can get the frequency of a sound sample via the following:

1) Calculate the peak for each complex number: $\sqrt{\mathrm{real}^2 + \mathrm{imag}^2}$

2) Get the index of the array element with the highest peak.

3) Index $\times$ mhz of the sample audio $/$ number of elements in the array

This seems to work however I'm wondering if the second-highest peak would be the second "most present" frequency, and so on. So for example, if I had a guitar chord, and I got the top 6 frequencies, would those be the notes of a 6 stringed chord?

$\endgroup$
1
  • 1
    $\begingroup$ Ben, do you know about harmonics? you can pluck one single note on the guitar and still get multiple frequencies from your FFT analysis. how should your software interpret that? $\endgroup$ Jun 20, 2017 at 16:08

4 Answers 4

1
$\begingroup$

Unlikely. The top 6 FFT magnitudes would more probably contain several overtones or harmonics that are stronger than the 6 note pitches in a chord. Furthermore, some of the spectral frequency peaks can be between FFT bins, depending on the length of the FFT. So the frequency you've calculated by just multiplying by a bin index could be different from any pitch frequency in the audio. Depending on any window used, you might also find windowing artifacts in the FFT magnitude spectrum.

$\endgroup$
0
$\begingroup$

I do not have enough reputation to comment on @hotpaw2's answer and so I am writing this as an answer. It is somewhat easy to detect if the second, third and the subsequent peaks are harmonics or not; The frequency would be a multiple of the first peak if it is a harmonic. If you take a large enough FFT (higher freq resolution) this should be fairly accurate and it also solves your other problem.

$\endgroup$
3
  • $\begingroup$ sorry, i'm not too familiar with signal processing, why does the frequency of other notes have to be multiple of the highest peak?? $\endgroup$
    – Ben Arnao
    Jun 21, 2017 at 18:20
  • $\begingroup$ No, I meant to say that since harmonics of the peak signal will be at multiples of freq corresponding to the peak signal, you can discard them and locate the other peaks which will likely correspond to the other notes. Of course, this will fail if the notes are too close to the harmonics of the peak signal. $\endgroup$ Jun 21, 2017 at 19:14
  • $\begingroup$ Hmm i see, thanks for clarifying. Based on my data i'm not seeing too many harmonics though... is that normal? $\endgroup$
    – Ben Arnao
    Jun 21, 2017 at 20:46
0
$\begingroup$

You have to be careful about peaks and the order of magnitudes. A peak is higher than its left and right neighbors but you can have the second strongest amplitude next to the highest amplitude and so forth.

$\endgroup$
0
$\begingroup$

An FFT does not perform frequency analysis. It is an efficient building block for constructing frequency analysis tools. It delivers interpretable results for periodic signals with a periodicity of exactly the transform window. If you have a rotating machine and take samples at fixed regular angles of rotation, stationary results are directly interpretable (short of aliasing which is still an issue). This is almost never the case for sound samples, so the conditions for which you can directly interpret frequency bins are not met.

A variety of windowing techniques are usually employed to make stuff more interpretable in line with naive expectations. If you don't do that, there is a large variation in how what you consider "the same situation" may pan out in the analysis data.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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