Пример #1
0
        //

        /// <summary>
        /// Calculates the power of a polynomial by convoluting its coefficients with it self n-times
        /// </summary>
        /// <param name="a">The coefficients of the polynomial</param>
        /// <param name="n">The power to which to raise the polynomial</param>
        /// <returns>The resulting polynomial coefficients after raising the poly to power-of-n</returns>
        public static double[] ArrayPower(double[] a, int n)
        {
            double[] output = { 1f };
            for (int i = 0; i < n; i++)
            {
                output = Convolution.Conv(output, a);
            }

            return(output);
        }
Пример #2
0
        /**
         * Process an incoming signal with the defined impulse response
         * @param input Input signal to be processed
         * @return processed signal <b>without</b> the "tail". output.length = input.length
         */
        public double[] Process(double[] input)
        {
            double[] data    = Convolution.Conv(this.response, input);
            double[] output  = new double[input.Length];
            double[] newTail = new double[tail.Length];

            int i = 0;

            while (i < data.Length)
            {
                if (i < output.Length)
                {
                    // Ef data liggur á bilinu 0...output length, færa gögn í output
                    output[i] = data[i];

                    if (i < tail.Length)
                    {
                        output[i] += tail[i];
                    }
                }
                else
                {
                    // Ef data liggur út fyrir output þá færa restina í nýtt tail
                    newTail[i - output.Length] = data[i];

                    if (i < tail.Length)                     // Ef það er eitthvað eftir af gamla teilinu bæta því við
                    {
                        newTail[i - output.Length] += tail[i];
                    }
                }

                i++;
            }
            this.tail = newTail;

            return(output);
        }