0
$\begingroup$

So I'm currently working on a project where I need to find the frequencies for specific peaks in my FFT plot of an audio file. However, I'm not sure how to actually get the frequencies that correspond to the peaks I'm interested in.

This is my code: https://pastebin.com/zZW8B5Th

And this is a picture of my FFT plot: https://imgur.com/0ajtful

Essentially, I'm trying to construct a Fourier Series from the signal. Although I know how to find the coefficients of the sine/cosine terms, I'm just a little confused on how to find the frequency.

Thanks everyone!

$\endgroup$
1
$\begingroup$

MATLAB's indexing begins at 1, instead of 0, as most programming languages use. This causes a little wrinkle in interpreting the fft results. Index 1 corresponds to bin 0, index 2 to bin 1, etc. So to get the bin number, subtract 1 from the index.

The bin number corresponds to the frequency in units of cycles per frame, where frame is the section of the signal your are analysing. Usually, the variable $N$ is used to denote the number of samples in the frame. You also need to know the sampling rate, usually denoted by $f_s$ which usually has units of samples per second. CD quality audio has a sampling frequency of 44,100 samples per second.

To calculate the frequency in hertz (Hz) of a bin number, usually denoted with a $k$, do the following calculation:

$$ f_{HZ} = k \cdot \frac{f_s}{N} $$

The units for the equation goes like this:

$$ \frac{cycles}{second} = \frac{cycles}{frame} \cdot \frac{ \frac{samples}{second} }{ \frac{samples}{frame} } $$

Hope this helps,

Ced

$\endgroup$
  • $\begingroup$ thanks Dawggie for pointing out the indexing problem hard-coded into MATLAB. (something i have complained about for two decades.) Octave and R are no better. such a shame. $\endgroup$ – robert bristow-johnson Mar 6 '18 at 18:46

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.