Java API By Example, From Geeks To Geeks.

# Java > Open Source Codes > JSci > maths > FourierMath

 `1 package JSci.maths;2 3 /**4 * The Fourier math library.5 * This class cannot be subclassed or instantiated because all methods are static.6 * Use sort(transform(sort(...))) for the discrete analogue of the continuous Fourier transform,7 * and sort(inverseTransform(sort(...))) for the inverse transform.8 * @jsci.planetmath FourierTransform9 * @version 0.910 * @author Mark Hale11 */12 public final class FourierMath extends AbstractMath implements NumericalConstants {13         private FourierMath() {}14 15         /**16         * Fourier transform.17         * @return an array containing positive frequencies in ascending order18         * followed by negative frequencies in ascending order.19         * @author Don Cross20         */21         public static Complex[] transform(final Complex data[]) {22                 final int N=data.length;23                 if(!isPowerOf2(N))24                         throw new IllegalArgumentException ("The number of samples must be a power of 2.");25 26                 final double arrayRe[]=new double[N];27                 final double arrayIm[]=new double[N];28 29                 final int numBits=numberOfBitsNeeded(N);30 // Simultaneous data copy and bit-reversal ordering into output31 for(int i=0;i0)243                                 return i;244                 }245         }246         /**247         * Reverse bits.248         * @author Don Cross249         */250         private static int reverseBits(int index,final int numBits) {251                 int i,rev;252                 for(i=rev=0;i>=1;255                 }256                 return rev;257         }258 259         /**260         * Sorts the output from the Fourier transfom methods into261         * ascending frequency/time order.262         */263         public static Complex[] sort(final Complex output[]) {264                 final Complex ret[]=new Complex[output.length];265                 final int Nby2=output.length/2;266                 for(int i=0;i