Skip to content

Commit f0563b1

Browse files
committed
added doc for init_estimstoch
1 parent 317abe1 commit f0563b1

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

src/state_estim.jl

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,19 @@ end
7474
7575
Init stochastic model matrices from integrator specifications for state estimation.
7676
77+
The arguments `nint_u` and `nint_ym` specify how many integrators are added to each
78+
manipulated input and measured outputs. The function returns the state-space matrices `As`,
79+
`Cs_u` and `Cs_y` of the stochastic model:
7780
```math
78-
\mathbf{}
81+
\begin{aligned}
82+
\mathbf{x_s}(k+1) &= \mathbf{A_s x_s}(k) + \mathbf{B_s e}(k) \\
83+
\mathbf{y_s_{u}}(k) &= \mathbf{C_s_{u} x_s}(k) \\
84+
\mathbf{y_s_{ym}}(k) &= \mathbf{C_s_{ym} x_s}(k) \\
85+
\end{aligned}
7986
```
80-
81-
The function [`init_integrators`](@ref) builds the state-space matrice of the unmeasured
82-
disturbance models.
87+
where ``\mathbf{e}(k)`` is an unknown zero mean white noise and ``\mathbf{A_s} =
88+
\mathrm{diag}(\mathbf{A_s_{u}, A_s_{ym}})``. The estimations does not use ``\mathbf{B_s}``,
89+
it is thus ignored. The function [`init_integrators`](@ref) builds the state-space matrices.
8390
"""
8491
function init_estimstoch(model, i_ym, nint_u::IntVectorOrInt, nint_ym::IntVectorOrInt)
8592
nu, ny, nym = model.nu, model.ny, length(i_ym)
@@ -120,50 +127,44 @@ function stoch_ym2y(model::SimModel, i_ym, Asm, Bsm, Csm, Dsm)
120127
end
121128

122129
@doc raw"""
123-
init_integrators(nint, nys, varname::String) -> As, Cs, nint
130+
init_integrators(nint, ny, varname::String) -> A, C, nint
124131
125-
Calc state-space matrices `As, Cs` (stochastic part) from integrator specifications `nint`.
132+
Calc `A, C` state-space matrices from integrator specifications `nint`.
126133
127134
This function is used to initialize the stochastic part of the augmented model for the
128135
design of state estimators. The vector `nint` provides how many integrators (in series)
129-
should be incorporated for each stochastic output ``\mathbf{y_s}``:
130-
```math
131-
\begin{aligned}
132-
\mathbf{x_s}(k+1) &= \mathbf{A_s x_s}(k) + \mathbf{B_s e}(k) \\
133-
\mathbf{y_s}(k) &= \mathbf{C_s x_s}(k)
134-
\end{aligned}
135-
```
136-
where ``\mathbf{e}(k)`` is an unknown zero mean white noise. The specific case of one
137-
integrator per stochastic output results in `A_s = I` and `C_s = I`. The estimations does
138-
not use ``\mathbf{B_s}``, it is thus ignored. Note that this function is called twice :
136+
should be incorporated for each output. The argument should have `ny` element, except
137+
for `nint=0` which is an alias for no integrator at all. The specific case of one integrator
138+
per output results in `A = I` and `C = I`. The estimation does not use the `B` matrix, it
139+
is thus ignored. This function is called twice :
139140
140141
1. for the unmeasured disturbances at manipulated inputs ``\mathbf{u}``
141142
2. for the unmeasured disturbances at measured outputs ``\mathbf{y^m}``
142143
"""
143-
function init_integrators(nint::IntVectorOrInt, nys, varname::String)
144+
function init_integrators(nint::IntVectorOrInt, ny, varname::String)
144145
if nint == 0 # alias for no integrator at all
145-
nint = fill(0, nys)
146+
nint = fill(0, ny)
146147
end
147-
if length(nint) nys
148-
error("nint_$(varname) size ($(length(nint))) ≠ n$(varname) ($nys)")
148+
if length(nint) ny
149+
error("nint_$(varname) size ($(length(nint))) ≠ n$(varname) ($ny)")
149150
end
150151
any(nint .< 0) && error("nint_$(varname) values should be ≥ 0")
151-
nxs = sum(nint)
152-
As, Cs = zeros(nxs, nxs), zeros(nys, nxs)
153-
if nxs 0 # construct stochastic model state-space matrices (integrators) :
154-
i_As, i_Cs = 1, 1
155-
for i = 1:nys
152+
nx = sum(nint)
153+
A, C = zeros(nx, nx), zeros(ny, nx)
154+
if nx 0
155+
i_A, i_C = 1, 1
156+
for i = 1:ny
156157
nint_i = nint[i]
157158
if nint_i 0
158-
rows_As = (i_As):(i_As + nint_i - 1)
159-
As[rows_As, rows_As] = Bidiagonal(ones(nint_i), ones(nint_i-1), :L)
160-
Cs[i, i_Cs+nint_i-1] = 1
161-
i_As += nint_i
162-
i_Cs += nint_i
159+
rows_A = (i_A):(i_A + nint_i - 1)
160+
A[rows_A, rows_A] = Bidiagonal(ones(nint_i), ones(nint_i-1), :L)
161+
C[i, i_C+nint_i-1] = 1
162+
i_A += nint_i
163+
i_C += nint_i
163164
end
164165
end
165166
end
166-
return As, Cs, nint
167+
return A, C, nint
167168
end
168169

169170
@doc raw"""

0 commit comments

Comments
 (0)