I use this FFT and wrote a short program to test it.

package test_FFT;
import org.apache.commons.math3.transform.FastFourierTransformer;
import org.apache.commons.math3.transform.DftNormalization;
import org.apache.commons.math3.transform.TransformType;

public class FFT2 {

public static void main(String[] args) {
    double[][] array=new double[2][8];
    //An array of complex numbers with real part array[0][*]
    //and complex part array[1][*]
    //The output of the transformation will be saved in the input array

    for(int i=0;i<8;i++){
        System.out.println("real "+array[0][i]);
        System.out.println("complex "+array[1][i]);



In the output array I get amplitudes of sin and cos functions. The information about the frequencies should depend on the position within the output array. After some research on this page, I still don't understand how to calculate frequencies out of array positions.

I learned that there are many flavours of how to perform a FFT. Has anyone of you detailed knowledge on how calculate frequencies out of output of the FFT I use? A code sample computing frequencies for the output of the example below would be greatly appreciated. Thank you

  • 1
    $\begingroup$ I guess this should answer your question. $\endgroup$
    – Matt L.
    Apr 1 '16 at 16:28

At this moment i'm not hos i can't check my answer... You say

In the output array I get amplitudes of sin and cos functions.

Well that is you frequency array. Probably not the way want it. I suspect youre looking for the magnitude and maybe the phase.

the magnitude is quite easy.. it is the $abs(array (real + imag)$. the phase $ \phi = \arctan \frac{imag}{real} $

in this way it is common to show the half the frequency array because of it's symmetry. if you plot $array[0]$ to $array[N/2]$ you shoult get your frequecy array from $ \frac{1}{N}$ to $\frac{F_s}{2}$

  • 1
    $\begingroup$ should this be from $0Hz$ to $\frac{Fs}{2}$ ? $\endgroup$ Apr 1 '16 at 19:35
  • $\begingroup$ You're right i mean it right but type it wrong (most of the time i use semilog plots so i almost never use the 0 bin) $\endgroup$
    – Jan-Bert
    Apr 2 '16 at 7:37

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.