Example: Complex FFT

The Fourier coefficients of a complex periodic sequence are computed. Then the coefficients are used to try to reproduce the periodic sequence.
import com.imsl.math.*;

public class ComplexFFTEx1 {
    public static void main(String args[]) {
        Complex	x[] = {
            new Complex(1,8),
            new Complex(2,7),
            new Complex(3,6),
            new Complex(4,5),
            new Complex(5,4),
            new Complex(6,3),
            new Complex(7,2),
            new Complex(8,1)
        };
        ComplexFFT	fft = new ComplexFFT(x.length);
        
        Complex	y[] = fft.forward(x);
        Complex	z[] = fft.backward(y);
        for (int i = 0; i < x.length; i++) {
            z[i] = Complex.divide(z[i], x.length);
        }
        
        new PrintMatrix("x").print(x);
        new PrintMatrix("y").print(y);
        new PrintMatrix("z").print(z);
    }
}

Output

    x
    0    
0  1+8i  
1  2+7i  
2  3+6i  
3  4+5i  
4  5+4i  
5  6+3i  
6  7+2i  
7  8+1i  

         y
          0         
0       36+36i      
1    5.657+13.657i  
2         +8i       
3   -2.343+5.657i   
4       -4+4i       
5   -5.657+2.343i   
6       -8          
7  -13.657-5.657i   

    z
    0    
0  1+8i  
1  2+7i  
2  3+6i  
3  4+5i  
4  5+4i  
5  6+3i  
6  7+2i  
7  8+1i  

Link to Java source.