Understanding FFT output Understanding FFT output java java

Understanding FFT output


  1. You should neither look for the real or imaginative part of a complex number (that what's your real and imaginary array is). Instead you want to look for the magnitude of the frequency which is defined as sqrt (real * real + imag * imag). This number will always be positive. Now all you have to search is for the maximum value (ignore the first entry in your array. That is your DC offset and carries no frequency dependent information).

  2. You get 32 real and 32 imaginary outputs because you are using a complex to complex FFT. Remember that you've converted your 32 samples into 64 values (or 32 complex values) by extending it with zero imaginary parts. This results in a symetric FFT output where the frequency result occurs twice. Once ready to use in the outputs 0 to N/2, and once mirrored in the outputs N/2 to N. In your case it's easiest to simply ignore the outputs N/2 to N. You don't need them, they are just an artifact on how you calculate your FFT.

  3. The frequency to fft-bin equation is (bin_id * freq/2) / (N/2) where freq is your sample-frequency (aka 32 Hz, and N is the size of your FFT). In your case this simplifies to 1 Hz per bin. The bins N/2 to N represent negative frequencies (strange concept, I know). For your case they don't contain any significant information because they are just a mirror of the first N/2 frequencies.

  4. Your real and imaginary parts of each bin form a complex number. It is okay if real and imaginary parts are negative while the magnitude of the frequency itself is positive (see my answer to question 1). I suggest that you read up on complex numbers. Explaining how they work (and why they are useful) exceeds what is possible to explain in a single stackoverflow-question.

Note: You may also want to read up what autocorrelation is, and how it is used to find the fundamental frequency of a signal. I have a feeling that this is what you really want.


You already have some good answers, but I'll just add that you really need to apply a window function to your time domain data prior to the FFT, otherwise you will get nasty artefacts in your spectrum, due to spectral leakage.


1) Look for the indices in the real array with the highest values, besides the first one (that's the DC component). You'll probably need a sample rate considerably higher than 32 Hz, and a larger window size, to get much in the way of meaningful results.

2) The second half of both arrays is the mirror of the first half. For instance, note that the last element of the real array (1.774) is the same as the second element (1.774), and the last element of the imaginary array (1.474) is the negative of the second element.

3) The maximum frequency you can pick up at a sample rate of 32 Hz is 16 Hz (Nyquist limit), so each step is 2 Hz. As noted earlier, remember that the first element is 0 Hz (i.e, the DC offset).

4) Sure, a negative amplitude makes perfect sense. It just means that the signal is "flipped" -- a standard FFT is based on a cosine, which normally has value = 1 at t = 0, so a signal which had value = -1 at time = 0 would have a negative amplitude.