From c643b22bfc91f7b01a0b0e20f59c6dc825b02eab Mon Sep 17 00:00:00 2001 From: Sebastien Brisard Date: Tue, 31 Jan 2012 07:02:58 +0000 Subject: [PATCH] Updates to FastFourierTransformer, following changes to RootsOfUnity in r1238179. See MATH-677. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1238180 13f79535-47bb-0310-9956-ffa450edef68 --- .../math/transform/FastFourierTransformer.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java b/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java index 836e563f0..d59db63e2 100644 --- a/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java +++ b/src/main/java/org/apache/commons/math/transform/FastFourierTransformer.java @@ -189,8 +189,7 @@ public class FastFourierTransformer implements Serializable { * not a power of two */ public Complex[] transform(Complex[] f) { - // TODO Is this necessary? - roots.computeOmega(f.length); + roots.computeOmega(-f.length); if (unitary) { final double s = 1.0 / FastMath.sqrt(f.length); return TransformUtils.scaleArray(fft(f), s); @@ -243,7 +242,7 @@ public class FastFourierTransformer implements Serializable { * not a power of two */ public Complex[] inverseTransform(Complex[] f) { - roots.computeOmega(-f.length); // pass negative argument + roots.computeOmega(f.length); final double s = 1.0 / (unitary ? FastMath.sqrt(f.length) : f.length); return TransformUtils.scaleArray(fft(f), s); } @@ -278,11 +277,11 @@ public class FastFourierTransformer implements Serializable { for (int i = 0; i < n; i++) { repacked[i] = new Complex(f[2 * i], f[2 * i + 1]); } - roots.computeOmega(isInverse ? -n : n); + roots.computeOmega(isInverse ? n : -n); Complex[] z = fft(repacked); // reconstruct the FFT result for the original array - roots.computeOmega(isInverse ? -2 * n : 2 * n); + roots.computeOmega(isInverse ? 2 * n : -2 * n); transformed[0] = new Complex(2 * (z[0].getReal() + z[0].getImaginary()), 0.0); transformed[n] = new Complex(2 * (z[0].getReal() - z[0].getImaginary()), 0.0); for (int i = 1; i < n; i++) { @@ -352,8 +351,8 @@ public class FastFourierTransformer implements Serializable { f[i] = a.add(b); f[i + 2] = a.subtract(b); // omegaCount indicates forward or inverse transform - f[i + 1] = roots.isForward() ? e2 : e1; - f[i + 3] = roots.isForward() ? e1 : e2; + f[i + 1] = roots.isCounterClockWise() ? e1 : e2; + f[i + 3] = roots.isCounterClockWise() ? e2 : e1; } // iterations from bottom to top take O(N*logN) time