Skip to content

Instantly share code, notes, and snippets.

@jukworks
Created November 8, 2012 06:34
Show Gist options
  • Save jukworks/4037243 to your computer and use it in GitHub Desktop.
Save jukworks/4037243 to your computer and use it in GitHub Desktop.
A Sample Code: Getting a Real FFT of 1D array using jTransform library.
import edu.emory.mathcs.jtransforms.fft.DoubleFFT_1D;
public class FftTest {
public static void main(String[] args) {
double[] input = new double[]{
0.0176,
-0.0620,
0.2467,
0.4599,
-0.0582,
0.4694,
0.0001,
-0.2873};
DoubleFFT_1D fftDo = new DoubleFFT_1D(input.length);
double[] fft = new double[input.length * 2];
System.arraycopy(input, 0, fft, 0, input.length);
fftDo.realForwardFull(fft);
for(double d: fft) {
System.out.println(d);
}
}
}
@EvgenyYankovskiy
Copy link

This is not entirely correct if you set a signal with a period T = 1 s, that is, the frequency should be 1 Hz, then with this code you will see 2 Hz. More correct would be DoubleFFT_1D fftDo = new DoubleFFT_1D(input.length / 2);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment