Python-Control Classes

LTI System Class

lti.py

The Lti module contains the Lti parent class to the child classes StateSpace and TransferFunction. It is designed for use in the python-control library.

Routines in this module:

Lti.__init__ isdtime() isctime() timebase() timebaseEqual()

class lti.Lti(inputs=1, outputs=1, dt=None)

Lti is a parent class to linear time invariant control (LTI) objects.

Lti is the parent to the StateSpace and TransferFunction child classes. It contains the number of inputs and outputs, and the timebase (dt) for the system.

The timebase for the system, dt, is used to specify whether the system is operating in continuous or discrete time. It can have the following values:

  • dt = None No timebase specified
  • dt = 0 Continuous time system
  • dt > 0 Discrete time system with sampling time dt
  • dt = True Discrete time system with unspecified sampling time

When to Lti systems are combined, there timebases much match. A system with timebase None can be combined with a system having a specified timebase, and the result will have the timebase of the latter system.

The StateSpace and TransferFunction child classes contain several common “virtual” functions. These are:

__init__ copy __str__ __neg__ __add__ __radd__ __sub__ __rsub__ __mul__ __rmul__ __div__ __rdiv__ evalfr freqresp pole zero feedback returnScipySignalLti

Methods

damp()
lti.isctime(sys, strict=False)

Check to see if a system is a continuous time system

Parameters:

sys : LTI system

System to be checked

strict: bool (default = False)

If strict is True, make sure that timebase is not None

lti.isdtime(sys, strict=False)

Check to see if a system is a discrete time system

Parameters:

sys : LTI system

System to be checked

strict: bool (default = False)

If strict is True, make sure that timebase is not None

lti.timebase(sys, strict=True)

Return the timebase for an Lti system

dt = timebase(sys)

returns the timebase for a system ‘sys’. If the strict option is set to False, dt = True will be returned as 1.

lti.timebaseEqual(sys1, sys2)

Check to see if two systems have the same timebase

timebaseEqual(sys1, sys2)

returns True if the timebases for the two systems are compatible. By default, systems with timebase ‘None’ are compatible with either discrete or continuous timebase systems. If two systems have a discrete timebase (dt > 0) then their timebases must be equal.

State Space Class

statesp.py

State space representation and functions.

This file contains the StateSpace class, which is used to represent linear systems in state space. This is the primary representation for the python-control library.

Routines in this module:

StateSpace.__init__ StateSpace._remove_useless_states StateSpace.copy StateSpace.__str__ StateSpace.__neg__ StateSpace.__add__ StateSpace.__radd__ StateSpace.__sub__ StateSpace.__rsub__ StateSpace.__mul__ StateSpace.__rmul__ StateSpace.__div__ StateSpace.__rdiv__ StateSpace.evalfr StateSpace.freqresp StateSpace.pole StateSpace.zero StateSpace.feedback StateSpace.returnScipySignalLti StateSpace.append _convertToStateSpace _rss_generate

class statesp.StateSpace(*args)

The StateSpace class represents state space instances and functions.

The StateSpace class is used throughout the python-control library to represent systems in state space form. This class is derived from the Lti base class.

The main data members are the A, B, C, and D matrices. The class also keeps track of the number of states (i.e., the size of A).

Discrete time state space system are implemented by using the ‘dt’ class variable and setting it to the sampling period. If ‘dt’ is not None, then it must match whenever two state space systems are combined. Setting dt = 0 specifies a continuous system, while leaving dt = None means the system timebase is not specified. If ‘dt’ is set to True, the system will be treated as a discrete time system with unspecified sampling time.

Methods

append(other) Append a second model to the present model.
damp()
evalfr(omega) Evaluate a SS system’s transfer function at a single frequency.
feedback([other, sign]) Feedback interconnection between two LTI systems.
freqresp(omega) Evaluate the system’s transfer func.
horner(s) Evaluate the systems’s transfer function for a complex variable
minreal([tol]) Calculate a minimal realization, removes unobservable and
pole() Compute the poles of a state space system.
returnScipySignalLti() Return a list of a list of scipy.signal.lti objects.
zero() Compute the zeros of a state space system.
append(other)

Append a second model to the present model. The second model is converted to state-space if necessary, inputs and outputs are appended and their order is preserved

