diff --git a/src/analysis.jl b/src/analysis.jl index 688454371..722ab4186 100644 --- a/src/analysis.jl +++ b/src/analysis.jl @@ -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) diff --git a/src/freqresp.jl b/src/freqresp.jl index 5dd45e692..e3392cf0a 100644 --- a/src/freqresp.jl +++ b/src/freqresp.jl @@ -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` of system `sys` over the frequency vector `w`. """ @@ -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) @@ -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)` diff --git a/src/matrix_comps.jl b/src/matrix_comps.jl index ac5026b65..2609572d1 100644 --- a/src/matrix_comps.jl +++ b/src/matrix_comps.jl @@ -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. diff --git a/test/test_freqresp.jl b/test/test_freqresp.jl index 60ffe9d76..cd20c7d13 100644 --- a/test/test_freqresp.jl +++ b/test/test_freqresp.jl @@ -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)