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
impl TransferFunction
pub fn new(num: Vec<f64>, den: Vec<f64>) -> Result<Self, TransferFunctionError>
Sourcepub fn to_state_space(&self) -> StateSpace
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.
Sourcepub fn settled_state(&self, y0: f64) -> Result<Vec<f64>, SettledStateError>
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.
Sourcepub fn settled_state_discrete(
&self,
y0: f64,
) -> Result<Vec<f64>, SettledStateError>
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)}.$$