evalfr(omega)

Evaluate a SS system’s transfer function at a single frequency.

self.evalfr(omega) returns the value of the transfer function matrix with input value s = i * omega.

feedback(other=1, sign=-1)

Feedback interconnection between two LTI systems.

freqresp(omega)

Evaluate the system’s transfer func. at a list of ang. frequencies.

mag, phase, omega = self.freqresp(omega)

reports the value of the magnitude, phase, and angular frequency of the system’s transfer function matrix evaluated at s = i * omega, where omega is a list of angular frequencies, and is a sorted version of the input omega.

horner(s)

Evaluate the systems’s transfer function for a complex variable

Returns a matrix of values evaluated at complex variable s.

minreal(tol=0.0)

Calculate a minimal realization, removes unobservable and uncontrollable states

pole()

Compute the poles of a state space system.

returnScipySignalLti()

Return a list of a list of scipy.signal.lti objects.

For instance,

>>> out = ssobject.returnScipySignalLti()
>>> out[3][5]

is a signal.scipy.lti object corresponding to the transfer function from the 6th input to the 4th output.

zero()

Compute the zeros of a state space system.

statesp.rand(d0, d1, ..., dn)

Random values in a given shape.

Create an array of the given shape and propagate it with random samples from a uniform distribution over [0, 1).

Parameters:

d0, d1, ..., dn : int, optional

The dimensions of the returned array, should all be positive. If no argument is given a single Python float is returned.

Returns:

out : ndarray, shape (d0, d1, ..., dn)

Random values.

See also

random

Notes

This is a convenience function. If you want an interface that takes a shape-tuple as the first argument, refer to np.random.random_sample .

Examples

>>> np.random.rand(3,2)
array([[ 0.14022471,  0.96360618],  #random
       [ 0.37601032,  0.25528411],  #random
       [ 0.49313049,  0.94909878]]) #random
statesp.randn(d0, d1, ..., dn)

Return a sample (or samples) from the “standard normal” distribution.

If positive, int_like or int-convertible arguments are provided, randn generates an array of shape (d0, d1, ..., dn), filled with random floats sampled from a univariate “normal” (Gaussian) distribution of mean 0 and variance 1 (if any of the d_i are floats, they are first converted to integers by truncation). A single float randomly sampled from the distribution is returned if no argument is provided.

This is a convenience function. If you want an interface that takes a tuple as the first argument, use numpy.random.standard_normal instead.

Parameters:

d0, d1, ..., dn : int, optional

The dimensions of the returned array, should be all positive. If no argument is given a single Python float is returned.

Returns:

Z : ndarray or float

A (d0, d1, ..., dn)-shaped array of floating-point samples from the standard normal distribution, or a single such float if no parameters were supplied.

See also

random.standard_normal
Similar, but takes a tuple as its argument.

Notes

For random samples from N(\mu, \sigma^2), use:

sigma * np.random.randn(...) + mu

Examples

>>> np.random.randn()
2.1923875335537315 #random

Two-by-four array of samples from N(3, 6.25):

>>> 2.5 * np.random.randn(2, 4) + 3
array([[-4.49401501,  4.00950034, -1.81814867,  7.29718677],  #random
       [ 0.39924804,  4.68456316,  4.99394529,  4.84057254]]) #random

Transfer Function Class

xferfcn.py

Transfer function representation and functions.

This file contains the TransferFunction class and also functions that operate on transfer functions. This is the primary representation for the python-control library.

Routines in this module:

TransferFunction.__init__ TransferFunction._truncatecoeff TransferFunction.copy TransferFunction.__str__ TransferFunction.__neg__ TransferFunction.__add__ TransferFunction.__radd__ TransferFunction.__sub__ TransferFunction.__rsub__ TransferFunction.__mul__ TransferFunction.__rmul__ TransferFunction.__div__ TransferFunction.__rdiv__ TransferFunction.__truediv__ TransferFunction.__rtruediv__ TransferFunction.evalfr TransferFunction.freqresp TransferFunction.pole TransferFunction.zero TransferFunction.feedback TransferFunction.minreal TransferFunction.returnScipySignalLti TransferFunction._common_den _tfpolyToString _addSISO _convertToTransferFunction

