public static void Draw( Rect position, ComplexNumber[] data )
 {
     float[] realData = new float[ data.Length ];
     for (int i=0; i<realData.Length; i++)
     {
         realData[ i ] = data[ i ].Magnitude;
     }
     Draw( position, realData );
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Fasts the fourier transform.
 /// </summary>
 /// <returns>
 /// The fourier transform.
 /// </returns>
 /// <param name='realData'>
 /// Real data.
 /// </param>
 public static ComplexNumber[] FastFourierTransform( float[] realData )
 {
     ComplexNumber[] x = new ComplexNumber[ realData.Length ];
     for (int i=0; i<x.Length; i++)
     {
         x[i] = new ComplexNumber( realData[ i ] );
     }
     return FastFourierTransform( x );
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Fasts the fourier transform.
        /// </summary>
        /// <returns>
        /// The fourier transform.
        /// </returns>
        /// <param name='x'>
        /// X.
        /// </param>
        public static ComplexNumber[] FastFourierTransform( ComplexNumber[] x )
        {
            int N = x.Length; // The total number of samples
            if (N == 1)
            {
                // If we have only one sample, it is our result
                return x;
            }

            // Split data set in half:
            ComplexNumber[] E = new ComplexNumber[ N/2 ];
            ComplexNumber[] D = new ComplexNumber[ N/2 ];
            for (int i=0; i<N/2; i++)
            {
                E[ i ] = x[ 2 * i ];
                D[ i ] = x[ 2 * i + 1 ];
            }

            // Recurse.
            E = FastFourierTransform( E );
            D = FastFourierTransform( D );

            // Multiply D by complex number (for reasons)
            for (int k=0; k<N/2; k++)
            {
                ComplexNumber temp = ComplexNumber.FromPolar( 1, -2 * Mathf.PI * k / N );
                D[k] *= temp;
            }

            // Define the result array:
            ComplexNumber[] X = new ComplexNumber[ N ];

            // Add Complex Numbers
            for (int k=0; k<N/2; k++)
            {
                X[ k ] = E[ k ] + D[ k ];
                X[ k + N/2 ] = E[ k ] - D[ k ];
            }

            // Return result
            return X;
        }