示例#1
0
        private static void Supertransform(double[] b, double[] a, double[] zb, double[] za, double fs)
        {
            int numOfCoeffs = b.Length;
            int order       = numOfCoeffs - 1;

            double[] zplus1  = { 1.0f, 1.0f };
            double[] zminus1 = { 1.0f, -1.0f };

            double[][] polys = new double[numOfCoeffs][];

            for (int i = 0; i < numOfCoeffs; i++)
            {
                polys[i] = Convolution.Conv(ArrayPower(zplus1, order - i), ArrayPower(zminus1, i));
            }

            for (int i = 0; i < numOfCoeffs; i++)
            {
                zb[i] = 0;
                za[i] = 0;
                for (int j = 0; j < numOfCoeffs; j++)
                {
                    zb[i] += (double)(polys[j][i] * b[j] * Math.Pow(2 * fs, j));
                    za[i] += (double)(polys[j][i] * a[j] * Math.Pow(2 * fs, j));
                }
            }
        }
示例#2
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);
        }
示例#3
0
文件: Conv.cs 项目: wesgrant/AudioLib
        /**
         * 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);
        }