You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pm_unstable_adjust = n_unstable_poles*360# count the number of unstable poles, and remove 360 for each. Be careful with poles that are counted as integrators
586
598
pm = pm .+ adjust .- pm_unstable_adjust
@@ -595,9 +607,11 @@ function sisomargin(sys::LTISystem, w::AbstractVector{<:Real}; full=false, allMa
_add_eps_negative(w) = [-(eps(eltype(w))); w] # The size of the negative frequency is a tradeoff, too small and the check `if abs(d) > 20` in _findCrossings may fail, but too large and we get an inaccurate interpolation.
614
+
601
615
# Interpolate the values in "list" given the floating point "index" fi
602
616
functioninterpolate(fi, list)
603
617
fif =floor.(Integer, fi)
@@ -613,19 +627,25 @@ function _allPhaseCrossings(w, phase)
613
627
#Calculate numer of times real axis is crossed on negative side
# This can happen when there are both negative and positive frequencies and the Nyquist contour crosses the negative real axis at -infinity
644
+
# This logic is slightly flawed since if there are two frequencies, like -eps, eps that have phase values very close to each other we'll fail to reject the crossing, but to handle this case properly one would have to look at both phase and gain at the same time, which we aren't set-up to do easily at this. We should be able to reject the most common case when the default eps() negative frequency is the only one used
645
+
continue
646
+
end
627
647
#Interpolate to approximate crossing
628
-
t = res[i]/(res[i]-res[i+1])
648
+
t = res[i]/d
629
649
push!(tcross, i+t)
630
650
wt = w[i]+t*(w[i+1]-w[i])
631
651
push!(wcross, wt)
@@ -649,11 +669,14 @@ The delay margin is computed as the phase margin in radians divided by the cross
649
669
functiondelaymargin(G::LTISystem)
650
670
# Phase margin in radians divided by cross-over frequency in rad/s.
651
671
issiso(G) ||error("delaymargin only supports SISO systems")
652
-
m =margin(G,allMargins=true)
653
-
isempty(m[4][1]) &&returnInf
654
-
ϕₘ, i =findmin(m[4][1])
672
+
ωgₘ, gₘ, ωϕₘa, ϕₘa=margin(G,allMargins=true)
673
+
isempty(ϕₘa[1]) &&returnInf
674
+
ϕₘ, i =findmin(sign.(ωϕₘa[1]) .* ϕₘa[1])# flip sign of negative frequency margins
655
675
ϕₘ *= π/180
656
-
ωϕₘ = m[3][1][i]
676
+
ωϕₘ = ωϕₘa[1][i]
677
+
ifnumeric_type(G) <:Real
678
+
ωϕₘ =abs(ωϕₘ)
679
+
end
657
680
dₘ = ϕₘ/ωϕₘ
658
681
ifisdiscrete(G)
659
682
dₘ /= G.Ts # Give delay margin in number of sample times, as matlab does
0 commit comments