FFT { public static void transform(double[] real, double[] imag, boolean inverse) { if (real == null || imag == null) throw new NullPointerException("Received null argument"); if (real.length != imag.length) throw new IllegalArgumentException("Arrays must be equal length"); int N = real.length; assert MathUtils.isPowerOfTwo(N); int halfN = N/2; int iReverse = 0; for (int i=0; i<N; i++) { if (i > iReverse) { double tmpReal = real[i]; double tmpImag = imag[i]; real[i] = real[iReverse]; imag[i] = imag[iReverse]; real[iReverse] = tmpReal; imag[iReverse] = tmpImag; } int b = halfN; while (b>=1 && iReverse>=b) { iReverse -= b; b >>= 1; } iReverse += b; } for (int blockLength = 2, powerOfTwo=1; blockLength <= N; blockLength <<= 1, powerOfTwo++) { double wStepReal = cosDelta[powerOfTwo]; double wStepImag = sinDelta[powerOfTwo]; if (inverse) wStepImag = -wStepImag; double wReal = 1; double wImag = 0; int halfBlockLength = blockLength / 2; for (int n=0; n<halfBlockLength; n++) { for (int i=n; i<N; i+=blockLength) { int j = i+halfBlockLength; double tmpReal = wReal*real[j] - wImag*imag[j]; double tmpImag = wReal*imag[j] + wImag*real[j]; real[j] = real[i] - tmpReal; imag[j] = imag[i] - tmpImag; real[i] += tmpReal; imag[i] += tmpImag; } double oldWReal = wReal; wReal = oldWReal*wStepReal - wImag*wStepImag; wImag = oldWReal*wStepImag + wImag*wStepReal; } } if (inverse) { for (int i=0; i<N; i++) { real[i] /= N; imag[i] /= N; } } }  static double[] computeLogPowerSpectrum(final double[] signal); static double[] computeLogPowerSpectrum_FD(final double[] fft); static double[] computePowerSpectrum(final double[] signal); static double[] computePowerSpectrum_FD(final double[] fft); static double[] computeLogAmplitudeSpectrum(final double[] signal); static double[] computeLogAmplitudeSpectrum_FD(final double[] fft); static double[] computeAmplitudeSpectrum(final double[] signal); static double[] computeAmplitudeSpectrum_FD(final double[] fft); static double[] computePhaseSpectrum_FD(final double[] fft); static void transform(double[] real, double[] imag, boolean inverse); static void transform(double[] realAndImag, boolean inverse); static void realTransform(double data[], boolean inverse); static double[] convolveWithZeroPadding(final double[] signal1, final double[] signal2, double deltaT); static double[] convolveWithZeroPadding(final double[] signal1, final double[] signal2); static double[] convolve(final double[] signal1, final double[] signal2, double deltaT); static double[] convolve(final double[] signal1, final double[] signal2); static double[] convolve_FD(final double[] signal1, final double[] fft2, double deltaT); static double[] convolve_FD(final double[] signal1, final double[] fft2); static double[] correlateWithZeroPadding(final double[] signal1, final double[] signal2); static double[] correlate(final double[] signal1, final double[] signal2); static double[] autoCorrelate(final double[] signal); static double[] autoCorrelateWithZeroPadding(final double[] signal); static void main(String[] args);  }
@Test public void testTransform() { double[] signal = getSampleSignal(1024); double[] real = new double[signal.length]; System.arraycopy(signal, 0, real, 0, signal.length); double[] imag = new double[signal.length]; FFT.transform(real, imag, false); FFT.transform(real, imag, true); double err = MathUtils.sumSquaredError(signal, real); Assert.assertTrue("Error: "+err, err<1.E-16); }