API Documentation

Package Root

Root module of tanuna package.

@author: Adrian Schlatter

exception tanuna.root.ApproximationError[source]
class tanuna.root.CT_LTI_System(A, B, C, D, x0=None)[source]

Continuous-time, Linear, time-invariant system

property Wo

Observability matrix

property Wr

Reachability matrix

freqResponse(f=None)[source]

Returns (f, r), where

f : Array of frequencies r : (Complex) frequency response

f is either provided as an argument to thin function or determined automatically.

impulseResponse(t=None)[source]

Returns (t, yimpulse), where

yimpulse : Impulse response (without direct term D) t : Corresponding array of times

t is either provided as an argument to this function or determined automatically.

property observable

Returns True if the system is observable.

property order

The order of the system

property poles

Eigenvalues of the state matrix

property reachable

Returns True if the system is reachable.

property shape

Number of outputs and inputs

stepResponse(t=None)[source]

Returns (t, ystep), where

ystep : Step response t : Corresponding array of times

t is either provided as an argument to this function or determined automatically.

property tf

Transfer-function representation [b, a] of the system. Returns numerator (b) and denominator (a) coefficients.

\[G(s) = \frac{b[0] * s^0 + ... + b[m] * s^m} {a[0] * s^0 + ... + a[n] * s^n}\]
property zpk

Gain, Pole, Zero representation of the system. Returns a tuple (z, p, k) with z the zeros, p the poles, and k the gain of the system. p is an array. The format of z and k depends on the number of inputs and outputs of the system:

For a SISO system z is an array and k is float. For a system with more inputs or outputs, z and k are lists of ‘shape’ (nout, nin) containing arrays and floats, respectively.

class tanuna.root.CT_System(f, g, s0)[source]

Describes a continuous-time system with dynamics described by ordinary differential equations.

s: Internal state (vector) of the system s0: Initial state of the system u: External input (vector)

f(t, s, u): Dynamics of the system (ds/dt = f(t, s, u)) g(t, s, u): Function that maps state s to output y = g(t, s, u)

It is solved by simply calling it with an argument t. t is either a float or array-like. In the latter case, the system is solved for all the times t in the array.

observable(t)[source]

Returns whether the system is observable at time t (i.e. its internal state is determinable from inputs u and outputs y).

reachable(t)[source]

Returns whether the system is reachable at time t (i.e. all states are reachable by providing an appropriate input u(t)).

steadyStates(u0, t)[source]

Returns a list of tuples (s_i, stability_i) with:

  • s_i: A steady-state at time t, i.e. f(t, s_i, u0) = 0

  • stability_i: True if this steady-state is stable, false otherwise

tangentLTI(s0, u0, t)[source]

Approximates the CT_System at time t near state s0 and input u0 by an LTISystem (linear, time-invariant system). Raises ApproximationError if the system can not be linearized.

exception tanuna.root.ConnectionError[source]
class tanuna.root.DT_LTI_System(A, B, C, D, x0=matrix([[0.], [0.]]))[source]

Implements the discrete-time linear, time-invariant system with input vector u[t], internal state vector x[t], and output vector y[t]:

x[t+1] = A * x[t] + B * u[t] y[t] = C * x[t] + D * u[t]

where

A: state matrix B: input matrix C: output matrix D: feedthrough matrix

The system is initialized with state vector x[0] = x0.

classmethod fromTransferFunction(phi)[source]

Initialize DiscreteLTI instance from transfer-function coefficients ‘Theta’ and ‘phi’.

observable()[source]

Returns true if the system is observable

proper()[source]

Returns true if the system’s transfer function is strictly proper, i.e. the degree of the numerator is less than the degree of the denominator.

reachable()[source]

Returns True if the system is observable

stable()[source]

Returns True if the system is strictly stable

tf()[source]

Returns the transfer function (b, a) where ‘b’ are the coefficients of the nominator polynomial and ‘a’ are the coefficients of the denominator polynomial.

class tanuna.root.DT_LTV_System(At, Bt, Ct, Dt, X0)[source]

Implements the discrete linear, time-variant system with input vector u[t], internal state vector x[t], and output vector y[t]:

x[t+1] = A[t]*x[t] + B[t]*u[t] y[t] = C*x[t] + D*u[t]

where

A[t]: state matrices B[t]: input matrices C[t]: output matrices D[t]: feedthrough matrices

The system is initialized with state vector x[0] = X0.

exception tanuna.root.MatrixError[source]
tanuna.root.Thetaphi(b, a)[source]

Translate filter-coefficient arrays b and a to Theta, phi representation:

phi(B)*y_t = Theta(B)*x_t

Theta, phi = Thetaphi(b, a) are the coefficient of the back-shift-operator polynomials (index i belongs to B^i)

tanuna.root.ba(Theta, phi)[source]

Translate backshift-operator polynomials Theta and phi to filter coefficient array b, a.

a[0]*y[t] = a[1]*y[t-1] + … + a[n]*y[t-n] + b[0]*x[t] + … + b[m]*x[t-m]

tanuna.root.cofactorMat(A)[source]

Cofactor matrix of matrix A. Can handle matrices of poly1d.

tanuna.root.connect(H, G, Gout=None, Hin=None)[source]

Connect outputs Gout of G to inputs Hin of H. The outputs and inputs of the connected system are arranged as follows:

  • remaining outputs of G get lower, the outputs of H the higher indices

  • inputs of G get the lower, remaining inputs of H the higher indices

connect(H, G) is equivalent to H * G.

tanuna.root.determinant(A)[source]

Determinant of square matrix A. Can handle matrices of poly1d.

tanuna.root.differenceEquation(b, a)[source]

Takes filter coefficient arrays b and a and returns string with difference equation using powers of B, where B the backshift operator.

tanuna.root.feedback(G, Gout, Gin)[source]

Create feedback connection from outputs Gout to inputs Gin

tanuna.root.minor(A, i, j)[source]

Returns matrix obtained by deleting row i and column j from matrix A.

tanuna.root.polyDiag(polyList)[source]

Construct diagonal matrix from list of poly1d

Continuous-Time LTI Library

Library of ready-to-use continuous-time LTI systems.

@author: Adrian Schlatter

class tanuna.CT_LTI.HighPass(fC, k=1.0)[source]

High-Pass Filter with 3-dB frequency fC and pass-band gain k

class tanuna.CT_LTI.LowPass(fC, k=1.0)[source]

Low-Pass Filter with 3-dB frequency fC and DC-gain k

class tanuna.CT_LTI.Order2(w0, zeta, k)[source]

A second-order system with

  • w0: Natural frequency

  • zeta: Damping ratio (0: undamped, 1: critically damped)

  • k: Gain