From 5d68fd449db2bcd3f780946684cdfecef61e65aa Mon Sep 17 00:00:00 2001 From: baggepinnen Date: Fri, 24 May 2019 17:13:18 +0200 Subject: [PATCH 1/3] Fix nyquistplot --- src/delay_systems.jl | 2 +- src/plotting.jl | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/delay_systems.jl b/src/delay_systems.jl index 9636dd7c5..bee8b2354 100644 --- a/src/delay_systems.jl +++ b/src/delay_systems.jl @@ -135,7 +135,7 @@ end # We have to default to something, look at the sys.P.P and delays -function _bounds_and_features(sys::DelayLtiSystem, plot::Symbol) +function _bounds_and_features(sys::DelayLtiSystem, plot::Val) ws, pz = _bounds_and_features(sys.P.P, plot) logtau = log10.(abs.(sys.Tau)) logtau = filter(x->x>4, logtau) # Ignore low frequency diff --git a/src/plotting.jl b/src/plotting.jl index 00c5344b9..4a6057add 100644 --- a/src/plotting.jl +++ b/src/plotting.jl @@ -388,16 +388,16 @@ nyquistplot redata = re_resp[:, i, j] imdata = im_resp[:, i, j] @series begin - ylims := (min(max(-20,minimum(imdata)),-1), max(min(20,maximum(imdata)),1)) - xlims := (min(max(-20,minimum(redata)),-1), max(min(20,maximum(redata)),1)) + ylims --> (min(max(-20,minimum(imdata)),-1), max(min(20,maximum(imdata)),1)) + xlims --> (min(max(-20,minimum(redata)),-1), max(min(20,maximum(redata)),1)) title --> "Nyquist plot from: u($j)" yguide --> "To: y($i)" subplot --> s2i(i,j) label --> "\$G_{$(si)}\$" styledict = getStyleSys(si,length(systems)) linestyle --> styledict[:l] + seriescolor --> styledict[:c] hover --> [Printf.@sprintf("ω = %.3f", w) for w in w] - color --> styledict[:c] (redata, imdata) end # Plot rings @@ -405,15 +405,19 @@ nyquistplot v = range(0,stop=2π,length=100) S,C = sin.(v),cos.(v) @series begin - label := "" + primary := false linestyle := :dash - color := :black + linecolor := :black + seriestype := :path + markershape := :none (C,S) end @series begin - label := "" + primary := false linestyle := :dash - color := :black + linecolor := :black + seriestype := :path + markershape := :none (C .-1,S) end end From 90f82a79f0f424e6ed580c71ce0302c94546b4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20F=C3=A4lt?= Date: Mon, 27 May 2019 15:04:03 +0200 Subject: [PATCH 2/3] cleaned up one example --- example/delayed_lti_system.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/example/delayed_lti_system.jl b/example/delayed_lti_system.jl index 0587d01a4..141fce381 100644 --- a/example/delayed_lti_system.jl +++ b/example/delayed_lti_system.jl @@ -7,13 +7,11 @@ s = tf("s") P = delay(0.2) * ss(1/(s+1)) K = 3; Ti = 0.3; -C = DelayLtiSystem(ss(K*(1 + 1/s))) +C = ss(K*(1 + 1/s)) ω = exp10.(LinRange(-2,2,500)) -L_fr = freqresp(C*P, ω)[:] -plot(real(L_fr), imag(L_fr), xlim=[-2,1], ylim=[-2,2], title="Nyquist curve") +nyquistplot(P*C, ω, xlims=(-2,1), ylims=(-2,2), gaincircles=false) G_yd = feedback(P, C) -plot(ω, abs.(freqresp(G_yd, ω)[:]), xscale=:log, yscale=:log, - title="Transfer function from load disturbances to output.") +bodeplot(G_yd, ω, plotphase=false, title="Transfer function from load disturbances to output.") From 7be24b542d37fb02934f96d43863a7ce67a8fe85 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Tue, 28 May 2019 17:46:19 +0200 Subject: [PATCH 3/3] Add unwrapping to bode phase --- src/plotting.jl | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/plotting.jl b/src/plotting.jl index 4a6057add..e733f6ab2 100644 --- a/src/plotting.jl +++ b/src/plotting.jl @@ -260,7 +260,7 @@ optionally provided. `kwargs` is sent as argument to Plots.plot.""" bodeplot -@recipe function bodeplot(p::Bodeplot; plotphase=true, ylimsphase=()) +@recipe function bodeplot(p::Bodeplot; plotphase=true, ylimsphase=(), unwrap=true) systems, w = _processfreqplot(Val{:bode}(), p.args...) ny, nu = size(systems[1]) s2i(i,j) = LinearIndices((nu,(plotphase ? 2 : 1)*ny))[j,i] @@ -301,9 +301,7 @@ bodeplot color --> styledict[:c] w, magdata end - if !plotphase - continue - end + plotphase || continue @series begin grid --> true @@ -315,7 +313,7 @@ bodeplot label --> "\$G_{$(si)}\$" linestyle --> styledict[:l] color --> styledict[:c] - w, phasedata + w, unwrap ? ControlSystems.unwrap(phasedata.*(pi/180)).*(180/pi) : phasedata end end