0

i don't know what to do after obtaining a set of complex numbers from FFT on a wav file.How could i obtain the corresponding frequencies.This is output i got after performing FFT which is shown below

[ 12535945.00000000    +0.j            -30797.74496367 +6531.22295858j
    -26330.14948055-11865.08322966j ...,     34265.08792783+31937.15794965j
    -26330.14948055+11865.08322966j    -30797.74496367 -6531.22295858j]
Femaref
  • 60,705
  • 7
  • 138
  • 176
zzz
  • 1
  • 1
  • 1
  • 2
    possible duplicate of [how to extract frequency associated with fft values in python](http://stackoverflow.com/questions/3694918/how-to-extract-frequency-associated-with-fft-values-in-python) – kennytm Sep 12 '10 at 15:09

3 Answers3

4

Actually the abs(x) operation only converts a real/imaginary pair from your result list into a magnitude. Do that unless you want to keep the imaginary portion for future use. So after conversion, each number in the result list represents a magnitude of signal at a certain frequency in your frequency spectrum. So frequency is represented by list index. When you plot the data on an XY graph, what you see is the magnitude of frequencies that your source signal contains. Don't forget that only your first half of data is valid. The other half is usually a mirror image of the first half due to aliasing.

For example say you run a 1024 point FFT on a wav file that contains data sampled at 10Khz. The FFT will take that 10Khz spectrum and divide that into 1024 'bins'. Then the FFT will decide how much each chunk of spectrum is present in the source wav file. Your output should be those bins. Generally when I do a frequency analysis, the actual numbers I get back aren't what's important. Its the magnitudes relative to surrounding bins that I'm interested in.


For a little more detail, we're relying on the principle of superposition which states that any time-varying signal containing many frequencies can be split up into many signals containing one component frequency each and vice versa. So the FFT output reflects this property. Each value of your output list represents a magnitude for a signal at a single frequency (usually called a 'bin') that is present in your source signal. Combine all those signals together and you should get your source signal back.

Oh and in case you didn't know, only the first half of your result list is valid due to Nyquist's Rule (or law, not sure) which says that all sampling systems can only reproduce frequencies in a signal that is at most half the sampling frequency. So if you sample a signal at 10Khz, you can only reproduce frequencies up to 5Khz from the data taken during your sampling. The same principle is the reason why only the first half of your FFT data is valid. The second half is an alias of the first half.

Sorry for the long-winded explanation, your question doesn't indicate what experience you have so I thought an explanation of the general gist of an FFT is needed.

spade78
  • 1,939
  • 1
  • 20
  • 29
  • 2
    Actually, `numpy.abs` doesn't quite just strip out the imaginary portion. It returns the magnitude of a complex number. E.g.: `sqrt(a^2 + b^2)` for the complex number `a + ib`. See http://www.scipy.org/Numpy_Example_List_With_Doc#head-dcec325e12b04ed82f0db9149deed4f8073eddf9 Still, nice general explanation! – Joe Kington Sep 12 '10 at 16:12
1

As @KennyTM already explained on the duplicate question:

The frequency is determined by the index of the array. Each element corresponds to a frequency.

To determine the frequency of that each element represents, you need to know the sampling frequency of your data and the length of the array.

Basically, it would be something like:

sampling_freq = 1000.0 # in Hz
freq = np.linspace(0, (1.0 / sampling_freq / 2.0), (x.size / 2) + 1)

For one half of the fft array (which is symmetric about the center). My memory is rusty, though, so this may be a bit off...

Either way, numpy has a helper function to do it for you: numpy.fft.fftfreq

Joe Kington
  • 275,208
  • 71
  • 604
  • 463
0

If I'm not mistaken, the frequency can be obtained by calculating the magnitude of the complex number. So a simple abs(x) on each of those complex numbers should return the frequency.

Federico Cáceres
  • 1,216
  • 12
  • 19