Created
November 8, 2012 06:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
You are great!! Thank you for this sample!!
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
thanks, for me this was a critical bit of info to get this working. just a few notes ...
import org.jtransforms.fft.DoubleFFT_1D;
https://github.com/IcmVis/JLargeArrays
0.7862
0.0
-0.8283067304251197
-0.3991936433800569
-0.2874
-0.2348
0.9799067304251197
0.09400635661994317
-0.37379999999999997
0.0
0.9799067304251197
-0.09400635661994317
-0.2874
0.2348
-0.8283067304251197
0.3991936433800569
System.out.println("get back");
fftDo.complexInverse(fft,true);
for (double d: fft)
System.out.println(d);