@@ -21,17 +21,12 @@ struct SteadyKalmanFilter <: StateEstimator
2121 R̂:: Hermitian{Float64, Matrix{Float64}}
2222 K:: Matrix{Float64}
2323 function SteadyKalmanFilter (model, i_ym, nint_ym, Q̂, R̂)
24- nu, nx, ny = model. nu, model. nx, model. ny
25- nym, nyu = length (i_ym), ny - length (i_ym)
26- Asm, Csm, nint_ym = init_estimstoch (i_ym, nint_ym)
27- nxs = size (Asm,1 )
28- nx̂ = nx + nxs
24+ nym, nyu, nxs, nx̂, As, Cs, nint_ym = init_estimstoch (model, i_ym, nint_ym)
25+ Â, B̂u, Ĉ, B̂d, D̂d = augment_model (model, As, Cs)
2926 validate_kfcov (nym, nx̂, Q̂, R̂)
30- As, _ , Cs = stoch_ym2y (model, i_ym, Asm, [], Csm, [])
31- Â , B̂u, Ĉ, B̂d, D̂d = augment_model (model, As, Cs)
3227 K = try
3328 Q̂_kalman = Matrix (Q̂) # Matrix() required for Julia 1.6
34- R̂_kalman = zeros (eltype (R̂), ny, ny)
29+ R̂_kalman = zeros (eltype (R̂), model . ny, model . ny)
3530 R̂_kalman[i_ym, i_ym] = R̂
3631 kalman (Discrete, Â, Ĉ, Q̂_kalman, R̂_kalman)[:, i_ym]
3732 catch my_error
@@ -44,8 +39,7 @@ struct SteadyKalmanFilter <: StateEstimator
4439 end
4540 end
4641 Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :] # measured outputs ym only
47- i_ym = collect (i_ym)
48- lastu0 = zeros (nu)
42+ lastu0 = zeros (model. nu)
4943 x̂ = [zeros (model. nx); zeros (nxs)]
5044 Q̂ = Hermitian (Q̂, :L )
5145 R̂ = Hermitian (R̂, :L )
@@ -123,7 +117,7 @@ as state feedback. The method [`default_nint`](@ref) computes the default value
123117- Use 1 integrator if the disturbances on the output are typically "step-like"
124118- Use 2 integrators if the disturbances on the output are typically "ramp-like"
125119
126- The function [`init_estimstoch `](@ref) builds the stochastic model from `nint_ym`.
120+ The function [`init_integrators `](@ref) builds the stochastic model from `nint_ym`.
127121
128122!!! tip
129123 Increasing `σQ_int` values increases the integral action "gain".
@@ -198,17 +192,11 @@ struct KalmanFilter <: StateEstimator
198192 Q̂:: Hermitian{Float64, Matrix{Float64}}
199193 R̂:: Hermitian{Float64, Matrix{Float64}}
200194 function KalmanFilter (model, i_ym, nint_ym, P̂0, Q̂, R̂)
201- nu, nx, ny = model. nu, model. nx, model. ny
202- nym, nyu = length (i_ym), ny - length (i_ym)
203- Asm, Csm, nint_ym = init_estimstoch (i_ym, nint_ym)
204- nxs = size (Asm,1 )
205- nx̂ = nx + nxs
195+ nym, nyu, nxs, nx̂, As, Cs, nint_ym = init_estimstoch (model, i_ym, nint_ym)
196+ Â, B̂u, Ĉ, B̂d, D̂d = augment_model (model, As, Cs)
206197 validate_kfcov (nym, nx̂, Q̂, R̂, P̂0)
207- As, _ , Cs = stoch_ym2y (model, i_ym, Asm, [], Csm, [])
208- Â , B̂u, Ĉ, B̂d, D̂d = augment_model (model, As, Cs)
209198 Ĉm, D̂dm = Ĉ[i_ym, :], D̂d[i_ym, :] # measured outputs ym only
210- i_ym = collect (i_ym)
211- lastu0 = zeros (nu)
199+ lastu0 = zeros (model. nu)
212200 x̂ = [zeros (model. nx); zeros (nxs)]
213201 P̂0 = Hermitian (P̂0, :L )
214202 Q̂ = Hermitian (Q̂, :L )
@@ -335,17 +323,11 @@ struct UnscentedKalmanFilter{M<:SimModel} <: StateEstimator
335323 function UnscentedKalmanFilter {M} (
336324 model:: M , i_ym, nint_ym, P̂0, Q̂, R̂, α, β, κ
337325 ) where {M<: SimModel }
338- nu, nx, ny = model. nu, model. nx, model. ny
339- nym, nyu = length (i_ym), ny - length (i_ym)
340- Asm, Csm, nint_ym = init_estimstoch (i_ym, nint_ym)
341- nxs = size (Asm,1 )
342- nx̂ = nx + nxs
343- validate_kfcov (nym, nx̂, Q̂, R̂, P̂0)
344- As, _ , Cs = stoch_ym2y (model, i_ym, Asm, [], Csm, [])
326+ nym, nyu, nxs, nx̂, As, Cs, nint_ym = init_estimstoch (model, i_ym, nint_ym)
345327 augment_model (model, As, Cs) # verify observability for LinModel
328+ validate_kfcov (nym, nx̂, Q̂, R̂, P̂0)
346329 nσ, γ, m̂, Ŝ = init_ukf (nx̂, α, β, κ)
347- i_ym = collect (i_ym)
348- lastu0 = zeros (nu)
330+ lastu0 = zeros (model. nu)
349331 x̂ = [zeros (model. nx); zeros (nxs)]
350332 P̂0 = Hermitian (P̂0, :L )
351333 Q̂ = Hermitian (Q̂, :L )
@@ -555,16 +537,10 @@ struct ExtendedKalmanFilter{M<:SimModel} <: StateEstimator
555537 Q̂:: Hermitian{Float64, Matrix{Float64}}
556538 R̂:: Hermitian{Float64, Matrix{Float64}}
557539 function ExtendedKalmanFilter {M} (model:: M , i_ym, nint_ym, P̂0, Q̂, R̂) where {M<: SimModel }
558- nu, nx, ny = model. nu, model. nx, model. ny
559- nym, nyu = length (i_ym), ny - length (i_ym)
560- Asm, Csm, nint_ym = init_estimstoch (i_ym, nint_ym)
561- nxs = size (Asm,1 )
562- nx̂ = nx + nxs
563- validate_kfcov (nym, nx̂, Q̂, R̂, P̂0)
564- As, _ , Cs, _ = stoch_ym2y (model, i_ym, Asm, [], Csm, [])
540+ nym, nyu, nxs, nx̂, As, Cs, nint_ym = init_estimstoch (model, i_ym, nint_ym)
565541 augment_model (model, As, Cs) # verify observability for LinModel
566- i_ym = collect (i_ym )
567- lastu0 = zeros (nu)
542+ validate_kfcov (nym, nx̂, Q̂, R̂, P̂0 )
543+ lastu0 = zeros (model . nu)
568544 x̂ = [zeros (model. nx); zeros (nxs)]
569545 P̂0 = Hermitian (P̂0, :L )
570546 Q̂ = Hermitian (Q̂, :L )
0 commit comments