src/com/michaelho/DivideAndConquer/DC4.java
/**
         * The function that calculates Fast Fourier Transform.
         *
         * @param a The complex numbers.
         * */
The function that calculates Fast Fourier Transform.
@param a The complex numbers.
The function that calculates Fast Fourier Transform . @param a The complex numbers .
Complex[] FFT(Complex[] a, Complex[] omega, int length, int pow) {
            if (length == 1)
                return a;
            Complex[] aEven = new Complex[length];
            Complex[] aOdd = new Complex[length];
            for(int k = 0; k < length; k++){
                if(k%2 == 0)
                    aEven[k/2] = a[k];
                else
                    aOdd[k/2] = a[k];
            }
            Complex[] solutionEven = FFT(aEven, omega, length/2, pow*2);
            Complex[] solutionOdd = FFT(aOdd, omega, length/2, pow*2);
            Complex[] polySol = new Complex[length];
            for (int i = 0; i < length; i++)
                polySol[i] = new Complex(0,0);
            for (int i = 0; i < length/2; i++) {
                polySol[i] = solutionEven[i].add(omega[i*pow].multiply(solutionOdd[i]));
                polySol[i+length/2] = solutionEven[i].subtract(omega[i*pow].multiply(solutionOdd[i]));
            }
            return polySol;
        }
Complex [ ] FFT ( Complex [ ] a , Complex [ ] omega , int length , int pow ) { if ( length == 1 ) return a ; Complex [ ] aEven = new Complex [ length ] ; Complex [ ] aOdd = new Complex [ length ] ; for ( int k = 0 ; k < length ; k ++ ) { if ( k % 2 == 0 ) aEven [ k / 2 ] = a [ k ] ; else aOdd [ k / 2 ] = a [ k ] ; } Complex [ ] solutionEven = FFT ( aEven , omega , length / 2 , pow * 2 ) ; Complex [ ] solutionOdd = FFT ( aOdd , omega , length / 2 , pow * 2 ) ; Complex [ ] polySol = new Complex [ length ] ; for ( int i = 0 ; i < length ; i ++ ) polySol [ i ] = new Complex ( 0 , 0 ) ; for ( int i = 0 ; i < length / 2 ; i ++ ) { polySol [ i ] = solutionEven [ i ] . add ( omega [ i * pow ] . multiply ( solutionOdd [ i ] ) ) ; polySol [ i + length / 2 ] = solutionEven [ i ] . subtract ( omega [ i * pow ] . multiply ( solutionOdd [ i ] ) ) ; } return polySol ; }
The function that calculates Fast Fourier Transform.
The function that calculates Fast Fourier Transform .
// send them into two different array of objects // combine the pieces