signal::filter::iir
IIR design the classical way (as SciPy's iirfilter): an analog
low-pass prototype's zeros, poles and gain; a frequency transform to
the band; the bilinear transform with pre-warped edges; then pairing
into second-order sections, poles nearest the unit circle last (the
pairing of SciPy's zpk2sos), which keeps high orders well
conditioned where a single b / a would not be.
Structs
ZpkSource
pub struct ZpkA filter as its zeros, poles and gain:
H(z) = gain * prod(z - zeros) / prod(z - poles).
The filter as second-order sections, one row
[b0, b1, b2, 1, a1, a2]per section, poles nearest the unit circle in the last row and the gain in the first (SciPy'szpk2soswith nearest pairing).nabiuse signal::filter::{Band, Iir, iirfilter}; let sos = (try iirfilter(3, Band::Lowpass(0.5), Iir::Butter)).to_sos(); println(sos.shape()); // [2, 6]The filter as one transfer function
(b, a), coefficients of z^0, z^-1, ... Exact for low orders; for high orders keep the sections, whose rounding error stays small.nabiuse signal::filter::{Band, Iir, iirfilter}; let (b, a) = (try iirfilter(1, Band::Lowpass(0.5), Iir::Butter)).to_ba(); println(b); // [0.5, 0.5] println(a); // [1.0, 0.0] (to rounding)
Enums
IirSource
pub enum IirThe analog prototype to design from.
use signal::filter::{Band, Iir, iirfilter};
let z = try iirfilter(3, Band::Lowpass(0.2), Iir::Cheby1(0.5));
println(z.poles.len()); // 3
Butterworth: maximally flat pass band.
Chebyshev type I: equiripple pass band, ripple
rpdB.Chebyshev type II: equiripple stop band,
rsdB down.Bessel (phase-normalized): maximally flat group delay.
Functions
iirfilterSource
pub fn iirfilter(n: usize, band: Band, kind: Iir, fs: f64 = 2.0) throws (SignalError) -> Zpk The digital IIR filter of order n (2n for band-pass and
band-stop) of kind for band, edges in units of fs, as zeros,
poles and gain. Turn it into sections with to_sos.
use signal::filter::{Band, Iir, iirfilter};
let z = try iirfilter(2, Band::Bandpass(0.2, 0.4), Iir::Butter);
println(z.poles.len()); // 4
butterSource
pub fn butter(n: usize, band: Band, fs: f64 = 2.0) throws (SignalError) -> Matrix<f64> A Butterworth filter as second-order sections.
use signal::filter::{Band, butter};
let sos = try butter(2, Band::Lowpass(0.5));
println(sos); // [[0.2928.., 0.5857.., 0.2928.., 1.0, 0.0, 0.1715..]]
cheby1Source
pub fn cheby1(n: usize, rp: f64, band: Band, fs: f64 = 2.0) throws (SignalError) -> Matrix<f64> A Chebyshev type I filter with rp dB of pass-band ripple, as
second-order sections.
use signal::filter::{Band, cheby1};
let sos = try cheby1(4, 1.0, Band::Highpass(300.0), fs: 8000.0);
println(sos.shape()); // [2, 6]
cheby2Source
pub fn cheby2(n: usize, rs: f64, band: Band, fs: f64 = 2.0) throws (SignalError) -> Matrix<f64> A Chebyshev type II filter rs dB down in the stop band, as
second-order sections. The edges are where the stop band starts.
use signal::filter::{Band, cheby2};
let sos = try cheby2(4, 40.0, Band::Lowpass(0.3));
println(sos.shape()); // [2, 6]
besselSource
pub fn bessel(n: usize, band: Band, fs: f64 = 2.0) throws (SignalError) -> Matrix<f64> A Bessel filter (phase-normalized, as SciPy's default), as second-order sections: nearly constant group delay in the pass band. Orders 1 to 16; the poles are good to about 1e-11 up to order 12 and 1e-9 at 16.
use signal::filter::{Band, bessel};
let sos = try bessel(4, Band::Lowpass(0.2));
println(sos.shape()); // [2, 6]
sos_to_baSource
pub fn sos_to_ba(sos: Matrix<f64>) -> (Vector<f64>, Vector<f64>) One (b, a) from second-order sections (the product of the rows).
use signal::filter::{Band, butter, sos_to_ba};
let (b, a) = sos_to_ba(try butter(1, Band::Lowpass(0.5)));
println(b); // [0.5, 0.5, 0.0]