@@ -173,7 +173,9 @@ and the covariances are repeated ``N_k`` times:
173173```
174174The estimation horizon ``H_e`` limits the window length:
175175```math
176- N_k = \m in(k+1, H_e)
176+ N_k = \b egin{cases}
177+ k + 1 & k < H_e \\
178+ H_e & k ≥ H_e \e nd{cases}
177179```
178180The vectors ``\m athbf{Ŵ}`` and ``\m athbf{V̂}`` encompass the estimated process noise
179181``\m athbf{ŵ}(k-j)`` and sensor noise ``\m athbf{v̂}(k-j)`` from ``j=N_k-1`` to ``0``. The
@@ -228,12 +230,15 @@ The estimated process and sensor noises are defined as:
228230 \m athbf{v̂}(k)
229231\e nd{bmatrix}
230232```
231- in which ``\m athbf{v̂}(k-j) =
232- \m athbf{y^m}(k-j) - \m athbf{ĥ^m}\b ig(\m athbf{x̂}_k(k-j), \m athbf{d}(k-j)\b ig)`` from ``j =
233- N_k-1`` to ``0``. The augmented model ``\m athbf{f̂}`` with the process noise recursively
234- generates the state estimates ``\m athbf{x̂}_k(k-j+1) =
235- \m athbf{f̂}\b ig(\m athbf{x̂}_k(k-j), \m athbf{u}(k-j), \m athbf{d}(k-j)\b ig) + \m athbf{ŵ}(k-j)``
236- from ``j=N_k-1`` to ``0``.
233+ based on the augmented model ``\m athbf{f̂, ĥ^m}``:
234+ ```math
235+ \b egin{aligned}
236+ \m athbf{x̂}_k(k-j+1) &= \m athbf{f̂}\B ig(\m athbf{x̂}_k(k-j), \m athbf{u}(k-j), \m athbf{d}(k-j)\B ig)
237+ + \m athbf{ŵ}(k-j) \\
238+ \m athbf{v̂}(k-j) &= \m athbf{y^m}(k-j)
239+ - \m athbf{ĥ^m}\B ig(\m athbf{x̂}_k(k-j), \m athbf{d}(k-j)\B ig)
240+ \e nd{aligned}
241+ ```
237242"""
238243function MovingHorizonEstimator (
239244 model:: SM ;
@@ -343,30 +348,34 @@ function relaxV̂(::SimModel{NT}, E) where {NT<:Real}
343348end
344349
345350@doc raw """
346- init_predmat_mhe(model::LinModel{NT}, He, i_ym, Â, B̂u, Ĉ, B̂d, D̂d) -> E, F, G, J, ex̄, fx̄
351+ init_predmat_mhe(
352+ model::LinModel{NT}, He, i_ym, Â, B̂u, Ĉ, B̂d, D̂d
353+ ) -> E, F, G, J, ex̄, fx̄, Ex̂, Fx̂, Gx̂, Jx̂
347354
348355Construct the MHE prediction matrices for [`LinModel`](@ref) `model`.
349356
350357Introducing the vector ``\m athbf{Z} = [\b egin{smallmatrix} \m athbf{x̂_k}(k-H_e+1)
351- \\ \m athbf{Ŵ} \b egin {smallmatrix}]`` with the decision variables, the estimated sensor
358+ \\ \m athbf{Ŵ} \e nd {smallmatrix}]`` with the decision variables, the estimated sensor
352359noises from time ``k-H_e+1`` to ``k`` are computed by:
353360```math
354361\b egin{aligned}
355- \m athbf{V̂} = \m athbf{Y^m - Ŷ^m} &= \m athbf{E Z + G U + J D + Y^m} \\
356- &= \m athbf{E Z + F}
362+ \m athbf{V̂} = \m athbf{Y^m - Ŷ^m} &= \m athbf{E Z + G U + J D + Y^m} \\
363+ &= \m athbf{E Z + F}
357364\e nd{aligned}
358- in which ``U``, ``D`` and ``Y^m`` contains respectively the manipulated inputs and measured
359- disturbances and measured outputs from time ``k-H_e+1`` to ``k``. The method also returns
360- similar matrices but for the estimation error at arrival:
365+ ```
366+ in which ``\m athbf{U, D}`` and ``\m athbf{Y^m}`` contains respectively the manipulated inputs
367+ and measured disturbances and measured outputs from time ``k-H_e+1`` to ``k``. The method
368+ also returns similar matrices but for the estimation error at arrival:
361369```math
362- \m athbf{x̄} = \m athbf{x̂}_{k-He }(k-H_e+1) - \m athbf{x̂}_{k}(k-H_e+1) = \m athbf{e_x̄ Z + f_x̄}
370+ \m athbf{x̄} = \m athbf{x̂}_{k-H_e }(k-H_e+1) - \m athbf{x̂}_{k}(k-H_e+1) = \m athbf{e_x̄ Z + f_x̄}
363371```
364372Lastly, the estimated states from time ``k-H_e+2`` to ``k+1`` are given by the equation:
365373```math
366374\b egin{aligned}
367- \m athbf{X̂} &= \m athbf{E_x̂ Z + G_x̂ U + J_x̂ D} \\
368- &= \m athbf{E_x̂ Z + F_x̂}
375+ \m athbf{X̂} &= \m athbf{E_x̂ Z + G_x̂ U + J_x̂ D} \\
376+ &= \m athbf{E_x̂ Z + F_x̂}
369377\e nd{aligned}
378+ ```
370379All these equations omit the operating points ``\m athbf{u_{op}, y_{op}, d_{op}}``. These
371380matrices are truncated when ``N_k < H_e`` (at the beginning).
372381
@@ -377,7 +386,7 @@ for the sensor noises are computed by (notice the minus signs after the equaliti
377386\b egin{aligned}
378387\m athbf{E} &= - \b egin{bmatrix}
379388 \m athbf{Ĉ^m}\m athbf{A}^{0} & \m athbf{0} & \c dots & \m athbf{0} \\
380- \m athbf{Ĉ^m}\m athbf{Â}^{1} & \m athbf{Ĉ^m} & \c dots & \m athbf{0} \\
389+ \m athbf{Ĉ^m}\m athbf{Â}^{1} & \m athbf{Ĉ^m}\m athbf{A}^{0} & \c dots & \m athbf{0} \\
381390 \v dots & \v dots & \d dots & \v dots \\
382391 \m athbf{Ĉ^m}\m athbf{Â}^{H_e-1} & \m athbf{Ĉ^m}\m athbf{Â}^{H_e-2} & \c dots & \m athbf{0} \e nd{bmatrix} \\
383392\m athbf{G} &= - \b egin{bmatrix}
@@ -649,12 +658,12 @@ for time-varying constraints.
649658 will not re-assign to its default value (defaults are set at construction only).
650659
651660- `estim::MovingHorizonEstimator` : moving horizon estimator to set constraints.
652- - `x̂min = fill(-Inf,nx̂)` : augmented state vector lower bounds ``\m athbf{x̂_{min}}``.
653- - `x̂max = fill(+Inf,nx̂)` : augmented state vector upper bounds ``\m athbf{x̂_{max}}``.
654- - `ŵmin = fill(-Inf,nx̂)` : augmented process noise vector lower bounds ``\m athbf{ŵ_{min}}``.
655- - `ŵmax = fill(+Inf,nx̂)` : augmented process noise vector upper bounds ``\m athbf{ŵ_{max}}``.
656- - `v̂min = fill(-Inf,nym)` : sensor noise vector lower bounds ``\m athbf{v̂_{min}}``.
657- - `v̂max = fill(+Inf,nym)` : sensor noise vector upper bounds ``\m athbf{v̂_{max}}``.
661+ - `x̂min = fill(-Inf,nx̂)` : augmented state lower bounds ``\m athbf{x̂_{min}}``.
662+ - `x̂max = fill(+Inf,nx̂)` : augmented state upper bounds ``\m athbf{x̂_{max}}``.
663+ - `ŵmin = fill(-Inf,nx̂)` : augmented process noise lower bounds ``\m athbf{ŵ_{min}}``.
664+ - `ŵmax = fill(+Inf,nx̂)` : augmented process noise upper bounds ``\m athbf{ŵ_{max}}``.
665+ - `v̂min = fill(-Inf,nym)` : sensor noise lower bounds ``\m athbf{v̂_{min}}``.
666+ - `v̂max = fill(+Inf,nym)` : sensor noise upper bounds ``\m athbf{v̂_{max}}``.
658667- all the keyword arguments above but with a capital letter, e.g. `X̂max` or `V̂max` : for
659668 time-varying constraints (see Extended Help).
660669
@@ -967,7 +976,7 @@ time-varying ``\mathbf{P̄}`` weight (the estimation error covariance at arrival
967976"""
968977function initpred! (estim:: MovingHorizonEstimator , model:: LinModel )
969978 nx̂, nŵ, nym, Nk = estim. nx̂, estim. nx̂, estim. nym, estim. Nk[]
970- nYm, nU, nD, nŴ = nym* Nk, model . nu * Nk, model . nd * Nk, nŵ* Nk
979+ nYm, nŴ = nym* Nk, nŵ* Nk
971980 nZ̃ = nx̂ + nŴ
972981 invQ̂_Nk, invR̂_Nk = @views estim. invQ̂_He[1 : nŴ, 1 : nŴ], estim. invR̂_He[1 : nYm, 1 : nYm]
973982 # --- update F and fx̄ vectors for MHE predictions ---
@@ -1068,10 +1077,12 @@ The method mutates `V̂` and `X̂` vector arguments. The vector `V̂` is the est
10681077noises `V̂` from ``k-N_k+1`` to ``k``. The `X̂` vector is estimated states from ``k-N_k+2`` to
10691078``k+1``.
10701079"""
1071- function predict! (V̂, X̂, estim:: MovingHorizonEstimator , :: LinModel , Z̃)
1072- nX̂, nYm = estim. nx̂* estim. Nk[], estim. nym* estim. Nk[]
1073- V̂[1 : nYm] = estim. Ẽ* Z̃ + estim. F
1074- X̂[1 : nX̂] = estim. con. Ẽx̂* Z̃ + estim. con. Fx̂
1080+ function predict! (
1081+ V̂, X̂, estim:: MovingHorizonEstimator , :: LinModel , Z̃:: Vector{T}
1082+ ) where {T<: Real }
1083+ nX̂, nYm, nZ̃ = estim. nx̂* estim. Nk[], estim. nym* estim. Nk[], estim. nx̂+ estim. nx̂* estim. Nk[]
1084+ V̂[1 : nYm] = @views estim. Ẽ[1 : nYm, 1 : nZ̃]* Z̃[1 : nZ̃] + estim. F[1 : nYm]
1085+ X̂[1 : nX̂] = @views estim. con. Ẽx̂[1 : nX̂, 1 : nZ̃]* Z̃[1 : nZ̃] + estim. con. Fx̂[1 : nX̂]
10751086 return V̂, X̂
10761087end
10771088
0 commit comments