This is a library for computing 1-2 dimensional Fourier Transform. It was written with Java 8, and should be Android-compatible (you can use it in an Android project). This library was written without any compile dependencies.
You can import it with maven.
If you are more familiar with the old implementation (version 1.0), consult the legacy branch
<dependency>
<groupId>com.tambapps.fft4j</groupId>
<artifactId>fft4j</artifactId>
<version>2.0</version>
</dependency>
Here is an example of a 1D fast fourier transform. There are several algorithms to perform FFT You can see all of them on the FastFouriers class.
double[] inputRe = getInputDataRe();
double[] inputIm = getInputDataIm();
double[] outputRe = new double[inputRe.length];
double[] outputIm = new double[inputRe.length];
FastFouriers.BASIC.transform(inputRe, inputIm, outputRe, outputIm);
// consult result in outputRe and outputIm
You can also use a Signal
which encapsulates a real and imaginary double arrays.
Signal input = inputData();
Signal output = FastFouriers.BASIC.transform(input);
3 different Fast Fourier Algorithms were implemented
This is a trivial implementation of a Fourier Transform using the basic Fourier Transform formula
A recursive implementation of the Cooley–Tukey FFT algorithm. Note that this algorithm requires the input length to be a power of 2.
An iterative implementation of the Cooley–Tukey FFT algorithm Note that this algorithm requires the input length to be a power of 2.
You can apply 2D FFT with a FastFourierTransformer2D. You can change the algorithm used by the transformer to compute fft by setting the AlgorithmChooser.
Signal2d signal2d = new Signal2d(M, N);
fill(signal2d);
FastFourier2d transformer2D = new FastFourier2d();
transformer2D.transform(signal2d);
// do some things with the fourier transform
transformer2D.inverse(signal2d);
// don't forget to shut it down as it uses an executor service
transformer2D.shutdown();
You can consult the fft-image-processing repo, an app that transforms images using FFT