Exemplo n.º 1
0
        /// <summary>
        /// Computes the IIR coefficients for a high-pass Butterworth filter.
        /// </summary>
        /// <param name="stopbandFreq">Stopband corner frequency (in Hz).</param>
        /// <param name="passbandFreq">Passband corner frequency (in Hz).</param>
        /// <param name="passbandRipple">Maximum allowed passband ripple.</param>
        /// <param name="stopbandAttenuation">Minimum required stopband attenuation.</param>
        /// <returns>IIR coefficients.</returns>
        /// <seealso cref="Designer.HighPass(double, double, double, double)"/>
        public static (IEnumerable <double> numerator, IEnumerable <double> denominator) HighPass(double stopbandFreq, double passbandFreq, double passbandRipple, double stopbandAttenuation)
        {
            var(n, wc) = Designer.HighPass(stopbandFreq, passbandFreq, passbandRipple, stopbandAttenuation);

            const double T = 2;

            var(gain, zeros, poles) = TransferFunction(n);

            wc = Helpers.MathFunctions.WarpFrequency(wc, T);
            (gain, zeros, poles) = TransferFunctionTransformer.HighPass(gain, zeros, poles, wc);

            return(Coefficients(gain, zeros, poles, T));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Computes the IIR coefficients for a notch Butterworth filter.
        /// </summary>
        /// <param name="centralFreq">Filter central frequency.</param>
        /// <param name="Q">Quality factor.</param>
        /// <param name="passbandRipple">Maximum allowed passband ripple.</param>
        /// <param name="stopbandAttenuation">Minimum required stopband attenuation.</param>
        /// <returns>IIR coefficients.</returns>
        /// <seealso cref="Designer.Notch(double, double, double, double)"/>
        public static (IEnumerable <double> numerator, IEnumerable <double> denominator) Notch(double centralFreq, double Q, double passbandRipple, double stopbandAttenuation)
        {
            var(n, wc1, wc2) = Designer.Notch(centralFreq, Q, passbandRipple, stopbandAttenuation);

            const double T = 2;

            var(gain, zeros, poles) = TransferFunction(n);

            wc1 = Helpers.MathFunctions.WarpFrequency(wc1, T);
            wc1 = Helpers.MathFunctions.WarpFrequency(wc2, T);
            (gain, zeros, poles) = TransferFunctionTransformer.BandStop(gain, zeros, poles, wc1, wc2);

            return(Coefficients(gain, zeros, poles, T));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Computes the IIR coefficients for a band-pass Butterworth filter.
        /// </summary>
        /// <param name="lowStopbandFreq">Lower stopband corner frequency (in Hz).</param>
        /// <param name="lowPassbandFreq">Lower passband corner frequency (in Hz).</param>
        /// <param name="highPassbandFreq">Higher passband corner frequency (in Hz).</param>
        /// <param name="highStopbandFreq">Higher stopband corner frequency (in Hz).</param>
        /// <param name="passbandRipple">Maximum allowed passband ripple.</param>
        /// <param name="stopbandAttenuation">Minimum required stopband attenuation.</param>
        /// <returns>IIR coefficients.</returns>
        /// <seealso cref="Designer.BandPass(double, double, double, double, double, double)"/>
        public static (double[] numerator, double[] denominator) BandPass(double lowStopbandFreq, double lowPassbandFreq, double highPassbandFreq, double highStopbandFreq, double passbandRipple, double stopbandAttenuation)
        {
            var(n, wc1, wc2) = Designer.BandPass(lowStopbandFreq, lowPassbandFreq, highPassbandFreq, highStopbandFreq, passbandRipple, stopbandAttenuation);

            const double T = 2;

            var(gain, zeros, poles) = TransferFunction(n);

            wc1 = Helpers.MathFunctions.WarpFrequency(wc1, T);
            wc2 = Helpers.MathFunctions.WarpFrequency(wc2, T);
            (gain, zeros, poles) = TransferFunctionTransformer.BandPass(gain, zeros, poles, wc1, wc2);

            return(Coefficients(gain, zeros, poles, T));
        }