Engee documentation
Notebook

Frequency response of SISO systems

This example shows how to plot the frequency response and obtain frequency response data for a single-input, single-output (SISO) dynamic system model.

Before you start, connect the package ControlSystems.jl.

In [ ]:
import Pkg
Pkg.add("ControlSystems")
In [ ]:
using ControlSystems
s = tf('s');

Create a model of the transfer function and plot its frequency response.

In [ ]:
H = tf([10,21],[1,1,4,26]); 
bode(H)
Out[0]:
([0.8088233541914841;;; 0.8089046843736906;;; 0.8089918641454111;;; … ;;; 0.0011497047425680343;;; 0.0010725473088794312;;; 0.0010005709166500281], [1.8467719298508563;;; 1.9119942598198527;;; 1.9795194061467587;;; … ;;; 179.3230779917472;;; 179.3462604412354;;; 179.36864326745186], [0.1, 0.10353218432956621, 0.10718913192051278, 0.11097524964120718, 0.11489510001873092, 0.11895340673703195, 0.12315506032928256, 0.12750512407130132, 0.1320088400831418, 0.13667163564620066  …  73.16807143427197, 75.75250258771912, 78.42822061337682, 81.19844993184013, 84.06652885618325, 87.03591361485161, 90.11018251665018, 93.29304026284686, 96.58832241158703, 100.0])

If you do not specify a frequency range to display, the bode function will automatically select a frequency range based on the system dynamics.

Calculate the frequency response between 1 and 13 rad/s.

In [ ]:
ω = collect(1:0.001:13);
mag, phase, w = bode(H, ω);

display([mag, phase])
2-element Vector{Array{Float64, 3}}:
 [0.9237490475443623;;; 0.9239884115824651;;; 0.924228047260294;;; … ;;; 0.06127526367424186;;; 0.06126550216321019;;; 0.061255743011682656]
 [18.620571649240677;;; 18.640012816814973;;; 18.65945837391501;;; … ;;; 174.636884266112;;; 174.63737792766062;;; 174.63787149391422]

When you call bode, the command returns vectors mag and phase containing the magnitude and phase of the frequency response. The array input $\omega$ tells bode to calculate the response over the frequency range from 1 to 13 rad/s. bode returns the frequency points in the vector w.

The resulting data can be plotted using the function bodeplot.

In [ ]:
bodeplot(H, ω, label = "H(s)")
Out[0]:

Conclusion

Thus, we have learnt how to plot the frequency response for a SISO system.