class xferfcn.TransferFunction(*args)

The TransferFunction class represents TF instances and functions.

The TransferFunction class is derived from the Lti parent class. It is used throught the python-control library to represent systems in transfer function form.

The main data members are ‘num’ and ‘den’, which are 2-D lists of arrays containing MIMO numerator and denominator coefficients. For example,

>>> num[2][5] = numpy.array([1., 4., 8.])

means that the numerator of the transfer function from the 6th input to the 3rd output is set to s^2 + 4s + 8.

Discrete time transfer functions are implemented by using the ‘dt’ class variable and setting it to something other than ‘None’. If ‘dt’ has a non-zero value, then it must match whenever two transfer functions are combined. If ‘dt’ is set to True, the system will be treated as a discrete time system with unspecified sampling time.

Methods

__call__(s) Evaluate the system’s transfer function for a complex vairable
damp()
evalfr(omega) Evaluate a transfer function at a single angular frequency.
feedback([other, sign]) Feedback interconnection between two LTI objects.
freqresp(omega) Evaluate a transfer function at a list of angular frequencies.
horner(s) Evaluate the systems’s transfer function for a complex variable
minreal([tol]) Remove cancelling pole/zero pairs from a transfer function
pole() Compute the poles of a transfer function.
returnScipySignalLti() Return a list of a list of scipy.signal.lti objects.
zero() Compute the zeros of a transfer function.
evalfr(omega)

Evaluate a transfer function at a single angular frequency.

self.evalfr(omega) returns the value of the transfer function matrix with input value s = i * omega.

feedback(other=1, sign=-1)

Feedback interconnection between two LTI objects.

freqresp(omega)

Evaluate a transfer function at a list of angular frequencies.

mag, phase, omega = self.freqresp(omega)

reports the value of the magnitude, phase, and angular frequency of the transfer function matrix evaluated at s = i * omega, where omega is a list of angular frequencies, and is a sorted version of the input omega.

horner(s)

Evaluate the systems’s transfer function for a complex variable

Returns a matrix of values evaluated at complex variable s.

minreal(tol=None)

Remove cancelling pole/zero pairs from a transfer function

pole()

Compute the poles of a transfer function.

returnScipySignalLti()

Return a list of a list of scipy.signal.lti objects.

For instance,

>>> out = tfobject.returnScipySignalLti()
>>> out[3][5]

is a signal.scipy.lti object corresponding to the transfer function from the 6th input to the 4th output.

zero()

Compute the zeros of a transfer function.

FRD Class

class frdata.FRD(*args, **kwargs)

The FRD class represents (measured?) frequency response TF instances and functions.

The FRD class is derived from the Lti parent class. It is used throughout the python-control library to represent systems in frequency response data form.

The main data members are ‘omega’ and ‘fresp’. omega is a 1D array with the frequency points of the response. fresp is a 3D array, with the first dimension corresponding to the outputs of the FRD, the second dimension corresponding to the inputs, and the 3rd dimension corresponding to the frequency points in omega. For example,

>>> frdata[2,5,:] = numpy.array([1., 0.8-0.2j, 0.2-0.8j])

means that the frequency response from the 6th input to the 3rd output at the frequencies defined in omega is set to the array above, i.e. the rows represent the outputs and the columns represent the inputs.

Methods

damp()
evalfr(omega) Evaluate a transfer function at a single angular frequency.
feedback([other, sign]) Feedback interconnection between two FRD objects.
freqresp(omega) Evaluate a transfer function at a list of angular frequencies.
evalfr(omega)

Evaluate a transfer function at a single angular frequency.

self.evalfr(omega) returns the value of the frequency response at frequency omega.

Note that a “normal” FRD only returns values for which there is an entry in the omega vector. An interpolating FRD can return intermediate values.

feedback(other=1, sign=-1)

Feedback interconnection between two FRD objects.

freqresp(omega)

Evaluate a transfer function at a list of angular frequencies.

mag, phase, omega = self.freqresp(omega)

reports the value of the magnitude, phase, and angular frequency of the transfer function matrix evaluated at s = i * omega, where omega is a list of angular frequencies, and is a sorted version of the input omega.

Table Of Contents

Previous topic

Utility Functions

This Page