Example: Fast Fourier Transform

The Fourier coefficients of a periodic sequence are computed. The coefficients are then used to reproduce the periodic sequence.
using System;
using Imsl.Math;

public class FFTEx1
{
	public static void  Main(String[] args)
	{
		double[] x = new double[]{1, 2, 3, 4, 5, 6, 7, 8};
		FFT fft = new FFT(x.Length);
		
		double[] y = fft.Forward(x);
		double[] z = fft.Backward(y);
		for (int i = 0; i < x.Length; i++)
		{
			z[i] = z[i] / x.Length;
		}
		
		new PrintMatrix("x").Print(x);
		new PrintMatrix("y").Print(y);
		new PrintMatrix("z").Print(z);
	}
}

Output

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

          y
           0          
0  36                 
1  -4                 
2   9.65685424949238  
3  -4                 
4   4                 
5  -4                 
6   1.65685424949238  
7  -4                 

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


Link to C# source.