PythonControl 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 pythoncontrol library.
Routines in this module:
Lti.__init__ isdtime() isctime() timebase() timebaseEqual()

class
control.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

isctime
(strict=False)¶ Check to see if a system is a continuoustime system
Parameters: sys : LTI system
System to be checked
strict: bool (default = False) :
If strict is True, make sure that timebase is not None

isdtime
(strict=False)¶ Check to see if a system is a discretetime system
Parameters: strict: bool (default = False) :
If strict is True, make sure that timebase is not None

control.lti.
isctime
(sys, strict=False)¶ Check to see if a system is a continuoustime system
Parameters: sys : LTI system
System to be checked
strict: bool (default = False) :
If strict is True, make sure that timebase is not None

control.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

control.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.

control.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 pythoncontrol library.
Routines in this module:
StateSpace.__init__ StateSpace._remove_useless_states StateSpace.copy StateSpace.__str__ StateSpace.__repr__ 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 StateSpace.__getitem__ _convertToStateSpace _rss_generate

class
control.statesp.
StateSpace
(*args)¶ The StateSpace class represents state space instances and functions.
The StateSpace class is used throughout the pythoncontrol 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.

append
(other)¶ Append a second model to the present model. The second model is converted to statespace 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.

sample
(Ts, method='zoh', alpha=None)¶ Convert a continuous time system to discrete time
Creates a discretetime system from a continuoustime system by sampling. Multiple methods of conversion are supported.
Parameters: Ts : float
Sampling period
method : {“gbt”, “bilinear”, “euler”, “backward_diff”, “zoh”}
Which method to use:
 gbt: generalized bilinear transformation
 bilinear: Tustin’s approximation (“gbt” with alpha=0.5)
 euler: Euler (or forward differencing) method (“gbt” with alpha=0)
 backward_diff: Backwards differencing (“gbt” with alpha=1.0)
 zoh: zeroorder hold (default)
alpha : float within [0, 1]
The generalized bilinear transformation weighting parameter, which should only be specified with method=”gbt”, and is ignored otherwise
Returns: sysd : StateSpace system
Discrete time system, with sampling rate Ts
Notes
Uses the command ‘cont2discrete’ from scipy.signal
Examples
>>> sys = StateSpace(0, 1, 1, 0) >>> sysd = sys.sample(0.5, method='bilinear')

zero
()¶ Compute the zeros of a state space system.

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 pythoncontrol library.
Routines in this module:
TransferFunction.__init__ TransferFunction._truncatecoeff TransferFunction.copy TransferFunction.__str__ TransferFunction.__repr__ 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
control.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 pythoncontrol library to represent systems in transfer function form.
The main data members are ‘num’ and ‘den’, which are 2D 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 nonzero 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.

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.

sample
(Ts, method='zoh', alpha=None)¶ Convert a continuoustime system to discrete time
Creates a discretetime system from a continuoustime system by sampling. Multiple methods of conversion are supported.
Parameters: Ts : float
Sampling period
method : {“gbt”, “bilinear”, “euler”, “backward_diff”, “zoh”, “matched”}
Which method to use:
 gbt: generalized bilinear transformation
 bilinear: Tustin’s approximation (“gbt” with alpha=0.5)
 euler: Euler (or forward differencing) method (“gbt” with alpha=0)
 backward_diff: Backwards differencing (“gbt” with alpha=1.0)
 zoh: zeroorder hold (default)
alpha : float within [0, 1]
The generalized bilinear transformation weighting parameter, which should only be specified with method=”gbt”, and is ignored otherwise
Returns: sysd : StateSpace system
Discrete time system, with sampling rate Ts
Notes
 Available only for SISO systems
 Uses the command cont2discrete from scipy.signal
Examples
>>> sys = TransferFunction(1, [1,1]) >>> sysd = sys.sample(0.5, method='bilinear')

zero
()¶ Compute the zeros of a transfer function.

FRD Class¶

class
control.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 pythoncontrol 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.80.2j, 0.20.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.

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.
