Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ the stability region of the complex plane.
function dcgain(sys::LTISystem, ϵ=0)
return iscontinuous(sys) ? evalfr(sys, -ϵ) : evalfr(sys, exp(-ϵ*sys.Ts))
end
dcgain(G::Union{UniformScaling, Number, AbstractMatrix}) = G

"""
markovparam(sys, n)
Expand Down
14 changes: 13 additions & 1 deletion src/freqresp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ function freqresp(sys::LTISystem, w::Real)
evalfr(sys, s)
end

freqresp(G::Union{UniformScaling, AbstractMatrix, Number}, w::Real) = G

"""
sys_fr = freqresp(sys, w)

Evaluate the frequency response of a linear system

`w -> C*((iw*im -A)^-1)*B + D`
`w -> C*((iw*im*I - A)^-1)*B + D`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was more thinking of the w -> ... iw ... in my comment, I assume this should be w->...w...? I added the I since I thought maybe that is where the iw came from?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But yeah, not really related (and not very important) so can fix it some other time.


of system `sys` over the frequency vector `w`.
"""
Expand All @@ -23,6 +25,14 @@ of system `sys` over the frequency vector `w`.
[evalfr(sys[i,j], _freq(w, te))[] for w in w_vec, i in 1:ny, j in 1:nu]
end

@autovec () function freqresp(G::AbstractMatrix, w_vec::AbstractVector{<:Real})
repeat(G, 1, 1, length(w_vec))
end

@autovec () function freqresp(G::Number, w_vec::AbstractVector{<:Real})
fill(G, 1, 1, length(w_vec))
end

_freq(w, ::Continuous) = complex(0, w)
_freq(w, te::Discrete) = cis(w*te.Ts)

Expand Down Expand Up @@ -121,6 +131,8 @@ function evalfr(G::TransferFunction{<:TimeEvolution,<:SisoTf}, s::Number)
map(m -> evalfr(m,s), G.matrix)
end

evalfr(G::Union{UniformScaling, AbstractMatrix, Number}, s) = G

"""
`F(s)`, `F(omega, true)`, `F(z, false)`

Expand Down
2 changes: 1 addition & 1 deletion src/matrix_comps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ end
Return the observer_predictor system
x̂' = (A - KC)x̂ + (B-KD)u + Ky
ŷ = Cx + Du
with the input equation [B K] * [u; y]
with the input equation [B-KD K] * [u; y]

If covariance matrices `R1, R2` are given, the kalman gain `K` is calculaded.

Expand Down
7 changes: 7 additions & 0 deletions test/test_freqresp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ resp1 = ones(ComplexF64, length(w), 1, 1)
@test freqresp(G1, w) == resp1
@test freqresp(H1, w) == resp1

for G in [2, 2I, 2I(2), randn(2,2)]
@test dcgain(G) == G
!(G isa UniformScaling) && @test freqresp(G, [1,2]) == cat(G,G, dims=3) # I does not have size
@test freqresp(G, 1) == G
@test evalfr(G, 1im) == G
end

## First order system

sys2 = ss(-1, 1, 1, 1)
Expand Down