Ejemplo n.º 1
0
        //#endfor instanced to 'Double'

        //#foreach instanced to 'Float'


        #region float

        #region Private Methods

        /// <summary>
        /// Fast furier transform, in place.
        /// </summary>
        /// <param name="inputs">The inputs.</param>
        /// <param name="forward">Is it forward or inverse transform.</param>
        static void InternalFFT(Complexf[] data, bool forward)
        {
            // We first permutate the inputs in bit-reversed order.
            ReverseBitsSort(data);

            // Is it a forward or backward transform.
            float exp = forward ? 1.0f : -1.0f;

            int n   = data.Length;
            int lnd = MathHelper.Log2(data.Length) + 1;

            for (int lmd = 1; lmd <= lnd; lmd++)
            {
                int m  = 1 << lmd;
                int mh = m / 2;
                for (int j = 0; j < mh; j++)
                {
                    Complexf e = MathHelper.ExpI(exp * (float)(2.0 * MathHelper.PI) * (float)j / (float)m);
                    for (int r = 0; r <= n - m; r += m)
                    {
                        Complexf u = data[r + j];
                        Complexf v = data[r + j + mh] * e;
                        data[r + j]      = u + v;
                        data[r + j + mh] = u - v;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transforms the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static Complexf[] Transform([PowerOfTwoArray] Complexf[] input, FurierTransformType type)
        {
            Complexf[] result = new Complexf[input.Length];
            input.CopyTo(result, 0);

            TransformInPlace(result, type);
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Transforms the specified input.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <param name="type">The type.</param>
        /// <returns></returns>
        public static Complexf[] Transform([PowerOfTwoArray] float[] input, FurierTransformType type)
        {
            Complexf[] result = new Complexf[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                result[i] = new Complexf(input[i], 0.0f);
            }


            TransformInPlace(result, type);
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Quadratic equation root; e.g. 0 = a*x^2 + b*x + c. The solution is either both with
        /// real numbers (imagionary = 0) or both with complex numbers.
        /// </summary>
        /// <param name="x0">The first complex result.</param>
        /// <param name="x1">The second complex result.</param>
        public static void Roots(float a, float b, float c, out Complexf x0, out Complexf x1)
        {
            double D = b * b - 4.0 * a * c;

            if (D < 0.0f)
            {
                float sD = (float)global::System.Math.Sqrt(-D);
                x0 = new Complexf((-b) / (2.0f * a), sD / (2.0f * a));
                x1 = new Complexf((-b) / (2.0f * a), -sD / (2.0f * a));
            }
            else
            {
                float sD = (float)global::System.Math.Sqrt(D);
                x0 = new Complexf((-b + sD) / (2.0f * a), 0.0f);
                x1 = new Complexf((-b - sD) / (2.0f * a), 0.0f);
            }
        }