/// <summary> /// Constructor for Inverse FFT /// </summary> /// <param name="Input"></param> public FFT(ComplexNumber[,] Input) { nx = Width = Input.GetLength(0); ny = Height = Input.GetLength(1); Fourier = Input; }
/** * Perform a 2D FFT inplace given a complex 2D array * The direction dir, 1 for forward, -1 for reverse * The size of the array (nx,ny) * Return false if there are memory problems or * the dimensions are not powers of 2 */ public ComplexNumber[,] fft2d(ComplexNumber[,] c, int nx, int ny, int dir) { int i,j; int m;//Power of 2 for current number of points double []real; double []imag; ComplexNumber [,] output;//=new COMPLEX [nx,ny]; output = c; // Copying Array // Transform the Rows real = new double[nx] ; imag = new double[nx]; for (j=0;j<ny;j++) { for (i=0;i<nx;i++) { real[i] = c[i,j].real; imag[i] = c[i,j].imag; } // Calling 1D FFT Function for Rows m = (int)System.Math.Log((double)nx, 2);//Finding power of 2 for current number of points e.g. for nx=512 m=9 FFT1D(dir,m,ref real,ref imag); for (i=0;i<nx;i++) { output[i, j].real = real[i]; output[i, j].imag = imag[i]; } } // Transform the columns real = new double[ny]; imag = new double[ny]; for (i=0;i<nx;i++) { for (j=0;j<ny;j++) { real[j] = output[i, j].real; imag[j] = output[i, j].imag; } // Calling 1D FFT Function for Columns m = (int)System.Math.Log((double)ny, 2);//Finding power of 2 for current number of points e.g. for nx=512 m=9 FFT1D(dir,m,ref real,ref imag); for (j=0;j<ny;j++) { output[i, j].real = real[j]; output[i, j].imag = imag[j]; } } return(output); }