In [1]:
import seaborn as sns
from scipy import signal
from matplotlib import pyplot as plt
%matplotlib inline
In automatics control (and engineering in general), a transfer function is the relation between the input and the output of a linear time-invariant system with zero initial conditions: $$G(s) = \frac{Y(s)}{X(s)} = \frac{ \mathcal{L}\left\{y(t)\right\} }{ \mathcal{L}\left\{x(t)\right\} }$$
As presented above, Laplace transform is used to change from the time domain to the s-complex domain.
Different linear systems can be represented by their transfer function.
For example, a simple $G(s) = \frac{3}{s+5}$ object can be modelled in Python as follows:
In [9]:
numerator = (3, )
denominator = (1, 5)
system = (numerator, denominator)
system_lti = signal.lti(numerator, denominator)
With the help from scipy.signal it's very easy to present typical properties of LTI systems, like step or impulse response, Bode plot or Nyquist plot.
In [10]:
plt.plot(*signal.step(system))
Out[10]:
In [4]:
plt.plot(*signal.impulse(system))
Out[4]:
In [5]:
# TODO: doesn't work too well, for now :/
# frequency response (is it Nyquist, though???)
plt.plot(*signal.freqresp(system))
Out[5]:
In [6]:
# Bode diagram
omega, mag, pha = signal.bode(system)
plt.semilogx(omega, mag)
plt.semilogx(omega, pha)
Out[6]: