# Getting Started with Transfer Functions¶

by Jeffrey Kantor (jeff at nd.edu). The latest version of this notebook is available at https://github.com/jckantor/CBE30338.

The Python Control Systems Library provides basic tools for the analysis and design of linear feedback control systems. The library provides tools to specify transfer function and state space models, manipulate models using block diagram algebra, stability analysis, and perform time and frequency domain simulation.

The purpose of these notes is to provide a quick start with the Python Control Systems Library. Consult the Python Control Systems Documentation for more details.

## 1. Installation¶

The Python Control Systems Library is not, unfortunately, a standard part of most standard Python distributions. On most systems, the following commands will perform the required one-time installation of the necessary software.

In [1]:
!pip install slycot
!pip install control
Requirement already satisfied: slycot in /Users/jeff/anaconda/lib/python3.5/site-packages
Requirement already satisfied: control in /Users/jeff/anaconda/lib/python3.5/site-packages
Requirement already satisfied: matplotlib in /Users/jeff/anaconda/lib/python3.5/site-packages (from control)
Requirement already satisfied: numpy in /Users/jeff/anaconda/lib/python3.5/site-packages (from control)
Requirement already satisfied: scipy in /Users/jeff/anaconda/lib/python3.5/site-packages (from control)
Requirement already satisfied: six>=1.10 in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)
Requirement already satisfied: python-dateutil in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)
Requirement already satisfied: pytz in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)
Requirement already satisfied: cycler>=0.10 in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=1.5.6 in /Users/jeff/anaconda/lib/python3.5/site-packages (from matplotlib->control)

## 2. Library Usage¶

The control systems library is designed to work with a simplified syntax where libraries are imported without the standard prefixes.

In [2]:
%matplotlib inline

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import control.matlab as control

## 3. Demonstration¶

### 3.1 Step Response of Transfer Functions¶

The following cells demonstrate the use of two functions in the control systems library, tf and step. Suppose a signal $y(s)$ is related to an input $u(s)$ by the formula

$$y(s) = \underbrace{\frac{4.3}{3.2s + 1}}_{G(s)} u(s)$$

The transfer function

$$G(s) = \frac{4.3}{3.2 s + 1}$$

is represented in the control system libary using tf(num,den) where num and den list the coefficients of the numerator and denominator polynomials.

In [3]:
G = control.tf([4.3],[3.2, 1])
print(G)
4.3
---------
3.2 s + 1

The step response is created and plotted as

In [4]:
y,t = control.step(G)
plt.plot(t,y)
plt.xlabel('Time')
plt.title('Step Response')
Out[4]:
<matplotlib.text.Text at 0x115bfb748>

### 3.2 Transfer Functions in Series¶

Models for complex systems are generally constructed by combining models of simpler elements. Consider, for example, a serial connection of two transfer functions

$$y_1(s) = G_1(s) u(s)$$

$$y_2(s) = G_2(s) y_1(s)$$

which can be diagrammed as

$$u(s) \longrightarrow \boxed{\\G_1(s)} \stackrel{y_1(s)}{\longrightarrow} \boxed{\\G_2(s)} \longrightarrow y_2(s)$$

The serial composition of two transfer functions can be written

$$y_2(s) = \underbrace{G_2(s)G_1(s)}_{G(s)} u(s)$$

where the product $G(s) = G_2(s)G_1(s)$ represents the transfer function of the combined system. In terms of a block diagram

$$u(s) \longrightarrow \boxed{\\G_1(s)} \stackrel{y_1(s)}{\longrightarrow} \boxed{\\G_2(s)} \longrightarrow y_2(s) \qquad \implies \qquad u(s) \longrightarrow \boxed{\\G_2(s)G_1(s)} \longrightarrow y_2(s)$$

The product G(s) = G_2(s)G_1(s)$$is computed by taking the products of the numerator and denominator polynomials, respectively. For example, suppose$$G_1(s) = \frac{12.3}{10 s + 1} \text{ and }G_2(s) = \frac{4}{15 s + 1}Then \begin{align*} G(s) & = G_2(s)G_1(s) \\ & = \frac{4}{15 s + 1} \times \frac{12.3}{10 s + 1} = \frac{4 \times 12.3}{(15s + 1)(10s + 1)} = \frac{49.2}{150 s^2 + 25s + 1} \end{align*} We can verify this calculation using the control systems library. In [5]: G1 = control.tf([12.3],[10,1]) G2 = control.tf([4],[15,1]) G = G2 * G1 print(G) y,t = control.step(G) plt.plot(t,y) plt.xlabel('Time') plt.title('Step Response of Two First Order Transfer Functions in Series') 49.2 ------------------ 150 s^2 + 25 s + 1 Out[5]: <matplotlib.text.Text at 0x115d47128> ### 3.3 Second Order Transfer Functions¶ The control systems library is particularly helpful when working with second and higher order transfer functions. ForG(s) = \frac{3}{4s^2 + s + 1}\$

In [6]:
R = control.tf([3.],[4.,1.,1.])
print(R)

y,t = control.step(R)
plt.plot(t,y)
plt.xlabel('Time')
plt.title('Response of a Second Order System')
3
-------------
4 s^2 + s + 1

Out[6]:
<matplotlib.text.Text at 0x115dbcd68>