Ejemplo n.º 1
0
        /// <summary>
        /// Result = A (*) B
        /// By using DFT for calculations
        /// </summary>
        /// <param name="A"></param>
        /// <param name="B"></param>
        /// <param name="Result"></param>
        public static void Convolution_DFT_F( FxVectorF A, FxVectorF B, out FxVectorF Result )
        {
            FxVectorF A_dftReal,A_dftImag,B_dftReal,B_dftImag;

            TimeStatistics.ClockLap( "Enter" );

            // get the max size from A,B
            int maxSize = ( A.Size > B.Size ) ? A.Size : B.Size;

            // check for padding
            if ( A.Size == maxSize && B.Size != maxSize ) {
                // increase the size of B
                B.Padding( maxSize - B.Size, true, 0 );
            } else if ( B.Size == maxSize && A.Size != maxSize ) {
                A.Padding( maxSize - A.Size, true, 0 );
            }

            TimeStatistics.ClockLap( "AfterPadding" );

            // calc the DFT of the signal
            SignalTools.DFT_F( A, true, out A_dftReal, out A_dftImag );

            TimeStatistics.ClockLap( "After DFT A" );

            // calc the DFT of the signal
            SignalTools.DFT_F( B, true, out B_dftReal, out B_dftImag );

            TimeStatistics.ClockLap( "After DFT B" );

            // allocate result vector
            Result = new FxVectorF( maxSize );

            float real,imag;

            // do the multiplication
            for ( int i=0; i < maxSize; i++ ) {
                // complex multiplication
                real = A_dftReal[i] * B_dftReal[i] - A_dftImag[i] * B_dftImag[i];
                imag = A_dftReal[i] * B_dftImag[i] + A_dftImag[i] * B_dftReal[i];

                // set the new values
                A_dftReal[i] = real;
                A_dftImag[i] = imag;
            }

            TimeStatistics.ClockLap( "After multiplication" );

            // calc the DFT of the signal
            SignalTools.DFT_F( A_dftReal, A_dftImag, false, out Result, out B_dftImag );

            TimeStatistics.ClockLap( "After iDFT" );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a new filter base on existing data 
        /// </summary>
        /// <param name="filter"></param>
        public FIR_GenericFilter( FxVectorF filter )
        {
            p_Impulse = filter.GetCopy() as FxVectorF;

            // normalize the filter
            p_Impulse.Divide( (float)p_Impulse.Norms( NormVectorType.Manhattan ) );

            // check that is power of 2 ( we do that for speed )
            if ( Math.Pow( 2, Math.Log( p_Impulse.Size, 2 ) ) != p_Impulse.Size ) {
                // calc the size of log2 extence
                int sizeLog2 = (int)Math.Floor( Math.Log( p_Impulse.Size, 2 ) ) + 1;

                // calc the new maxSize
                int newSize = (int)Math.Pow( 2, sizeLog2 );

                // increase the size of Impulse
                p_Impulse.Padding( newSize - p_Impulse.Size, true, 0 );
            }

            // calc the fft of impulse
            TransformImpulseToFFT();
        }