Python-control provides a number of methods for creating LTI control systems.
ss() | create state-space (SS) models |
tf() | create transfer function (TF) models |
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.
Create a state space system.
The function accepts either 1 or 4 parameters:
Create a state space system from the matrices of its state and output equations:
The matrices can be given as array like data types or strings. Everything that the constructor of numpy.matrix accepts is permissible here too.
Parameters: | sys: Lti (StateSpace or TransferFunction)
A: array_like or string
B: array_like or string
C: array_like or string
D: array_like or string
|
---|---|
Returns: | out: StateSpace
|
Raises: | ValueError
|
Examples
>>> # Create a StateSpace object from four "matrices".
>>> sys1 = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> # Convert a TransferFunction to a StateSpace object.
>>> sys_tf = tf([2.], [1., 3])
>>> sys2 = ss(sys_tf)
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.
Create a transfer function system. Can create MIMO systems.
The function accepts either 1 or 2 parameters:
Create a transfer function system from its numerator and denominator polynomial coefficients.
If num and den are 1D array_like objects, the function creates a SISO system.
To create a MIMO system, num and den need to be 2D nested lists of array_like objects. (A 3 dimensional data structure in total.) (For details see note below.)
Parameters: | sys: Lti (StateSpace or TransferFunction)
num: array_like, or list of list of array_like
den: array_like, or list of list of array_like
|
---|---|
Returns: | out: TransferFunction
|
Raises: | ValueError
TypeError
|
Notes
Todo
The next paragraph contradicts the comment in the example! Also “input” should come before “output” in the sentence:
“from the (j+1)st output to the (i+1)st input”
num[i][j] contains the polynomial coefficients of the numerator for the transfer function from the (j+1)st output to the (i+1)st input. den[i][j] works the same way.
The coefficients [2, 3, 4] denote the polynomial .
Examples
>>> # Create a MIMO transfer function object
>>> # The transfer function from the 2nd input to the 1st output is
>>> # (3s + 4) / (6s^2 + 5s + 4).
>>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]
>>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]]
>>> sys1 = tf(num, den)
>>> # Convert a StateSpace to a TransferFunction object.
>>> sys_ss = ss("1. -2; 3. -4", "5.; 7", "6. 8", "9.")
>>> sys2 = tf(sys1)
Create a stable discrete random state space object.
Parameters: | states: integer
inputs: integer
outputs: integer
|
---|---|
Returns: | sys: StateSpace
|
Raises: | ValueError
|
See also
rss
Notes
If the number of states, inputs, or outputs is not specified, then the missing numbers are assumed to be 1. The poles of the returned system will always have a magnitude less than 1.
Check to see if a system is a continuous time system
Parameters: | sys : LTI system
strict: bool (default = False)
|
---|
Check to see if a system is a discrete time system
Parameters: | sys : LTI system
strict: bool (default = False)
|
---|
Create a linear system that approximates a delay.
Return the numerator and denominator coefficients of the Pade approximation.
Parameters: | T : number
n : integer
|
---|---|
Returns: | num, den : array
|
Notes
Based on an algorithm in Golub and van Loan, “Matrix Computation” 3rd. Ed. pp. 572-574.
Convert a continuous time system to discrete time
Creates a discrete time system from a continuous time system by sampling. Multiple methods of conversion are supported.
Parameters: | sysc : linsys
Ts : real
method : string
|
---|---|
Returns: | sysd : linsys
|
Notes
Examples
>>> sysc = TransferFunction([1], [1, 2, 1])
>>> sysd = sample_system(sysc, 1, method='matched')
Transform a state space system to a transfer function.
The function accepts either 1 or 4 parameters:
Create a state space system from the matrices of its state and output equations.
For details see: ss()
Parameters: | sys: StateSpace
A: array_like or string
B: array_like or string
C: array_like or string
D: array_like or string
|
---|---|
Returns: | out: TransferFunction
|
Raises: | ValueError
TypeError
|
Examples
>>> A = [[1., -2], [3, -4]]
>>> B = [[5.], [7]]
>>> C = [[6., 8]]
>>> D = [[9.]]
>>> sys1 = ss2tf(A, B, C, D)
>>> sys_ss = ss(A, B, C, D)
>>> sys2 = ss2tf(sys_ss)
Return state space data objects for a system
Parameters: | sys: Lti (StateSpace, or TransferFunction)
|
---|---|
Returns: | (A, B, C, D): list of matrices
|
Transform a transfer function to a state space system.
The function accepts either 1 or 2 parameters:
Create a transfer function system from its numerator and denominator polynomial coefficients.
For details see: tf()
Parameters: | sys: Lti (StateSpace or TransferFunction)
num: array_like, or list of list of array_like
den: array_like, or list of list of array_like
|
---|---|
Returns: | out: StateSpace
|
Raises: | ValueError
TypeError
|
Examples
>>> num = [[[1., 2.], [3., 4.]], [[5., 6.], [7., 8.]]]
>>> den = [[[9., 8., 7.], [6., 5., 4.]], [[3., 2., 1.], [-1., -2., -3.]]]
>>> sys1 = tf2ss(num, den)
>>> sys_tf = tf(num, den)
>>> sys2 = tf2ss(sys_tf)
Return transfer function data objects for a system
Parameters: | sys: Lti (StateSpace, or TransferFunction)
|
---|---|
Returns: | (num, den): numerator and denominator arrays
|
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.
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.