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
8 changes: 6 additions & 2 deletions src/model_augmentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,17 @@ end

- `Bd`: The disturbance input matrix.
"""
function add_resonant_disturbance(sys::AbstractStateSpace, ω, ζ, Bd::AbstractArray)
function add_resonant_disturbance(sys::AbstractStateSpace, ω, ζ, Bd::AbstractArray; measurement=false)
Ad = [-ζ -float(ω); ω -ζ]
if isdiscrete(sys)
Ad .*= sys.Ts
Ad = exp(Ad)
end
add_disturbance(sys, Ad, [Bd zeros(sys.nx)])
if measurement
add_measurement_disturbance(sys, Ad, Bd)
else
add_disturbance(sys, Ad, [Bd zeros(sys.nx)])
end
end

"""
Expand Down
9 changes: 9 additions & 0 deletions test/test_augmentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ Gd = add_resonant_disturbance(G, 1, 0, 1)
allapproxin(a, b) = all(any(a .≈ b', dims=2))
@test allapproxin(poles(Gd), [eigvals(exp([0 -1; 1 0]*0.1)); exp(-1*0.1)])

# Discrete time, input matrix, and measurement disturbance
G = c2d(ss(tf(1.0, [1, 1])), 0.1)
Gd = add_resonant_disturbance(G, 1, 0, [1.0 0.0], measurement=true)
@test sminreal(Gd) == G
@test Gd.nx == 3
allapproxin(a, b) = all(any(a .≈ b', dims=2))
@test allapproxin(poles(Gd), [eigvals(exp([0 -1; 1 0]*0.1)); exp(-1*0.1)])
@test size(Gd.C, 2) == 3 # C matrix extended with disturbance states


##

Expand Down
Loading