Skip to content

Commit

Permalink
Compat with ControlSystems v0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Oct 26, 2020
1 parent 849f2e8 commit 08fc7f5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/SpectralDistances.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ IRLS,
examplemodels


export TimeDomain,
export TimeEvolution,
Continuous,
Discrete,
SortAssignement,
Expand Down
19 changes: 11 additions & 8 deletions src/eigenvalue_manipulations.jl
Original file line number Diff line number Diff line change
@@ -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

Expand Down
27 changes: 14 additions & 13 deletions src/ltimodels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
"""
Expand All @@ -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

Expand Down Expand Up @@ -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))


"""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 08fc7f5

Please sign in to comment.