public static void DFT ( ComplexNumber [ ] data , Direction direction ) { int n = data . length ; ComplexNumber [ ] c = new ComplexNumber [ n ] ; // for each destination element for ( int i = 0 ; i < n ; i ++ ) { c [ i ] = new ComplexNumber ( 0 , 0 ) ; double sumRe = 0 ; double sumIm = 0 ; double phim = 2 * Math . PI * i / n ; // sum source elements for ( int j = 0 ; j < n ; j ++ ) { double gRe = data [ j ] . real ; double gIm = data [ j ] . imaginary ; double cosw = Math . cos ( phim * j ) ; double sinw = Math . sin ( phim * j ) ; if ( direction == Direction . Backward ) sinw = - sinw ; sumRe += ( gRe * cosw + data [ j ] . imaginary * sinw ) ; sumIm += ( gIm * cosw - data [ j ] . real * sinw ) ; } c [ i ] = new ComplexNumber ( sumRe , sumIm ) ; } if ( direction == Direction . Backward ) { for ( int i = 0 ; i < c . length ; i ++ ) { data [ i ] . real = c [ i ] . real / n ; data [ i ] . imaginary = c [ i ] . imaginary / n ; } } else { for ( int i = 0 ; i < c . length ; i ++ ) { data [ i ] . real = c [ i ] . real ; data [ i ] . imaginary = c [ i ] . imaginary ; } } }
1 - D Discrete Fourier Transform .