ZPKModel

Struct ZPKModel 

Source
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

Source

pub fn new<T, U>(zeros: T, poles: U, k: Flt) -> ZPKModel
where T: Into<Vec<PoleOrZero>>, U: Into<Vec<PoleOrZero>>,

Creata a new ZPK model, with give list of poles and zeros, and gain

§Args
  • zeros - list like struct of zeros. Can be a Vec<ZeroOrPole> or an &[ZeroOrPole].
  • poles - list like struct of poles. Can be a Vec<ZeroOrPole> or an &[ZeroOrPole].
  • k - linear gain.
Source

pub fn setWarpFreq(self, fcrit: Flt) -> ZPKModel

Set critical frequency in filter, used for bilinear transform.

§Args
  • fcrit - New critical frequency in [Hz].
Source

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.

Source

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, or fu < 0.
Source

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]
Source

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 Clone for ZPKModel

Source§

fn clone(&self) -> ZPKModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ZPKModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ZPKModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'py> IntoPyObject<'py> for ZPKModel

Source§

type Target = ZPKModel

The Python output type
Source§

type Output = Bound<'py, <ZPKModel as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = PyErr

The type returned in the event of a conversion error.
Source§

fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>

Performs the conversion.
Source§

impl Mul for ZPKModel

Source§

type Output = ZPKModel

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: ZPKModel) -> Self

Performs the * operation. Read more
Source§

impl PyClass for ZPKModel

Source§

type Frozen = False

Whether the pyclass is frozen. Read more
Source§

impl PyClassImpl for ZPKModel

Source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
Source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
Source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
Source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
Source§

const IS_IMMUTABLE_TYPE: bool = false

#[pyclass(immutable_type)]
Source§

type BaseType = PyAny

Base class
Source§

type ThreadChecker = SendablePyClass<ZPKModel>

This handles following two situations: Read more
Source§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
Source§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
Source§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
Source§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
Source§

fn items_iter() -> PyClassItemsIter

Source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
Source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

Source§

fn dict_offset() -> Option<isize>

Source§

fn weaklist_offset() -> Option<isize>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a ZPKModel

Source§

type Holder = Option<PyRef<'py, ZPKModel>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl<'a, 'py> PyFunctionArgument<'a, 'py, false> for &'a mut ZPKModel

Source§

type Holder = Option<PyRefMut<'py, ZPKModel>>

Source§

fn extract( obj: &'a Bound<'py, PyAny>, holder: &'a mut Self::Holder, ) -> PyResult<Self>

Source§

impl PyMethods<ZPKModel> for PyClassImplCollector<ZPKModel>

Source§

fn py_methods(self) -> &'static PyClassItems

Source§

impl PyTypeInfo for ZPKModel

Source§

const NAME: &'static str = "ZPKModel"

Class name.
Source§

const MODULE: Option<&'static str> = ::core::option::Option::None

Module name, if any.
Source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
Source§

fn type_object(py: Python<'_>) -> Bound<'_, PyType>

Returns the safe abstraction over the type object.
Source§

fn is_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type or a subclass of this type.
Source§

fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of this type.
Source§

impl<'a, T: AsArray<'a, Flt>> TransferFunction<'a, T> for ZPKModel

Source§

fn tf(&self, _fs: Flt, freq: T) -> Array1<Complex<Flt>>

Compute frequency response (i.e. transfer function from input to output) Read more
Source§

impl DerefToPyAny for ZPKModel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromPyObject<'_> for T
where T: PyClass + Clone,

Source§

fn extract_bound(obj: &Bound<'_, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

Source§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

Source§

fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>

Converts self into an owned Python object, dropping type information.
Source§

fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
Source§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>

Converts self into a Python object. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PyErrArguments for T
where T: for<'py> IntoPyObject<'py> + Send + Sync,

Source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
Source§

impl<T> PyTypeCheck for T
where T: PyTypeInfo,

Source§

const NAME: &'static str = <T as PyTypeInfo>::NAME

Name of self. This is used in error messages, for example.
Source§

fn type_check(object: &Bound<'_, PyAny>) -> bool

Checks if object is an instance of Self, which may include a subtype. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> Ungil for T
where T: Send,