Back to the blog

Process Control with Python

Obtaining the step response of a closed-loop control system using the control library, equivalent to MATLAB's Control System Toolbox. The example uses a transfer function from Ogata [1].

\[\frac{C(s)}{R(s)} = \frac{6.3223\,s^2 + 18\,s + 12.8112}{s^4 + 6\,s^3 + 11.3223\,s^2 + 18\,s + 12.8112}\]
import control as ct
import matplotlib.pyplot as plt

# Variable in the Laplace domain
s = ct.TransferFunction.s

# Numerator and denominator of the Transfer Function
num = 6.3223*s**2 + 18*s + 12.8112
den = s**4 + 6*s**3 + 11.3223*s**2 + 18*s + 12.8112

# Transfer Function
TF = num/den

# Step Response
t, y = ct.step_response(TF)

# Plotting the step response
plt.plot(t, y)
plt.title("Step Response")
plt.ylabel("Amplitude")
plt.xlabel("Time [s]")
plt.grid()
plt.show()

Running this code produces the step response:

Step response

The system is underdamped: it exhibits an initial overshoot close to 1.6 and oscillations that decay until settling at unity. This type of analysis is the foundation for tuning PID controllers, evaluating stability criteria (Routh–Hurwitz, phase/gain margin) or comparing alternative designs before implementing them in hardware.

Installation:

pip install control

Reference

[1] K. Ogata, Control Engineering Problems Using Matlab. Prentice Hall, 2000.

Back to the blog