Skip to content

Commit

Permalink
Conversion methods for AbstractStateSpace instead of statespace (#327)
Browse files Browse the repository at this point in the history
* Make call to minreal in gangoffour optional

Since it so often fails, it's good to have it be optional.

* Conversion methods for AbstractStateSpace instead of statespace

* More conversion routines
  • Loading branch information
baggepinnen committed Sep 27, 2020
1 parent 18a1e0c commit b5d6d75
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/types/conversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function convert(::Type{TransferFunction{TE,S}}, G::TransferFunction) where {TE,
return TransferFunction{TE,eltype(Gnew_matrix)}(Gnew_matrix, TE(G.timeevol))
end

function convert(::Type{S}, sys::StateSpace) where {T, MT, TE, S <:StateSpace{TE,T,MT}}
function convert(::Type{S}, sys::AbstractStateSpace) where {T, MT, TE, S <:StateSpace{TE,T,MT}}
if sys isa S
return sys
else
Expand All @@ -78,7 +78,10 @@ Base.convert(::Type{HeteroStateSpace{TE1,AT,BT,CT,DT}}, s::StateSpace{TE2,T,MT})

Base.convert(::Type{HeteroStateSpace}, s::StateSpace) = HeteroStateSpace(s)

Base.convert(::Type{StateSpace}, s::HeteroStateSpace) = StateSpace(s.A, s.B, s.C, s.D, s.Ts)

function Base.convert(::Type{StateSpace}, G::TransferFunction{TE,<:SisoTf{T0}}) where {TE,T0<:Number}

T = Base.promote_op(/,T0,T0)
convert(StateSpace{TE,T,Matrix{T}}, G)
end
Expand Down Expand Up @@ -243,9 +246,9 @@ end
balance_transform(sys::StateSpace, perm::Bool=false) = balance_transform(sys.A,sys.B,sys.C,perm)


convert(::Type{TransferFunction}, sys::StateSpace{TE}) where TE = convert(TransferFunction{TE,SisoRational}, sys)
convert(::Type{TransferFunction}, sys::AbstractStateSpace{TE}) where TE = convert(TransferFunction{TE,SisoRational}, sys)

function convert(::Type{TransferFunction{TE,SisoRational{T}}}, sys::StateSpace) where {TE,T<:Number}
function convert(::Type{TransferFunction{TE,SisoRational{T}}}, sys::AbstractStateSpace) where {TE,T<:Number}
matrix = Matrix{SisoRational{T}}(undef, size(sys))

A, B, C, D = ssdata(sys)
Expand All @@ -270,8 +273,6 @@ end
function convert(::Type{TransferFunction{TE,SisoZpk{T,TR}}}, sys::StateSpace) where {TE,T<:Number, TR <: Number}
matrix = Matrix{SisoZpk{T,TR}}(undef, size(sys))

A, B, C, D = ssdata(sys)

for i=1:noutputs(sys), j=1:ninputs(sys)
z, p, k = siso_ss_to_zpk(sys, i, j)
matrix[i, j] = SisoZpk{T,TR}(z, p, k)
Expand Down
2 changes: 1 addition & 1 deletion src/types/tf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tf(D::AbstractArray{T}) where T = tf(D, Continuous())

tf(n::Number, args...; kwargs...) = tf([n], args...; kwargs...)

tf(sys::StateSpace) = convert(TransferFunction, sys) # NOTE: Would perhaps like to write TransferFunction{SisoRational}, but couldn't get this to work...
tf(sys::AbstractStateSpace) = convert(TransferFunction, sys) # NOTE: Would perhaps like to write TransferFunction{SisoRational}, but couldn't get this to work...

function tf(G::TransferFunction{TE,<:SisoTf{T}}) where {TE<:TimeEvolution,T<:Number}
convert(TransferFunction{TE,SisoRational{T}}, G)
Expand Down
1 change: 1 addition & 0 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ numeric_type(sys::SisoTf) = numeric_type(typeof(sys))

numeric_type(::Type{TransferFunction{TE,S}}) where {TE,S} = numeric_type(S)
numeric_type(::Type{<:StateSpace{TE,T}}) where {TE,T} = T
numeric_type(::Type{<:HeteroStateSpace{TE,AT}}) where {TE,AT} = eltype(AT)
numeric_type(::Type{<:DelayLtiSystem{T}}) where {T} = T
numeric_type(sys::LTISystem) = numeric_type(typeof(sys))

Expand Down

0 comments on commit b5d6d75

Please sign in to comment.