From 08fc7f5a16b83861dbe166e41cc5fc392938a9c9 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Mon, 26 Oct 2020 07:04:33 +0100 Subject: [PATCH] Compat with ControlSystems v0.8 --- Project.toml | 2 +- src/SpectralDistances.jl | 2 +- src/eigenvalue_manipulations.jl | 19 +++++++++++-------- src/ltimodels.jl | 27 ++++++++++++++------------- 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Project.toml b/Project.toml index c5e6b88..45701c5 100644 --- a/Project.toml +++ b/Project.toml @@ -42,7 +42,7 @@ ZygoteRules = "700de1a5-db45-46bc-99cf-38207098b444" [compat] BackwardsLinalg = "0.1.1" -ControlSystems = "0.5.8, 0.6, 0.8" +ControlSystems = "0.8" DSP = "0.6" Distances = "0.8, 0.9, 0.10" DocStringExtensions = "0.8" diff --git a/src/SpectralDistances.jl b/src/SpectralDistances.jl index a9e04cc..eb5c66c 100644 --- a/src/SpectralDistances.jl +++ b/src/SpectralDistances.jl @@ -134,7 +134,7 @@ IRLS, examplemodels -export TimeDomain, +export TimeEvolution, Continuous, Discrete, SortAssignement, diff --git a/src/eigenvalue_manipulations.jl b/src/eigenvalue_manipulations.jl index 9a9543d..7bb6e26 100644 --- a/src/eigenvalue_manipulations.jl +++ b/src/eigenvalue_manipulations.jl @@ -1,11 +1,14 @@ -"Abstract type that represents a time-domain, either `Discrete` or `Continuous`" -abstract type TimeDomain end -"Continuous time domain" -struct Continuous <: TimeDomain end -"Discrete (sampled) time domain" -struct Discrete <: TimeDomain end - -Base.Broadcast.broadcastable(p::TimeDomain) = Ref(p) +# "Abstract type that represents a time-domain, either `Discrete` or `Continuous`" +# abstract type TimeDomain end +# "Continuous time domain" +# struct Continuous <: TimeDomain end +# "Discrete (sampled) time domain" +# struct Discrete <: TimeDomain end + +import ControlSystems: Continuous, Discrete, TimeEvolution +ControlSystems.Discrete() = Discrete(1) +Base.Broadcast.broadcastable(p::TimeEvolution) = Ref(p) + abstract type AbstractAssignmentMethod end diff --git a/src/ltimodels.jl b/src/ltimodels.jl index 70e16d1..cd3f5d8 100644 --- a/src/ltimodels.jl +++ b/src/ltimodels.jl @@ -165,9 +165,9 @@ ControlSystems.tf(m::AR) = tf(1, Vector(m.ac)) ControlSystems.tf(m::ARMA, ts) = tf(Vector(m.c), Vector(m.a), ts) ControlSystems.tf(m::ARMA) = tf(Vector(m.cc), Vector(m.ac)) -Base.convert(::Type{T}, m::AbstractModel) where T <: TransferFunction{<:ControlSystems.SisoRational} = tf(m) +Base.convert(::Type{T}, m::AbstractModel) where T <: TransferFunction{Continuous, <:ControlSystems.SisoRational} = tf(m) -Base.convert(::Type{T}, m::AbstractModel) where T <: TransferFunction{<:ControlSystems.SisoZpk} = zpk(tf(m)) +Base.convert(::Type{T}, m::AbstractModel) where T <: TransferFunction{Continuous, <:ControlSystems.SisoZpk} = zpk(tf(m)) function ARMA(g::ControlSystems.TransferFunction) ControlSystems.issiso(g) || error("Can only convert SISO systems to ARMA") @@ -204,11 +204,11 @@ PolynomialRoots.roots(::Continuous, m::AR) = m.pc PolynomialRoots.roots(::Discrete, m::ARMA) = m.p PolynomialRoots.roots(::Continuous, m::ARMA) = m.pc PolynomialRoots.roots(::Continuous, r::ContinuousRoots) = r -ControlSystems.pole(d::TimeDomain, m::AbstractModel) = roots(d,m) +ControlSystems.pole(d::TimeEvolution, m::AbstractModel) = roots(d,m) ControlSystems.tzero(::Discrete, m::ARMA) = m.z ControlSystems.tzero(::Continuous, m::ARMA) = m.zc """ - ControlSystems.denvec(::TimeDomain, m::AbstractModel) + ControlSystems.denvec(::TimeEvolution, m::AbstractModel) Get the denominator polynomial vector """ @@ -234,6 +234,7 @@ function Base.getproperty(m::AbstractModel, p::Symbol) p === :nx && return length(m.ac) p === :nu && return 1 p === :ny && return 1 + p === :timeevol && return Continuous() getfield(m,p) end @@ -653,9 +654,9 @@ function abs2residues!(rw, a::AbstractVector, b, r::AbstractVector{CT} = hproots end end -residues(d::TimeDomain, m::AbstractModel) = residues(denvec(d,m), numvec(d,m), roots(d,m)) +residues(d::TimeEvolution, m::AbstractModel) = residues(denvec(d,m), numvec(d,m), roots(d,m)) -abs2residues!(rw, d::TimeDomain, m::AbstractModel) = abs2residues!(rw, denvec(d,m), numvec(d,m), roots(d,m)) +abs2residues!(rw, d::TimeEvolution, m::AbstractModel) = abs2residues!(rw, denvec(d,m), numvec(d,m), roots(d,m)) """ @@ -726,16 +727,16 @@ function spectralenergy(G::LTISystem) end # spectralenergy(a::AbstractArray) = spectralenergy(determine_domain(roots(reverse(a))), a) -function spectralenergy(d::TimeDomain, m::AbstractModel) +function spectralenergy(d::TimeEvolution, m::AbstractModel) spectralenergy(d, denvec(d, m), numvec(d,m)) end """ - spectralenergy(d::TimeDomain, a::AbstractVector, b) + spectralenergy(d::TimeEvolution, a::AbstractVector, b) Calculates the energy in the spectrum associated with transfer function `b/a` """ -function spectralenergy(d::TimeDomain, ai::AbstractVector{T}, b)::T where T +function spectralenergy(d::TimeEvolution, ai::AbstractVector{T}, b)::T where T a = Double64.(ai) ac = a .* (-1).^(length(a)-1:-1:0) a2 = polyconv(ac,a) @@ -772,7 +773,7 @@ function determine_domain(r) Discrete() end -function AutoRoots(d::TimeDomain, r) +function AutoRoots(d::TimeEvolution, r) d isa Discrete ? DiscreteRoots(r) : ContinuousRoots(r) end function AutoRoots(r) @@ -802,16 +803,16 @@ function normalize_energy(r) end """ - scalefactor(::TimeDomain, a, [b,] σ²) + scalefactor(::TimeEvolution, a, [b,] σ²) Returns `k` such that the system with numerator `kb` and denomenator `a` has spectral energy `σ²`. `σ²` should typically be the variance of the corresponding time signal. """ -function scalefactor(d::TimeDomain, a, b, σ²) +function scalefactor(d::TimeEvolution, a, b, σ²) e = spectralenergy(d, a, b) (σ²/(e)) end -function scalefactor(d::TimeDomain, a, σ²) +function scalefactor(d::TimeEvolution, a, σ²) e = spectralenergy(d, a, 1) (σ²/(e)) end