Esempio n. 1
0
        static void Example2D()
        {
            using (var input = new AlignedArrayComplex(16, 64, 16))
                using (var output = new AlignedArrayComplex(16, input.GetSize()))
                {
                    for (int row = 0; row < input.GetLength(0); row++)
                    {
                        for (int col = 0; col < input.GetLength(1); col++)
                        {
                            input[row, col] = (double)row * col / input.Length;
                        }
                    }

                    DFT.FFT(input, output);
                    DFT.IFFT(output, output);

                    for (int row = 0; row < input.GetLength(0); row++)
                    {
                        for (int col = 0; col < input.GetLength(1); col++)
                        {
                            Console.Write((output[row, col].Real / input[row, col].Real / input.Length).ToString("F2").PadLeft(6));
                        }
                        Console.WriteLine();
                    }
                }
        }
Esempio n. 2
0
            ///<summary>
            ///This routine casts the output of FFTW engine to a Complex matrix, so the spectrum can be saved
            ///and manipulated
            /// </summary>
            /// <param name="FFTOutput">The FFT spectrum output in FFTW format</param>
            /// <returns>Spectrum as matrix of double</returns>
            private static Complex[,] CastFFTWToComplexSpectrum(AlignedArrayComplex FFTOutput)
            {
                int    m     = FFTOutput.GetLength(0);
                int    n     = FFTOutput.GetLength(1);
                double N_spe = (double)m * n;

                Complex[,] spectrum = new Complex[m, n]; //Initialize spectrum
                for (int i = 0; i < m; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        spectrum[i, j] = new Complex(FFTOutput[i, j].Real / N_spe, FFTOutput[i, j].Imaginary / N_spe);
                    }
                }

                return(spectrum);
            }
Esempio n. 3
0
 public static cuDoubleComplex[] PerformFft(cuDoubleComplex[] data, int size, TransformDirection direction)
 {
     if (cudaAvailable)
     {
         return(cuHelper.PerformFFT(data, size, direction));
     }
     else
     {
         cuDoubleComplex[] result = new cuDoubleComplex[size * size];
         using (var input = new AlignedArrayComplex(16, size, size))
             using (var output = new AlignedArrayComplex(16, input.GetSize()))
             {
                 for (int i = 0; i < input.GetLength(0); i++)
                 {
                     for (int j = 0; j < input.GetLength(1); j++)
                     {
                         input[i, j] = new Complex(data[i * size + j].real, data[i * size + j].imag);
                     }
                 }
                 if (direction == TransformDirection.Forward)
                 {
                     DFT.FFT(input, output);
                 }
                 else
                 {
                     DFT.IFFT(input, output);
                 }
                 for (int i = 0; i < input.GetLength(0); i++)
                 {
                     for (int j = 0; j < input.GetLength(1); j++)
                     {
                         result[i * size + j].real = output[i, j].Real;
                         result[i * size + j].imag = output[i, j].Imaginary;
                     }
                 }
             }
         return(result);
     }
 }
Esempio n. 4
0
        public static void Shift(AlignedArrayComplex grid)
        {
            var n2 = grid.GetLength(0) / 2;

            for (int i = 0; i < n2; i++)
            {
                for (int j = 0; j < n2; j++)
                {
                    var tmp13 = grid[i, j];
                    grid[i, j]           = grid[i + n2, j + n2];
                    grid[i + n2, j + n2] = tmp13;

                    var tmp24 = grid[i + n2, j];
                    grid[i + n2, j] = grid[i, j + n2];
                    grid[i, j + n2] = tmp24;
                }
            }
        }