Data Science and Computing with Python for Pilots and Flight Test Engineers
Conversion between System Representations
In the previous lesson we have learned that during the creation of a control system, we can choose between three different representations: transfer function (tf), zeros-poles-gain (zpk) and state space (ss). In this lesson we learn how to convert between these representation, i.e. if we have created our system in one representation, how to turn it later into another.
Conversion between Representations with scipy.signal Submodule of SciPy Library
Given a linear control system \(sys\), defined by differential equation
$$ \ddot x(t) + 2 \dot x(t) + 17 x = f(t) $$
and created initially, for instance, in the state space (ss) representation with:
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
A = np.array([[-2.0, -17.0],[1.0, 0.0]])
B = np.array([[1.0],[0.0]])
C = np.array([[0.0, 1.0]])
D = np.array([[0.0]])
sys = signal.lti(A, B, C, D)
sys
we can convert it to transfer function representation (tf), zeros/poles/gain representation (zpk), and back to state-space representation (ss), respectively with the following methods provided by all three of the lti subclasses TransferFunction, ZerosPolesGain, StateSpace:
sys.to_tf()
sys.to_zpk()
sys.to_ss()
Conversion between Representations with control.matlab Submodule of python-control Library
Given a linear control system \(sys\), defined by differential equation
$$ \ddot x(t) + 2 \dot x(t) + 17 x = f(t) $$
and created initially, for instance, in the state space (ss) representation with:
import numpy as np
import matplotlib.pyplot as plt
from control.matlab import *
A = np.array([[-2, -17],[1.0, 0.0]])
B = np.array([[1.0],[0.0]])
C = np.array([[0.0, 1.0]])
D = np.array([[0.0]])
sys_ss = ss(A, B, C, D)
sys_ss
we can convert it to transfer function representation (tf), and back to state-space representation (ss), respectively.
sys = ss2tf(sys) # converts ss representation to tf representation
sys = tf2ss(sys) # converts ft representation to ss representation
Exercise
Set up the example system above in transfer function representation. (In order to do this, you need to find out the transfer function corresponding the the above differential equation (see lesson on Control System Setup Theory). Then convert the system to state space representation using the corresponding line of code above. Output the result (by simply typing the name of the system instance on a line by itself) and compare the \(A, B, C, D\) matrices output by the computer on that occasion to the ones given above in one of the code cells. They should turn out to be the same.