pub struct ZPKModel { /* private fields */ }Expand description
Analog zero-pole-gain model for real input to real output. Provides methods to generate analog filters of standard type, i.e. bandpass, lowpass and highpass. These can subsequentially be used to generate a digital filter.
§Example: Create a digital second order Butterworth bandpass filter
use lasprs::filter::{FilterSpec, ZPKModel};
let fs = 48000.;
let butter = ZPKModel::butter(FilterSpec::Bandpass{fl: 10., fu: 100., order: 2});
let mut filt = butter.bilinear(fs);
It has a transfer function that can be described as a rational function of the form:
Π_i (s-z_i)
H(s) = k ------------
Π_i (s-p_i)where Π denotes the product of a series, z_i are the zeros, and p_i
are the poles. In order to have real output for a real input, the zeros and
poles should either be real, or come in complex conjugate pairs. This is
enforced by the way the poles and zero’s are internally stored.
Implementations§
Source§impl ZPKModel
impl ZPKModel
Sourcepub fn new<T, U>(zeros: T, poles: U, k: Flt) -> ZPKModel
pub fn new<T, U>(zeros: T, poles: U, k: Flt) -> ZPKModel
Creata a new ZPK model, with give list of poles and zeros, and gain
§Args
zeros- list like struct of zeros. Can be aVec<ZeroOrPole>or an&[ZeroOrPole].poles- list like struct of poles. Can be aVec<ZeroOrPole>or an&[ZeroOrPole].k- linear gain.
Sourcepub fn setWarpFreq(self, fcrit: Flt) -> ZPKModel
pub fn setWarpFreq(self, fcrit: Flt) -> ZPKModel
Set critical frequency in filter, used for bilinear transform.
§Args
fcrit- New critical frequency in [Hz].
Sourcepub fn setGainAt(self, freq: Flt, required_gain: Flt) -> ZPKModel
pub fn setGainAt(self, freq: Flt, required_gain: Flt) -> ZPKModel
Change the gain value such that it matches val at frequency freq.
Does not change the phase at the given frequency.
Sourcepub fn butter(spec: FilterSpec) -> ZPKModel
pub fn butter(spec: FilterSpec) -> ZPKModel
Create a Butterworth filter according to a certain specification in
spec.
§Panics
- If specified
order == 0 - If order is larger than [BUTTER_MAX_ORDER].
- If for a bandpass filter
fl>=fu. - If
fl, orfu < 0.
Sourcepub fn bilinear(&self, fs: Flt) -> SeriesBiquad
pub fn bilinear(&self, fs: Flt) -> SeriesBiquad
Apply bilinear transform to obtain series biquads from this ZPK model. Pre-warping is taken into account, based on settings stored in ZPKModel. Using ZPKModel::setWarpFreq, this can be overridden.
§Args
fs- Sampling frequency [Hz]
Sourcepub fn freqWeightingFilter(wt: FreqWeighting) -> ZPKModel
pub fn freqWeightingFilter(wt: FreqWeighting) -> ZPKModel
Create analog filter prototype for a frequency weighting as used in Sound Level Meters.
§Args
wt-[FreqWeighting]to use. i.e. A-weighting.
§Examples
§Get part of pulse response of digital A-filter at 48 kHz
use lasprs::filter::{ZPKModel, FreqWeighting, Filter};
// Sampling frequency in Hz
let fs = 48000.;
let mut afilter = ZPKModel::freqWeightingFilter(FreqWeighting::A).bilinear(fs);
let mut data = [0.; 1000];
data[0] = 1.0;
let out = afilter.filter(&data);Trait Implementations§
Source§impl<'py> IntoPyObject<'py> for ZPKModel
impl<'py> IntoPyObject<'py> for ZPKModel
Source§type Output = Bound<'py, <ZPKModel as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <ZPKModel as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClassImpl for ZPKModel
impl PyClassImpl for ZPKModel
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§type ThreadChecker = SendablePyClass<ZPKModel>
type ThreadChecker = SendablePyClass<ZPKModel>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyMethods<ZPKModel> for PyClassImplCollector<ZPKModel>
impl PyMethods<ZPKModel> for PyClassImplCollector<ZPKModel>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for ZPKModel
impl PyTypeInfo for ZPKModel
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
Source§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
impl DerefToPyAny for ZPKModel
Auto Trait Implementations§
impl Freeze for ZPKModel
impl RefUnwindSafe for ZPKModel
impl Send for ZPKModel
impl Sync for ZPKModel
impl Unpin for ZPKModel
impl UnwindSafe for ZPKModel
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FromPyObject<'_> for T
impl<T> FromPyObject<'_> for T
Source§impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
impl<'py, T> FromPyObjectBound<'_, 'py> for Twhere
T: FromPyObject<'py>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
Source§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.