@@ -70,38 +70,31 @@ function remove_op!(estim::StateEstimator, u, d, ym)
7070end
7171
7272"""
73- init_estimstoch(model, i_ym, nint_ym)
73+ init_estimstoch(model, i_ym, nint_u, nint_ym)
7474
7575Init stochastic model matrices from integrator specifications for state estimation.
7676"""
77- function init_estimstoch (model, i_ym, nint_ym; nint_u= 0 )
78- validate_ym (model, i_ym)
79- nu, nx, ny = model. nu, model. nx, model. ny
80- nym, nyu = length (i_ym), ny - length (i_ym)
77+ function init_estimstoch (model, i_ym, nint_u, nint_ym)
78+ nu, ny, nym = model. nu, model. ny, length (i_ym)
8179 As_u , Cs_u , nint_u = init_integrators (nint_u , nu , " u" )
8280 As_ym, Cs_ym, nint_ym = init_integrators (nint_ym, nym, " ym" )
8381 As_y, _ , Cs_y = stoch_ym2y (model, i_ym, As_ym, [], Cs_ym, [])
8482 nxs_u, nxs_y = size (As_u, 1 ), size (As_y, 1 )
8583 # combines input and output stochastic models:
86- As = [As_u zeros (nxs_u, nxs_y); zeros (nxs_y, nxs_u) As_y]
84+ As = [As_u zeros (nxs_u, nxs_y); zeros (nxs_y, nxs_u) As_y]
8785 Cs_u = [Cs_u zeros (nu, nxs_y)]
8886 Cs_y = [zeros (ny, nxs_u) Cs_y]
89-
90- # Bs = B*Ks (nx × nxs)
91- # Cs_u # nu x nxs_u
92- # B # nx x nu
93- # K_res = B*Cs_u # (nx × nu) * (nu × nxs_u) = (nx × nxs_u)
94-
9587 nxs = nxs_u + nxs_y
96- nx̂ = nx + nxs
97- return nym, nyu, nx̂, nxs, As, Cs_u, Cs_y, nint_u, nint_ym
88+ return As, Cs_u, Cs_y, nxs, nint_u, nint_ym
9889end
9990
10091" Validate the specified measured output indices `i_ym`."
10192function validate_ym (model:: SimModel , i_ym)
10293 if length (unique (i_ym)) ≠ length (i_ym) || maximum (i_ym) > model. ny
10394 error (" Measured output indices i_ym should contains valid and unique indices" )
10495 end
96+ nym, nyu = length (i_ym), model. ny - length (i_ym)
97+ return nym, nyu
10598end
10699
107100" Convert the measured outputs stochastic model `stoch_ym` to all outputs `stoch_y`."
@@ -139,7 +132,7 @@ where ``\mathbf{e}(k)`` is an unknown zero mean white noise. The estimations doe
1391321. for the unmodeled disturbances at measured outputs ``\m athbf{y^m}``
1401332. for the unmodeled disturbances at manipulated inputs ``\m athbf{u}``
141134"""
142- function init_integrators (nint:: Vector{Int} , nys, varname:: String )
135+ function init_integrators (nint:: IntVectorOrInt , nys, varname:: String )
143136 if nint == 0 # alias for no integrator at all
144137 nint = fill (0 , nys)
145138 end
@@ -192,16 +185,17 @@ function augment_model(model::LinModel, As, Cs_u, Cs_y; verify_obsv=true)
192185 D̂d = model. Dd
193186 # observability on Ĉ instead of Ĉm, since it would always return false when nym ≠ ny:
194187 if verify_obsv && ! observability (Â, Ĉ)[:isobservable ]
195- error (" The augmented model is unobservable. You may try to use 0 " *
196- " integrator on model integrating outputs with nint_ym parameter." )
188+ error (" The augmented model is unobservable. You may try to use 0 integrator on " *
189+ " model integrating outputs with nint_ym parameter. Adding integrators at both " *
190+ " inputs (nint_u) and outputs (nint_ym) can also violate observability." )
197191 end
198192 return Â, B̂u, Ĉ, B̂d, D̂d
199193end
200194" No need to augment the model if `model` is not a [`LinModel`](@ref)."
201- augment_model (:: SimModel , _ , _ ) = nothing
195+ augment_model (:: SimModel , _ , _ , _ ) = nothing
202196
203197@doc raw """
204- default_nint(model::LinModel, i_ym=1:model.ny)
198+ default_nint(model::LinModel, i_ym=1:model.ny, nint_u )
205199
206200Get default integrator quantity per measured outputs `nint_ym` for [`LinModel`](@ref).
207201
@@ -221,24 +215,27 @@ julia> nint_ym = default_nint(model)
221215 1
222216```
223217"""
224- function default_nint (model:: LinModel , i_ym:: IntRangeOrVector = 1 : model. ny)
218+ function default_nint (model:: LinModel , i_ym= 1 : model. ny, nint_u= 0 )
219+ validate_ym (model, i_ym)
225220 nint_ym = fill (0 , length (i_ym))
226221 for i in eachindex (i_ym)
227222 nint_ym[i] = 1
228- Asm, Csm = init_integrators (i_ym, nint_ym)
229- As , _ , Cs = stoch_ym2y (model, i_ym, Asm, [], Csm, [])
230- Â , _ , Ĉ = augment_model (model, As, Cs, verify_obsv= false )
223+ As, Cs_u, Cs_y = init_estimstoch (model, i_ym, nint_u, nint_ym)
224+ Â, _ , Ĉ = augment_model (model, As, Cs_u, Cs_y, verify_obsv= false )
231225 # observability on Ĉ instead of Ĉm, since it would always return false when nym ≠ ny
232226 observability (Â, Ĉ)[:isobservable ] || (nint_ym[i] = 0 )
233227 end
234228 return nint_ym
235229end
236230"""
237- default_nint(model::SimModel, i_ym=1:model.ny)
231+ default_nint(model::SimModel, i_ym=1:model.ny, nint_u=0 )
238232
239233One integrator on each measured output by default if `model` is not a [`LinModel`](@ref).
240234"""
241- default_nint (:: SimModel , i_ym:: IntRangeOrVector = 1 : model. ny) = fill (1 , length (i_ym))
235+ function default_nint (model:: SimModel , i_ym= 1 : model. ny, nint_u= 0 )
236+ validate_ym (model, i_ym)
237+ return fill (1 , length (i_ym))
238+ end
242239
243240@doc raw """
244241 f̂(estim::StateEstimator, x̂, u, d)
0 commit comments