IIRFilters.ButterOrder Method

Int32 ButterOrder(Double[] BEdges, Double PassRipple, Double StopRipple, TFilterType FilterType, ref Double[] CutoffFreq, Boolean Analog)

Estimate the minimum Butterworth filter order that meets a transition-band specification, and fill CutoffFreq with the natural (3 dB) cutoff(s). BEdges holds the band edges in ascending order (passband edge then stopband edge per band); PassRipple (R_p dB) and StopRipple (R_s dB) bound the passband ripple and stopband attenuation. The returned order is n=\lceil(log_(10)(10^(R_s/10)-1)/(10^(R_p/10)-1))/(2 log_(10)(omega_s/omega_p))\rceil, capped at MaxIirOrder (=50). CutoffFreq length must be half BEdges length and match FilterType (1 value for lp/hp, 2 for bp/bs). Domain: digital edges lie in (0,1)(0,1) with sampling frequency 2 (Analog=False); analog edges are in rad/s (Analog=True). NOTE: the natural cutoff placement differs slightly from scipy buttord (same integer order, the 3 dB frequency may differ by under 1 percent).

#NameTypeDescription
1BEdgesDouble[]
2PassRippleDoublescalar
3StopRippleDoublescalar
4FilterTypeTFilterType
5CutoffFreqDouble[] (ref)
6AnalogBoolean

Returns: Int32

Remarks:

Returns the order of a butterworth type IIR filter. Bedg array must contain the band edges of the transition region(s) sorted in ascending order. PassRipple defines the ripple of the passband and StopRipple defines the ripple of the stopband. The length of the CutoffFreq array must be equal to one half of the length of the BEdg array and must match the specified FilterType. The routine returns the estimated order as a result and fill's the CutoffFreq array. This array can then be passed to the ButterFilter routine.

Examples
using Dew.Math;
using Dew.Math.Editors;
using Dew.Math.Units;
using Dew.Signal;
using Dew.Signal.Units;
using Dew.Math.Tee;
using Dew.Signal.Tee;

private void button1_Click(object sender, EventArgs e)
{
    Vector z = new Vector(0);
    Vector p = new Vector(0);
    Vector num = new Vector(0);
    Vector den = new Vector(0);
    Vector Response = new Vector(0);
    Vector FreqFr = new Vector(0);
    double k;
    double[] Wc = new double[1];
    int Order; //design a fifth order filter.

    Order = IIRFilters.ButterOrder(new double[2] { 2, 6 }, 0.2,40,TFilterType.ftLowpass,ref Wc,true);  //design analog protype
    IIRFilters.ButterAnalog(Order,z, p, out k);  //design analog protype
    LinearSystems.LowpassToLowpass(z, p, ref k, Wc[0]);
    LinearSystems.ZeroPoleToTransferFun(num, den, z, p, k);
    FreqFr.Length = 1000;
    SignalUtils.LogRamp(FreqFr, -1, 1);

    SignalUtils.FrequencyResponseS(num, den, FreqFr, Response, 0);
    MtxVecTee.DrawIt(Response, "Frequency response", false);
}
See Also: IIRFilters.ButterFilter