Skip to main content

TransferFunction

Struct TransferFunction 

Source
pub struct TransferFunction {
    pub num: Vec<f64>,
    pub den: Vec<f64>,
}
Expand description

A single-input single-output transfer function N(s) / D(s), coefficients highest-degree first (e.g. s + 1 is [1.0, 1.0]). D must be nonzero-leading (degree = den.len() - 1) and deg(N) <= deg(D) — a proper transfer function; this is what every realizable continuous-time physical system is.

Fields§

§num: Vec<f64>§den: Vec<f64>

Implementations§

Source§

impl TransferFunction

Source

pub fn new(num: Vec<f64>, den: Vec<f64>) -> Result<Self, TransferFunctionError>

Source

pub fn to_state_space(&self) -> StateSpace

Realizes this transfer function in controllable canonical form.

D(s) = s^n + a_{n-1} s^{n-1} + ... + a_0 (monic, after normalizing by the original leading coefficient). If deg(N) == n, one step of polynomial long division extracts the direct feedthrough d = N[0] (after normalization) and leaves a strictly proper remainder R(s) = b_{n-1} s^{n-1} + ... + b_0; otherwise d = 0 and R = N.

A = [ 0      1      0     ...  0    ]      B = [0]
    [ 0      0      1     ...  0    ]          [0]
    [ ...                             ]         [...]
    [ 0      0      0     ...  1    ]          [0]
    [-a_0   -a_1   -a_2   ... -a_{n-1}]         [1]

C = [b_0, b_1, ..., b_{n-1}]      D = [d]

Verified against a first-order case by hand (docs/tests): for 1/(s+1), this gives exactly A=[[-1]], B=[[1]], C=[[1]], D=[[0]], the textbook single-state realization.

Source

pub fn settled_state(&self, y0: f64) -> Result<Vec<f64>, SettledStateError>

The state of Self::to_state_space’s realization that a continuous-time filter already settled at output $y_0$ holds — what a netlist’s y0= (and kind=pid’s own ic=) means.

In controllable canonical form every state is the derivative of the one before it, so an equilibrium is $x = (x_1, 0, \dots, 0)$, and the last row, $-a_0 x_1 + u_0 = 0$, fixes the constant input holding it there at $u_0 = a_0 x_1$. The output is then $y_0 = b_0 x_1 + d,u_0 = (b_0 + d,a_0),x_1$, and $b_0 + d,a_0$ is exactly the normalized numerator’s constant term $N(0)$, hence

$$x_1 = \frac{y_0}{b_0 + d,a_0}.$$

Nothing here needs $a_0 \ne 0$: for a transfer function with a pole at the origin (an integrator, a PID) the holding input is simply $u_0 = 0$, which is the “integrator pre-loaded, zero error” start a controller wants.

Source

pub fn settled_state_discrete( &self, y0: f64, ) -> Result<Vec<f64>, SettledStateError>

The discrete-time counterpart of Self::settled_state, for the same realization stepped as $x[k+1] = A x[k] + B u[k]$.

Here every state is the one before it delayed by a sample, so an equilibrium has all $n$ states equal, $x_i = \bar{x}$; the last row gives the holding input $u_0 = (1 + \sum_i a_i),\bar{x}$, and the output is $y_0 = \big(\sum_i b_i + d,(1 + \sum_i a_i)\big),\bar{x}$ — the normalized numerator evaluated at $z = 1$ — hence

$$\bar{x} = \frac{y_0}{\sum_i b_i + d,\big(1 + \sum_i a_i\big)}.$$

Trait Implementations§

Source§

impl Clone for TransferFunction

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TransferFunction

Source§

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

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

impl PartialEq for TransferFunction

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for TransferFunction

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, 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> 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> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.