Skip to content

Commit

Permalink
Closes #399
Browse files Browse the repository at this point in the history
  • Loading branch information
baggepinnen committed Jan 28, 2022
1 parent 9455a54 commit 90fa9c3
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/types/TransferFunction.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
struct TransferFunction{TE, S<:SisoTf{T} where T} <: LTISystem{TE}
matrix::Matrix{S}
timeevol::TE
nu::Int
ny::Int
function TransferFunction{TE,S}(matrix::Matrix{S}, timeevol::TE) where {S,TE}
# Validate size of input and output names
ny, nu = size(matrix)
return new{TE,S}(matrix, timeevol, nu, ny)
return new{TE,S}(matrix, timeevol)
end
end
function TransferFunction(matrix::Matrix{S}, timeevol::TE) where {TE<:TimeEvolution, T<:Number, S<:SisoTf{T}}
Expand Down Expand Up @@ -35,6 +33,22 @@ Base.size(G::TransferFunction) = size(G.matrix)
Base.eltype(::Type{S}) where {S<:TransferFunction} = S
Base.zero(G::TransferFunction{TE,S}) where {TE,S} = tf(zeros(numeric_type(S), size(G)), G.timeevol) # can not create a zero of a discrete system from the type alone, the sampletime is not stored.

function Base.getproperty(G::TransferFunction, s::Symbol)
s fieldnames(typeof(G)) && return getfield(G, s)
if s === :ny
return size(G, 1)
elseif s === :nu
return size(G, 2)
elseif s === :Ts
if isdiscrete(G)
return timeevol(G).Ts
else
@warn "Getting time 0.0 for non-discrete systems is deprecated. Check `isdiscrete` before trying to access time."
return 0.0
end
throw(ArgumentError("$(typeof(G)) has no property named $s"))
end
end

function Base.getindex(G::TransferFunction{TE,S}, inds...) where {TE,S<:SisoTf}
if size(inds, 1) != 2
Expand Down

0 comments on commit 90fa9c3

Please sign in to comment.