Visualization

poles and zeros of a transfer function

g = (s + 2) / (s^2 + 1/4)
viz_poles_and_zeros(g)

response of a system to an input

g = 4 / (4 * s ^ 2 + 0.8 * s + 1)
U = 1 / s
Y = g * U
data = simulate(Y, (0.0, 50.0))
viz_response(data, plot_title="SO underdamped step response")

Nyquist diagram

g = 1 / (s^2 + s + 1)
nyquist_diagram(g)

Bode plot

g = 3 / (s + 1)
bode_plot(g, log10_ω_min=-4.0, log10_ω_max=4.0, nb_pts=300)

the range of frequencies presented is determined by log10_ω_min and log10_ω_max. the resolution of the Bode plot is determined by nb_pts.

see gain_phase_margins to compute the gain and phase margins and the critical and gain crossover frequencies.

Root locus plot

g_ol = 4 / (s + 3) / (s + 2) / (s + 1)
root_locus(g_ol)

hipster plot theme

invoke the hipster plot theme used to make plots for this documentation by:

using PyPlot
PyPlot.matplotlib.style.use("https://raw.githubusercontent.com/SimonEnsemble/Controlz.jl/master/src/hipster.mplstyle")

detailed docs

Missing docstring.

Missing docstring for viz_response. Check Documenter's build log for details.

Controlz.nyquist_diagramFunction
nyquist_diagram(tf, nb_pts=500, ω_max=10.0)

plot the Nyquist diagram for a transfer function tf to visualize its frequency response. s=-1 is plotted as a red +. nb_pts changes the resolution. ω_max gives maximum frequency considered.

source
Controlz.bode_plotFunction
axs = bode_plot(tf, log10_ω_min=-4.0, log10_ω_max=4.0, nb_pts=300)

draw the Bode plot of a transfer function tf to visualize its frequency response. returns the two axes of the plot for further tuning via matplotlib commands.

adjust the range of frequencies that the Bode plot presents with log10_ω_min and log10_ω_max. increase the resolution of the Bode plot with nb_pts.

source
Controlz.root_locusFunction
root_locus(g_ol, max_mag_Kc=10.0, nb_pts=500)

visualize the root locus plot of an open-loop transfer function g_ol.

Arguments

  • g_ol::TransferFunction: the open-loop transfer function of the closed loop system
  • max_mag_Kc::Float64=10.0: the maximum magnitude by which the gain of g_ol is scaled in order to see the roots traversing the plane
  • nb_pts::Int=500: the number of gains to explore. increase for higher resolution.
source
Controlz.mk_gifFunction
mk_gif(data, plot_title="", plot_xlabel="time, t", 
             plot_ylabel="output, y(t)",
             savename="response")

make a .gif of the process response. data is a data frame with two columns, :t and :output, likely returned from simulate. accepts same arguments as viz_response. ImageMagick must be installed to create the .gif. the .gif is saved as a file savename.

Arguments

  • data::DataFrame: data frame of time series data, containing a :t column for times and :output column for the outputs.
  • plot_title::Union{String, LaTeXString}: title of plot
  • plot_xlabel::Union{String, LaTeXString}: x-label
  • plot_ylabel::Union{String, LaTeXString}: y-label
  • savename::String: filename to save as a .gif. .gif extension automatically appended if not provided.
source