0

I am using the FFT function from the Surge library. What is each element in the return array correlated with? How can I tell which frequencies correspond to which values?

For example, I am trying to find peaks in a certain frequency range.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
scord
  • 1,375
  • 1
  • 17
  • 34

1 Answers1

2

Generally for an FFT result, the array index corresponds to the discretised frequency "block" and the value is just the magnitude. Since you probably want to know the peak frequency and not the amplitude, the exact value of the latter is not that important.

The general steps are:

  1. get the array
  2. get the size of the array [1]
  3. find the max value in array [1]
  4. get the index of the max value [3]
  5. calculate frequency interval = sampleRate / size [2] / 2
  6. calculate the max frequency = index [4] * frequency interval
  7. return the frequency [6]
axelspark
  • 198
  • 10
  • 2
    Yes. A shorter answer would be just step 5. Note that the complex fourier transform of a real vector is redundant, so only the first half of the returned amplitudes are needed. You start at frequency zero and then every step is a frequency interval given by (5). It is always a good idea to plot the result (or it's absolute value) to make sure a given library doesn't 'roll' or 'rotate' your result vector. In that case you'd throw away the first half of your result and just use the 2nd half. – roadrunner66 Sep 06 '17 at 02:03
  • what is the unit of sampleRate? is it seconds^-1 or Hertz – scord Sep 06 '17 at 02:38
  • Hertz is seconds^-1 =) – axelspark Sep 06 '17 at 02:39
  • clarifying, equation 5 is equal to: f_i = sampleRate / (size * 2) – scord Sep 06 '17 at 02:52
  • 1
    yes sorry for the ambiguity. as @roadrunner66 has mentioned, only half of the amplitudes are used thus the 2 in the equation – axelspark Sep 06 '17 at 02:57