IIRFilters Namespace

Headers: Dew.Signal/IIrFilters.h, Dew.Signal/Units.IIrFilters.h · Cross-compiler

namespace Dew::Signal::Units::IIRFilters

Functions

NameDescription
BesselAnalogDesign an analog Bessel (Thomson) lowpass prototype filter of order Order, optimised for maximally-flat group delay (linear phase) rather than a flat magnitude. Returns zero-pole-gain with all zeros at infinity (z empty); the denominator is the reverse Bessel polynomial theta_n(s): H(s)=theta_n(0)/theta_n(s), theta_n(s)=sum_(k=0)^n((2n-k)!)/(2^(n-k) k! (n-k)!) s^k, normalised so that the DC gain is 1. The phase response is approximately linear near DC; the magnitude rolls off more gently than Butterworth. Domain: 1 <= Order <= MaxIirOrder. Poles satisfy Re(p_k)<0 (stable). z and p must share precision or an exception is raised.
BesselFilter (3)Design Bessel IIR filter.
ButterAnalogDesign an analog Butterworth lowpass prototype filter of order Order, cutoff fixed at 1 rad/s. Returns zero-pole-gain in z (zeros), p (poles), k (gain): H(s)=k/(prod_(i=1)^n(s-p_i)), p_k=exp(j(pi/2+(pi(2k-1))/2n)), k=1... n. All n poles lie on the left half of the unit circle (so the prototype is stable, Re(p_k)<0) and all zeros are at infinity (z is returned empty), giving a maximally-flat magnitude that is 3 dB down at omega=1. Domain: Order is a positive integer, 1 <= Order <= MaxIirOrder (=50). z and p must share the same precision; a precision mismatch raises an exception. No NaN is produced for valid input.
ButterFilter (4)Design a complete Butterworth IIR filter of the given Order, cutoff(s) CutoffFreq and band type FilterType, returning the transfer function in zero-pole form (z, p, k): H(z)=k (prod_i (z-z_i))/(prod_i (z-p_i)). Set Analog=True for an s-plane design or Analog=False for a z-plane (digital) design; for a digital design CutoffFreq lies in $(0,1)$ with sampling frequency 2 (so 1 = Nyquist). FilterType is lp/hp (1 cutoff) or bp/bs (2 cutoffs); a bandpass/bandstop design has twice the prototype order. IirFrequencyTransform selects when the frequency-band transform is applied (state-space-analog, zero-pole-analog or zero-pole-discrete). Digital poles satisfy |p_i|<1 (stable). The function result is the natural 3 dB cutoff W_c. The other overloads return the same filter as num/den (ba), second-order sections (sos) or state space (A,B,C,D). NOTE: a digital cutoff outside $(0,1)$ is NOT range-checked and yields a degenerate filter.
ButterOrderEstimate 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)$ 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).
ChebyshevIAnalogDesign an analog Chebyshev type I lowpass prototype filter of order Order with PassRipple dB of equiripple in the passband, cutoff fixed at 1 rad/s. Returns zero-pole-gain (z empty, all zeros at infinity): |H(jomega)|^2=1/(1+varepsilon^2 T_n^2(omega)), varepsilon=sqrt(10^(R_p/10)-1), where T_n is the order-n Chebyshev polynomial and R_p=PassRipple. The magnitude is equiripple in $[0,1]$ and monotone beyond; at the passband edge omega=1 it equals 10^(-R_p/20). Domain: 1 <= Order <= MaxIirOrder, PassRipple>0 dB. Poles satisfy Re(p_k)<0 (stable). z and p must share precision or an exception is raised.
ChebyshevIFilter (4)Design Chebyshev type I IIR filter.
ChebyshevIIAnalogDesign an analog Chebyshev type II (inverse Chebyshev) lowpass prototype filter of order Order with StopRipple dB of equiripple attenuation in the stopband, cutoff fixed at 1 rad/s. Returns zero-pole-gain with finite imaginary-axis zeros: |H(jomega)|^2=1/(1+[varepsilon^2 T_n^2(1/omega)]^(-1)), varepsilon=1/(sqrt(10^(R_s/10)-1)), z_k=j/(cos((2k-1)pi)/2n). The magnitude is maximally flat in the passband and equiripple in the stopband; at the stopband edge omega=1 it equals 10^(-R_s/20) where R_s=StopRipple. Domain: 1 <= Order <= MaxIirOrder, StopRipple>0 dB. Poles satisfy Re(p_k)<0 (stable). z and p must share precision or an exception is raised.
ChebyshevIIFilter (4)Design Chebyshev type II IIR filter.
ChebyshevIIOrderEstimate the minimum Chebyshev type II (inverse Chebyshev) filter order that meets a transition-band specification, and fill CutoffFreq with the STOPBAND-edge cutoff(s). The order formula matches Chebyshev type I, n=\lceil(cosh^(-1)sqrt((10^(R_s/10)-1)/(10^(R_p/10)-1)))/(cosh^(-1)(omega_s/omega_p))\rceil, capped at MaxIirOrder (=50). Because the natural cutoff is the stopband edge, the returned CutoffFreq may sit just outside the passband bracket; for bandpass/bandstop the estimated order can differ from scipy cheb2ord by at most one section. Domain: digital edges in $(0,1)$ (Analog=False) or analog rad/s (Analog=True); CutoffFreq length is half BEdges length and matches FilterType.
ChebyshevIOrderEstimate the minimum Chebyshev type I filter order that meets a transition-band specification, and fill CutoffFreq with the passband-edge cutoff(s). The order is n=\lceil(cosh^(-1)sqrt((10^(R_s/10)-1)/(10^(R_p/10)-1)))/(cosh^(-1)(omega_s/omega_p))\rceil, capped at MaxIirOrder (=50), where R_p=PassRipple and R_s=StopRipple in dB. BEdges holds the band edges ascending; CutoffFreq length must be half BEdges length and match FilterType. Domain: digital edges in $(0,1)$ (sampling frequency 2, Analog=False) or analog rad/s (Analog=True). The returned cutoff is the passband edge.
EllipticAnalogDesign an analog elliptic (Cauer) lowpass prototype filter of order Order, equiripple in BOTH bands (PassRipple dB passband, StopRipple dB stopband), cutoff fixed at 1 rad/s. Returns zero-pole-gain with finite imaginary-axis zeros: |H(jomega)|^2=1/(1+varepsilon^2 R_n^2(omega,xi)), varepsilon=sqrt(10^(R_p/10)-1), where R_n is the Chebyshev rational (elliptic) function. For a given order the elliptic design gives the narrowest transition band of the five families. At the passband edge omega=1 the magnitude equals 10^(-R_p/20). Domain: 1 <= Order <= MaxIirOrder, PassRipple>0, StopRipple>PassRipple (dB). Poles satisfy Re(p_k)<0 (stable). z and p must share precision or an exception is raised.
EllipticFilter (4)Design Elliptic IIR filter.
EllipticOrderEstimate the minimum elliptic (Cauer) filter order that meets a transition-band specification, and fill CutoffFreq with the passband-edge cutoff(s). Using the complete elliptic integral K( * ) and the selectivity k=omega_p/omega_s, discrimination k_1=sqrt((10^(R_p/10)-1)/(10^(R_s/10)-1)), the order is n=\lceil(K(k) K(sqrt(1-k_1^2)))/(K(sqrt(1-k^2)) K(k_1))\rceil, capped at MaxIirOrder (=50). For a given spec the elliptic order is the smallest of the five families. Domain: digital edges in $(0,1)$ (Analog=False) or analog rad/s (Analog=True); CutoffFreq length is half BEdges length and matches FilterType.
ExactIirZerosPlace the exact fixed zeros of a Butterworth or Chebyshev type I filter into z, given the filter Order, the bilinear-warped band-centre frequency Wc, the FilterType and the Analog flag. The locations are: DIGITAL (Analog=False) lowpass = Order zeros at $z=-1$; highpass = Order zeros at $z=+1$; bandpass = Order zeros at $z=+1$ then Order at $z=-1$; bandstop = 2Order unit-circle zeros at z=e^(+/- jtheta), theta=2arctanW_c/4. ANALOG (Analog=True) lowpass = no zeros; highpass/bandpass = Order zeros at the origin; bandstop = 2Order zeros at +/- jW_c. Domain: Order a positive integer; Wc the warped centre frequency (only used for bandstop). z is sized and overwritten; it must allow a complex result for the bandstop and analog-bandstop cases. No NaN is produced.
IirFilterMethodToStringReturn a human-readable name for a TIirFilterMethod value: fimButter -> 'Butterworth', fimChebyshevI -> 'Chebyshev type I', fimChebyshevII -> 'Chebyshev type II', fimElliptic -> 'Elliptic filter', fimDC -> 'DC filter', fimNotch -> 'Notch filter', fimBessel -> 'Bessel filter'. Pure mapping with no numeric computation; the domain is the full TIirFilterMethod enumeration and every value yields a non-empty string (no exception, no NaN).

Constants

NameTypeDescription
MaxIirOrderconst int