Bode plots are significant in the design and visualization of control systems. Since I move on Julia for everything, I wonder how to plot multiple responses of bode diagrams, for example, in this code, I got four plots that could be multiple in the same TF on the effect of the Q-factor
f1=bodeplot(LTISystem[G0], label=“G_0 at Q=0.5”);
f2=bodeplot(LTISystem[G1], label=“G_0 at Q=0.6”);
f3=bodeplot(LTISystem[G2], label=“G_0 at Q=0.7”);
f4=bodeplot(LTISystem[G3], label=“G_0 at Q=0.8”);
ControlSystemsBase does not have a built-in recipe for producing 3d-plots like that, but here’s something to get you started.
using ControlSystemsBase, Plots
pyplot()
function meshgrid(a,b)
grid_a = [i for i in a, j in b]
grid_b = [j for i in a, j in b]
grid_a, grid_b
end
ω = 1
G = [tf(ω^2, [1, 2ζ*ω, ω^2]) for ζ in ζs]
ζs = exp10.(LinRange(-4, -0.2, 200))
w = exp10.(LinRange(-2, 2, 200))
Z, W = meshgrid(ζs, w)
M = map(W, Z) do w, ζ
G = tf(ω^2, [1, 2ζ*ω, ω^2])
abs(freqresp(G, w)[])
end
surface(log10.(W), Z, log10.(M), xscale=:identity, yscale=:identity, zscale=:identity, xlabel="ω", ylabel="ζ", zlabel="|G(ω)|")
Hello! It is a beautiful plot, but I couldn’t reproduce your result xD, do you have more information on how can I build it, because I am a newbie, or any site about it?
What problem did you encounter? The code above should be self sufficient, you only need to ensure that the packages that are being loaded at the top are installed.
Hello again, I checked the logic and all is fine until I plot the surface, I checked the zeta sweep in every new TF, and again is all good; I only modified the zeta and w sweeps at bottom of G to make it work.
using ControlSystemsBase, Plots, PyCall
pyplot()
function meshgrid(a,b)
grid_a = [i for i in a, j in b]
grid_b = [j for i in a, j in b]
grid_a, grid_b
end
ω = 1
ζs = exp10.(LinRange(-4, -0.2, 200))
w = exp10.(LinRange(-2, 2, 200))
G = TransferFunction[tf(ω^2, [1, 2ζ*ω, ω^2]) for ζ in ζs]
Z, W = meshgrid(ζs, w)
M = map(W, Z) do w, ζ
G = tf(ω^2, [1, 2ζ*ω, ω^2])
abs(freqresp(G, w)[])
end
surface(log10.(W),
Z,
log10.(M),
xscale=:identity,
yscale=:identity,
zscale=:identity,
xlabel="ω",
ylabel="ζ",
zlabel="|G(ω)|")
Hmm, that exact code gives me the same figure I posted before Maybe there’s something off with PyPlot on your machine? Can you rotate the figure by clicking with the mouse and dragging?
You could also try another plotting backend, e.g., gr() or plotly(), here the latter might require you to install Plotly.jl
Thank you so much! with gr() it works! And you may have the reason that PyPlot doesn’t work as I expected on my machine since I had to run in the terminal, I think is time for a hard reset xD