├── firstpages
├── preface.tex
└── copyright.tex
├── lectures
├── template.tex
└── 2022_04_27.tex
├── img
├── freq-emphasis.png
└── README.md
├── Makefile
├── README.md
├── lectures_AY2020
├── template.tex
├── 2020-04-23.tex
├── 2020-04-30.tex
├── 2020-05-18.tex
├── 2020-05-19.tex
├── 2020-05-12.tex
├── 2020-04-22.tex
├── 2020-06-03.tex
├── 2020-05-25.tex
├── 2020-04-21.tex
├── 2020-04-16.tex
├── 2020-05-05.tex
├── 2020-05-04.tex
├── 2020-05-27.tex
├── 2020-05-07.tex
└── 2020-04-27.tex
├── .gitignore
├── main.tex
└── style.tex
/firstpages/preface.tex:
--------------------------------------------------------------------------------
1 | %!TEX root = ../main.tex
2 |
--------------------------------------------------------------------------------
/lectures/template.tex:
--------------------------------------------------------------------------------
1 | %!TEX root = ../main.tex
2 |
--------------------------------------------------------------------------------
/img/freq-emphasis.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polimi-cheatsheet/MIDA2/HEAD/img/freq-emphasis.png
--------------------------------------------------------------------------------
/img/README.md:
--------------------------------------------------------------------------------
1 | TODO: delete this folder when this single image will be replaced by a tikz figure.
2 |
3 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | PRINCIPALE = main
2 | PRINCIPALE_TEX = $(PRINCIPALE).tex
3 | PRINCIPALE_PDF = $(PRINCIPALE).pdf
4 | FILE_CLEAN = *.aux *.log *.out *.xdv *.toc *.fls *.fls *.fdb_latexmk *.synctex.gz *.synctex\(busy\)
5 | FILE_DISTCLEAN = $(PRINCIPALE_PDF)
6 |
7 | .PHONY: distclean clean pdf
8 |
9 | pdf: $(PRINCIPALE_PDF)
10 |
11 | $(PRINCIPALE_PDF): $(PRINCIPALE_TEX) *.tex
12 | git show -s --format=%H > commit_hash.part
13 | latexmk -pdf -jobname=$(PRINCIPALE) $(PRINCIPALE_TEX)
14 | rm -f commit_hash.part
15 |
16 | clean:
17 | rm -f $(FILE_CLEAN) commit_hash.part
18 |
19 | distclean : clean
20 | rm -f $(FILE_DISTCLEAN)
--------------------------------------------------------------------------------
/firstpages/copyright.tex:
--------------------------------------------------------------------------------
1 | %!TEX root = ../main.tex
2 |
3 | \vspace*{\stretch{12}}
4 |
5 | \textcopyright \ The authors. Some rights reserved.
6 |
7 | This work is licensed under CC BY-NC-SA 4.0.\\
8 | \url{http://creativecommons.org/licenses/by-nc-sa/4.0/}
9 |
10 | In particular, without the authors' permission, it is forbidden to make digital or printed copies to sell them.
11 |
12 | The \latex source code is available at\\
13 | \url{https://github.com/polimi-cheatsheet/MIDA2}
14 |
15 | \vspace*{\stretch{2}}
16 |
17 | \textsc{Document created on \today}
18 | \IfFileExists{./commit_hash.part}{\\\textsc{Version} \texttt{\input{commit_hash.part}}}{}
19 |
20 | \vspace*{\stretch{2}}
21 |
22 | \textsc{Developed by:}\\
23 | \textsc{Edoardo Morassutto}\\
24 | \textsc{Marco Donadoni}\\
25 | \textsc{Cosimo Russo}\\
26 | \textsc{Federico Cazzola}\\
27 | \textsc{Andrea Bosisio} - \texttt{andrea2.bosisio@mail.polimi.it}
28 |
29 | \vspace*{\stretch{5}}
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [![CC BY-NC-SA 4.0][cc-by-nc-sa-shield]][cc-by-nc-sa]
2 |
3 | > **WHAT ABOUT MIDA1?** Here you can find the [MIDA1 repository](https://github.com/teobucci/mida).
4 |
5 | # Model Identification and Data Analysis - Part 2
6 |
7 | Lecture notes of the [Model Identification and Data Analysis - Part 2 (051589)](https://www11.ceda.polimi.it/schedaincarico/schedaincarico/controller/scheda_pubblica/SchedaPublic.do?&evn_default=evento&c_classe=765794&polij_device_category=DESKTOP&__pj0=0&__pj1=42d68cc1050be0569561dabe2a5df40b) course at Politecnico di Milano, A.Y. 2021-2022.
8 |
9 | ## Project structure
10 |
11 | The main file to be compiled is `main.tex`.
12 | The others source files have been imported with `\input{file}` and they shouldn't be directly compiled. However, at the top of each source file there is the command `%!TEX root = ../main.tex`, thus, one can also compile the project by compiling whatever source `.tex` file.
13 |
14 | ## Updates and Errors
15 |
16 | This is the result of the reviews and updates of class notes taken during A.Y. 2019-2020 and could contains errors and inaccuracies. Besides, no lecturer has reviewed the contents of this files. Therefore, use it at will and with responsibility.
17 | If you want to adjust or modify the document you can do that via a Pull Request or you can contact via email.
18 |
19 | ## Autors
20 |
21 | - Edoardo Morassutto ([@edomora97](https://github.com/edomora97))
edoardo.morassutto@gmail.com
22 | - Andrea Bosisio ([@andreabosisio](https://github.com/andreabosisio))
andrea2.bosisio@mail.polimi.it
23 |
24 | ### Other credits
25 |
26 | The style of this LaTeX document is taken from the [MIDA1 repository](https://github.com/teobucci/mida).
27 |
28 | ## License
29 |
30 | This work is licensed under [Creative Commons BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/). In particular, without the authors' permission, it is forbidden to make digital or printed copies to sell them.
31 |
32 | [cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg
33 | [cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/
34 |
35 |
--------------------------------------------------------------------------------
/lectures_AY2020/template.tex:
--------------------------------------------------------------------------------
1 | \chapter{Template}
2 | \section{Table}
3 |
4 | \begin{table}[htp]
5 | \centering
6 | \begin{tabular}{r|l|p{10cm}}
7 | Right & Left & Longlonglonglonglonglonglonglong longlonglonglonglonglonglonglonglonglonglonglonglong longlonglonglonglonglong \\
8 | Right & Left & Longlonglonglonglonglonglong
9 | longlonglonglonglonglonglonglong
10 | longlonglonglong
11 | longlonglonglonglonglonglonglong
12 | \end{tabular}
13 | \caption{This is a caption}
14 | \label{tab:trans-sym}
15 | \end{table}
16 |
17 | \section{List}
18 | This is a List:
19 | \begin{itemize}
20 | \item \textbf{Bullet 1}: Bullet 1 is bullet 1.
21 | \item \textbf{Bullet 2}: Bullet 2 is bullet 2.
22 | \end{itemize}
23 |
24 | \section{Definition}
25 | \begin{definition}\label{def:def1}
26 | \textbf{DEFINITION NAME}: This is a definition.
27 | \end{definition}
28 |
29 | % avoid bad break
30 | \vspace{5cm}
31 |
32 | \section{Theorem}
33 | \begin{theo}[THEOREM NAME]{theo:theo1}
34 | This is a theorm. Below are equations.
35 | \begin{align}\label{eq:multi-equations}
36 | \psi(\bvec{a}) &= A\cdot \bvec{a} + \bvec{t}.\\
37 | R_x &= \begin{bmatrix}
38 | 0 & \cos(\theta) & -\sin(\theta)\\
39 | 0 & \sin(\theta) & \cos(\theta)\\
40 | 1 & 0 & 0
41 | \end{bmatrix},
42 | R_y = \begin{bmatrix}
43 | \cos(\theta) & 0 & -\sin(\theta)\\
44 | \sin(\theta) & 0 & \cos(\theta)\\
45 | 0 & 1 & 0
46 | \end{bmatrix},
47 | R_z = \begin{bmatrix}
48 | \cos(\theta) & -\sin(\theta) & 0\\
49 | \sin(\theta) & \cos(\theta) & 0 \\
50 | 0 & 0 & 1
51 | \end{bmatrix}
52 | \end{align}
53 | \end{theo}
54 |
55 | \begin{lem}[LEMMA NAME]{lem:leml}
56 | This is a lemma
57 | \end{lem}
58 |
59 | \begin{prf}[LEMMA NAME]{prf:leml}
60 | This is a proof.
61 | \end{prf}
62 |
63 | \section{Tikz Pictures}
64 | \begin{figure}[htp]
65 | \centering
66 | \begin{tikzpicture}[scale=0.6]
67 | \draw[->] (0,-1)--(0,1.5)node[above] {$s$};
68 | \draw[->] (-0.8,0.6) to[bend right] (0.8,0.6);
69 | \draw[->] (0.9, 0.8)--(0.9, 1.2) node[right] {$\omega$};
70 | \filldraw[dashed] (0,-0.2)--(0.9, -0.3) circle (1pt) node [right] {$q$};
71 | \draw[->] (0.8, -0.9)--(1.2, -0.8) node[right] {$v$};
72 | \end{tikzpicture}
73 | \caption{This is a caption. }
74 | \label{fig:rotation}
75 | \end{figure}
76 |
77 |
78 |
79 |
80 |
81 | \curinstructor{Ins Tructor1}
82 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 |
3 | ## Core latex/pdflatex auxiliary files:
4 | *.aux
5 | *.lof
6 | *.log
7 | *.lot
8 | *.fls
9 | *.out
10 | *.toc
11 | *.fmt
12 | *.fot
13 | *.cb
14 | *.cb2
15 | .*.lb
16 |
17 | ## Intermediate documents:
18 | *.dvi
19 | *.xdv
20 | *-converted-to.*
21 | # these rules might exclude image files for figures etc.
22 | # *.ps
23 | # *.eps
24 | # *.pdf
25 |
26 | ## Generated if empty string is given at "Please type another file name for output:"
27 | .pdf
28 |
29 | ## Bibliography auxiliary files (bibtex/biblatex/biber):
30 | *.bbl
31 | *.bcf
32 | *.blg
33 | *-blx.aux
34 | *-blx.bib
35 | *.run.xml
36 |
37 | ## Build tool auxiliary files:
38 | *.fdb_latexmk
39 | *.synctex
40 | *.synctex(busy)
41 | *.synctex.gz
42 | *.synctex.gz(busy)
43 | *.pdfsync
44 |
45 | ## Build tool directories for auxiliary files
46 | # latexrun
47 | latex.out/
48 |
49 | ## Auxiliary and intermediate files from other packages:
50 | # algorithms
51 | *.alg
52 | *.loa
53 |
54 | # achemso
55 | acs-*.bib
56 |
57 | # amsthm
58 | *.thm
59 |
60 | # beamer
61 | *.nav
62 | *.pre
63 | *.snm
64 | *.vrb
65 |
66 | # changes
67 | *.soc
68 |
69 | # comment
70 | *.cut
71 |
72 | # cprotect
73 | *.cpt
74 |
75 | # elsarticle (documentclass of Elsevier journals)
76 | *.spl
77 |
78 | # endnotes
79 | *.ent
80 |
81 | # fixme
82 | *.lox
83 |
84 | # feynmf/feynmp
85 | *.mf
86 | *.mp
87 | *.t[1-9]
88 | *.t[1-9][0-9]
89 | *.tfm
90 |
91 | #(r)(e)ledmac/(r)(e)ledpar
92 | *.end
93 | *.?end
94 | *.[1-9]
95 | *.[1-9][0-9]
96 | *.[1-9][0-9][0-9]
97 | *.[1-9]R
98 | *.[1-9][0-9]R
99 | *.[1-9][0-9][0-9]R
100 | *.eledsec[1-9]
101 | *.eledsec[1-9]R
102 | *.eledsec[1-9][0-9]
103 | *.eledsec[1-9][0-9]R
104 | *.eledsec[1-9][0-9][0-9]
105 | *.eledsec[1-9][0-9][0-9]R
106 |
107 | # glossaries
108 | *.acn
109 | *.acr
110 | *.glg
111 | *.glo
112 | *.gls
113 | *.glsdefs
114 | *.lzo
115 | *.lzs
116 |
117 | # uncomment this for glossaries-extra (will ignore makeindex's style files!)
118 | # *.ist
119 |
120 | # gnuplottex
121 | *-gnuplottex-*
122 |
123 | # gregoriotex
124 | *.gaux
125 | *.gtex
126 |
127 | # htlatex
128 | *.4ct
129 | *.4tc
130 | *.idv
131 | *.lg
132 | *.trc
133 | *.xref
134 |
135 | # hyperref
136 | *.brf
137 |
138 | # knitr
139 | *-concordance.tex
140 | # TODO Comment the next line if you want to keep your tikz graphics files
141 | *.tikz
142 | *-tikzDictionary
143 |
144 | # listings
145 | *.lol
146 |
147 | # luatexja-ruby
148 | *.ltjruby
149 |
150 | # makeidx
151 | *.idx
152 | *.ilg
153 | *.ind
154 |
155 | # minitoc
156 | *.maf
157 | *.mlf
158 | *.mlt
159 | *.mtc[0-9]*
160 | *.slf[0-9]*
161 | *.slt[0-9]*
162 | *.stc[0-9]*
163 |
164 | # minted
165 | _minted*
166 | *.pyg
167 |
168 | # morewrites
169 | *.mw
170 |
171 | # nomencl
172 | *.nlg
173 | *.nlo
174 | *.nls
175 |
176 | # pax
177 | *.pax
178 |
179 | # pdfpcnotes
180 | *.pdfpc
181 |
182 | # sagetex
183 | *.sagetex.sage
184 | *.sagetex.py
185 | *.sagetex.scmd
186 |
187 | # scrwfile
188 | *.wrt
189 |
190 | # sympy
191 | *.sout
192 | *.sympy
193 | sympy-plots-for-*.tex/
194 |
195 | # pdfcomment
196 | *.upa
197 | *.upb
198 |
199 | # pythontex
200 | *.pytxcode
201 | pythontex-files-*/
202 |
203 | # tcolorbox
204 | *.listing
205 |
206 | # thmtools
207 | *.loe
208 |
209 | # TikZ & PGF
210 | *.dpth
211 | *.md5
212 | *.auxlock
213 |
214 | # todonotes
215 | *.tdo
216 |
217 | # vhistory
218 | *.hst
219 | *.ver
220 |
221 | # easy-todo
222 | *.lod
223 |
224 | # xcolor
225 | *.xcp
226 |
227 | # xmpincl
228 | *.xmpi
229 |
230 | # xindy
231 | *.xdy
232 |
233 | # xypic precompiled matrices and outlines
234 | *.xyc
235 | *.xyd
236 |
237 | # endfloat
238 | *.ttt
239 | *.fff
240 |
241 | # Latexian
242 | TSWLatexianTemp*
243 |
244 | ## Editors:
245 | # WinEdt
246 | *.bak
247 | *.sav
248 |
249 | # Texpad
250 | .texpadtmp
251 |
252 | # LyX
253 | *.lyx~
254 |
255 | # Kile
256 | *.backup
257 |
258 | # gummi
259 | .*.swp
260 |
261 | # KBibTeX
262 | *~[0-9]*
263 |
264 | # TeXnicCenter
265 | *.tps
266 |
267 | # auto folder when using emacs and auctex
268 | ./auto/*
269 | *.el
270 |
271 | # expex forward references with \gathertags
272 | *-tags.tex
273 |
274 | # standalone packages
275 | *.sta
276 |
277 | # Makeindex log files
278 | *.lpz
279 | main.pdf
280 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-04-23.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{23/04/2020}
2 |
3 | \begin{exercise}[similar to an exam exercise]
4 | Consider the following S.S. model
5 | \[
6 | F = \begin{bmatrix}
7 | \frac{1}{2} & 0 \\
8 | 1 & \frac{1}{4}
9 | \end{bmatrix}
10 | \qquad
11 | G = \begin{bmatrix}
12 | 1 \\ 0
13 | \end{bmatrix}
14 | \qquad
15 | H = \begin{bmatrix}
16 | 0 & 1
17 | \end{bmatrix}
18 | \qquad
19 | D = 0
20 | \]
21 | The system has grade $n=2$ and is single-input single-output.
22 |
23 | \paragraph{Question} Write the time domain equations of the system in the state space representation.
24 | \begin{align*}
25 | x_1(t+1) &= \frac{1}{2}x_1(t) + u(t) \\
26 | x_2(t+1) &= x_1(t) + \frac{1}{4}x_2(t) \\
27 | y(t) &= x_2(t)
28 | \end{align*}
29 |
30 | \paragraph{Question} Write the block scheme of the S.S. representation of the system.
31 | \begin{figure}[H]
32 | \centering
33 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
34 | \node [int] (in1) {$1$};
35 | \node [left of=in1] (u) {$u(t)$};
36 | \node [sum, right of=in1, node distance=1.5cm] (sum1) {};
37 | \node [int, right of=sum1, node distance=2.5cm] (n1) {$z^{-1}$};
38 | \node [int, below of=n1, node distance=1.5cm] (fb1) {$\frac{1}{2}$};
39 | \node [coordinate, right of=n1] (exit1) {};
40 | \node [int, below of=fb1, node distance=1.5cm] (in2) {$1$};
41 | \node [int, below of=in2, node distance=1.5cm] (n2) {$z^{-1}$};
42 | \node [sum, left of=n2, node distance=2.5cm] (sum2) {};
43 | \node [coordinate, right of=n2] (exit2) {};
44 | \node [int, below of=n2, node distance=1.5cm] (fb2) {$\frac{1}{4}$};
45 | \node [int, right of=exit2, node distance=1.5cm] (out2) {$1$};
46 | \node [right of=out2, node distance=1.5cm] (y) {$y(t)$};
47 |
48 | \draw[->] (u) -- (in1);
49 | \draw[->] (in1) -- (sum1);
50 | \draw[->] (sum1) edge node {$x_1(t+1)$} (n1);
51 | \draw (n1) edge node {$x_1(t)$} (exit1);
52 | \draw[->] (exit1) |- (fb1);
53 | \draw[->] (exit1) |- (in2);
54 | \draw[->] (fb1) -| (sum1);
55 | \draw[->] (in2) -| (sum2);
56 | \draw[->] (sum2) edge node {$x_2(t+1)$} (n2);
57 | \draw (n2) edge node {$x_2(t)$} (exit2);
58 | \draw[->] (exit2) |- (fb2);
59 | \draw[->] (fb2) -| (sum2);
60 | \draw[->] (exit2) -- (out2);
61 | \draw[->] (out2) -- (y);
62 | \end{tikzpicture}
63 | \end{figure}
64 |
65 |
66 | By visual inspection the system is fully observable and fully controllable.
67 |
68 | \paragraph{Question} Make a formal verification that the system is fully observable and controllable.
69 | \[
70 | O = \begin{bmatrix}
71 | H \\ HF
72 | \end{bmatrix} = \begin{bmatrix}
73 | 0 & 1 \\
74 | 1 & \frac{1}{4}
75 | \end{bmatrix}
76 | \qquad
77 | \rank O = 2 = n
78 | \]
79 | \[
80 | R = \begin{bmatrix}
81 | G & FG
82 | \end{bmatrix} = \begin{bmatrix}
83 | 1 & \frac{1}{2} \\
84 | 0 & 1
85 | \end{bmatrix}
86 | \qquad
87 | \rank R = 2 = n
88 | \]
89 | The extended ($n+1$) $O_3$ and $R_3$:
90 | \[
91 | O_3 = \begin{bmatrix}
92 | H \\ HF \\ HF^2
93 | \end{bmatrix} = \begin{bmatrix}
94 | 0 & 1 \\
95 | 1 & \frac{1}{4} \\
96 | \frac{3}{4} & \frac{1}{16}
97 | \end{bmatrix}
98 | \]
99 | \[
100 | R_3 = \begin{bmatrix}
101 | G & FG & F^2G
102 | \end{bmatrix} = \begin{bmatrix}
103 | 1 & \frac{1}{2} & \frac{1}{4} \\
104 | 0 & 1 & \frac{3}{4} \\
105 | \end{bmatrix}
106 | \]
107 |
108 | \paragraph{Question} Compute the transfer function representation.
109 |
110 | First method: direct manipulation of S.S. equations
111 | \begin{align*}
112 | x_1(t+1) &= \frac{1}{2}x_1(t) + u(t) \\
113 | x_2(t+1) &= x_1(t) + \frac{1}{4}x_2(t) \\
114 | y(t) &= x_2(t)
115 | \end{align*}
116 | \begin{align*}
117 | zx_1(t+1) - \frac{1}{2}x_1(t) = u(t) \qquad &\implies \qquad x_1(t) = \frac{1}{z-\frac{1}{2}}u(t) \\
118 | zx_2(t) - \frac{1}{4}x_2(t) = \frac{1}{z-\frac{1}{2}}u(t) \qquad &\implies \qquad x_2(t) = \frac{1}{(z-\frac{1}{4})(z-\frac{1}{2})}u(t) \\
119 | y(t) = \frac{1}{(z-\frac{1}{4})(z-\frac{1}{2})}u(t)
120 | \end{align*}
121 | \[
122 | W(z) = \frac{1}{(z-\frac{1}{4})(z-\frac{1}{2})}
123 | \]
124 |
125 | There are 2 poles: $z=\frac{1}{4}$ and $z=\frac{1}{2}$. Since the system is fully observable and controllable the poles correspond to the eigenvalues of $F$.
126 |
127 | Second method: use the formula
128 | \[
129 | W(z) = H(zI-F)^{-1}G = \begin{bmatrix}
130 | 0 & 1
131 | \end{bmatrix} \begin{bmatrix}
132 | z-\frac{1}{2} & 0 \\
133 | -1 & z-\frac{1}{4}
134 | \end{bmatrix}^{-1} \begin{bmatrix}
135 | 1 \\ 0
136 | \end{bmatrix} = \frac{1}{(z-\frac{1}{4})(z-\frac{1}{2})}
137 | \]
138 |
139 | \paragraph{Question} Write I/O time-domain representation
140 |
141 | \[
142 | y(t) = \frac{1}{z^2-\frac{3}{4}z+\frac{1}{8}}u(t) = \frac{z^{-2}}{1-\frac{3}{4}z^{-1}+\frac{1}{8}z^{-2}}u(t) = \frac{3}{4}y(t-1) - \frac{1}{8}y(t-2) + u(t-2)
143 | \]
144 |
145 | \paragraph{Question} Compute the first 6 values (including $\omega(0)$) of I.R.
146 |
147 | We decide to compute from the T.F. $\frac{z^{-2}}{1-\frac{3}{4}z^{-1}+\frac{1}{8}z^{-2}}$.
148 | Performing the long division of $W(z)$ the result is $z^{-2}+\frac{3}{4}z^{-3}+\frac{7}{16}z^{-4}+\frac{15}{64}z^{-5}$.
149 |
150 | \begin{align*}
151 | \omega(0) &= 0 &
152 | \omega(1) &= 0 &
153 | \omega(2) &= 1 \\
154 | \omega(3) &= \frac{3}{4} &
155 | \omega(4) &= \frac{7}{16} &
156 | \omega(5) &= \frac{15}{64}
157 | \end{align*}
158 |
159 | \paragraph{Question} Build the Hankel matrix and stop when the rank is not full.
160 |
161 | \[
162 | H_1 = \begin{bmatrix}
163 | 0
164 | \end{bmatrix}
165 | \qquad
166 | H_2 = \begin{bmatrix}
167 | 0 & 1 \\
168 | 1 & \frac{3}{4}
169 | \end{bmatrix}
170 | \qquad
171 | H_3 = \begin{bmatrix}
172 | 0 & 1 & \frac{3}{4} \\
173 | 1 & \frac{3}{4} & \frac{7}{16} \\
174 | \frac{3}{4} & \frac{7}{16} & \frac{15}{64}
175 | \end{bmatrix}
176 | \qquad
177 | \rank H_3 = 2
178 | \]
179 | $H_3$ is not full rank so the order of the system is 2. Notice that $O_3R_3 = H_3$.
180 | \end{exercise}
181 |
182 | \chapter{Parametric black-box system identification of I/O system using a frequency domain approach}
183 |
184 | So far we have seen:
185 | \begin{itemize}
186 | \item In MIDA1 parametric black-box identification of I/O systems (ARMAX) and time series (ARMA)
187 | \item In Chapter 1 non-parametric black-box identification of I/O systems (4SID)
188 | \end{itemize}
189 |
190 | The frequency domain approach is a black-box and parametric, and it's very used in practice since it's very robust and reliable.
191 |
192 | Since it's parametric it uses the 4 usual steps:
193 | \begin{enumerate}
194 | \item Experiment design and data pre-processing. A special type of experiment and data pre-processing is needed.
195 | \item Selection of parametric model class ($\mathcal{M}(\theta)$)
196 | \item Definition of a performance index ($J(\theta)$). A new special performance index is needed.
197 | \item Optimization ($\hat{\theta} = \argmin_\theta J(\theta)$)
198 | \end{enumerate}
199 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-04-30.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{30/04/2020}
2 |
3 | \begin{rem}[Emphasis on special frequency range]
4 | In some cases, between $\omega_1$ and $\omega_H$, we want to be more accurate in system identification in some frequency regions (typically around cut-off-frequency, around resonances).
5 |
6 | We can use different weights for different frequencies.
7 |
8 | \begin{figure}[H]
9 | \centering
10 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
11 | \begin{axis}[axis lines=none,ymax=2.5]
12 | \addplot[color=blue,mark=square]
13 | coordinates {
14 | (0,1)(1,1)(2,1)(3,1.2)(4,2)(5,1.2)(6,1)(7,1)(8,1)
15 | };
16 | \end{axis}
17 |
18 | \draw[->] (-0.5,0) -- (7,0) node[right] {$\omega$};
19 | \draw[->] (0.5,-0.5) -- (0.5,5) node[left] {$\lambda_i$};
20 | \node at (0.1,0.5) {$1$};
21 | \draw (6.3,0.1) -- (6.3,-0.1) node [below] {$\omega_H$};
22 | \draw (1.3,0.1) -- (1.3,-0.1) node [below] {$\omega_1$};
23 | \draw (2,0.1) -- (2,-0.1) node [below] {$\omega_2$};
24 | \end{tikzpicture}
25 | \end{figure}
26 |
27 | The performance index can be redefined:
28 | \[
29 | \tilde{J}_H (\theta) = \frac{1}{H} \sum_{i=1}^H \lambda_i \left(W(e^{j\omega_i};\theta) - \frac{\hat{B}_i}{A_i}e^{j\hat{\phi_i}}\right)^2
30 | \]
31 |
32 | Another \emph{trick}: more dense $\omega_i$ spacing in the frequency region of special interest (not really used).
33 | \end{rem}
34 |
35 | \begin{rem}[Single experiment]
36 | Sometimes the set of $H$ independent single-sinusoid experiments can be replaced by a long single ``sine-sweep'' experiment.
37 |
38 | \begin{figure}[H]
39 | \centering
40 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
41 | \draw[->] (-0.5,0) -- (5,0) node[right] {$t$};
42 | \draw[->] (0,-1) -- (0,2) node[left] {$u(t)$};
43 | \draw[domain=0:4.5,samples=100,smooth,variable=\x,red] plot ({\x},{cos(\x*180/3.14*(\x^1.7+5))*e^(-\x/2.5)});
44 | \end{tikzpicture}
45 | \caption*{Slowing-varying sinusoid with increasing frequency and decreasing amplitude.}
46 | \end{figure}
47 |
48 | We can cut a-posteriori the signal into $H$ pieces, and then back to the standard procedure.
49 | Or directly compute an estimation of $\hat{W}(e^{j\omega})$ as a ration of the output and input spectra.
50 |
51 | \[
52 | \hat{W}(e^{j\omega}) = \frac{\hat{\Gamma}_y(e^{j\omega})}{\hat{\Gamma}_u(e^{j\omega})}
53 | \]
54 |
55 | We can fit the estimated $\hat{W}(e^{j\omega})$ with the model frequency response $W(e^{j\omega}, \theta)$ in the performance index.
56 | This experiment is quicker but has usually a lower signal-to-noise-ration.
57 | \end{rem}
58 |
59 | \section{Comparison between time domain (ARMAX) and frequency domain parametric methods}
60 |
61 | \paragraph{Frequency domains}
62 | \begin{description}
63 | \item[Pro] Robust and very reliable. We put a lot of energy on each sinusoid. The frequency response estimation is very reliable.
64 | \item[Pro] Intuitive (easy to understand)
65 | \item[Pro] Consistent with control-design methods (usually in frequency domain)
66 | \item[Cons] More demanding for the experiment
67 | \end{description}
68 |
69 | Note that F.D. and T.D. methods should provide the same result if done correctly.
70 |
71 |
72 | \chapter{Kalman Filter (software sensing in feedback)}
73 |
74 | In MIDA1 we have mostly used I/O transfer function representations:
75 | \[ y(t) = \frac{B(z)}{A(z)}u(t-k) + \frac{C(z)}{A(z)}e(t) \qquad e(t) \sim WN \]
76 |
77 |
78 | Kalman filter theory is fully based on S.S. representation.
79 |
80 | \[
81 | \begin{cases}
82 | x(t+1) = Fx(t) + Gu(t) + v_1(t) & \qquad v_1 \sim WN \\
83 | y(t) = Hx(t) + \cancel{Du(t)} + v_2(t) & \qquad v_2 \sim WN
84 | \end{cases}
85 | \]
86 |
87 | \section{Motivation and Goals}
88 |
89 | Given a model description $\{F, G, H\}$ and noises variances (not a system identification technique), with K.F. theory we can address the following problems:
90 |
91 | \begin{itemize}
92 | \item $k$-steps ahead prediction of output: $\hat{y}(t+k|t)$ (already solved in MIDA1 for ARMAX).
93 | \item $k$-steps ahead prediction of state: $\hat{x}(t+k|t)$ (at time $t$ we have available $y(t)$, $y(t-1)$, $\ldots$, $u(t)$, $u(t-1)$, $\ldots$).
94 | \item Find the filter of the state: $\hat{x}(t|t)$ (given data of $y(t)$ and past, and $u(t)$ and part, the estimation is made at the same time). In practice it's \emph{software-sensing}, most important problem solved by Kalman filter (ideed K.F. is named \emph{filter}).
95 | \item Gray box system identification (see chapter 5). We have a recorded data set and the model structure with some unknown parameters.
96 | \end{itemize}
97 |
98 |
99 | Dynamical systems have this layout:
100 | \begin{figure}[H]
101 | \centering
102 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
103 | \node [int, ellipse, align=center] (sys) {$x_1(t)$\\$x_2(t)$\\$x_n(t)$};
104 | \node (in1) [left of=sys, node distance=2cm, yshift=0.7cm] {$u_1(t)$};
105 | \node (in2) [left of=sys, node distance=2cm] {$u_2(t)$};
106 | \node (in3) [left of=sys, node distance=2cm, yshift=-0.7cm] {$u_m(t)$};
107 | \node (out1) [right of=sys, node distance=2cm, yshift=0.7cm]{$y_1(t)$};
108 | \node (out2) [right of=sys, node distance=2cm]{$y_2(t)$};
109 | \node (out3) [right of=sys, node distance=2cm, yshift=-0.7cm]{$y_p(t)$};
110 |
111 | \draw[->] (in1) -- (sys);
112 | \draw[->] (in2) -- (sys);
113 | \draw[->] (in3) -- (sys);
114 | \draw[->] (sys) -- (out1);
115 | \draw[->] (sys) -- (out2);
116 | \draw[->] (sys) -- (out3);
117 | \end{tikzpicture}
118 | \end{figure}
119 |
120 | MIMO system with $m$ inputs, $p$ outputs and $n$ states.
121 |
122 | \textbf{Key problem} usually $p \ll n$, physical sensors are much less than system states.
123 | \begin{itemize}
124 | \item Cost
125 | \item Cables, power supply
126 | \item Maintenance (faults, degradation)
127 | \end{itemize}
128 |
129 | It is useful to have full ``measurement'' of states because:
130 | \begin{itemize}
131 | \item Control design (state feedback design)
132 | \item Monitoring (fault detection, predictive maintenance, \dots)
133 | \end{itemize}
134 |
135 | Software sensing (also called virtual sensing):
136 | \begin{figure}[H]
137 | \centering
138 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
139 | \node [int, ellipse, align=center] (sys) {system\\$x(t)$};
140 | \node (in1) [left of=sys, node distance=2cm, yshift=0.7cm] {};
141 | \node (in2) [left of=sys, node distance=2.3cm] {$u(t)$};
142 | \node (in3) [left of=sys, node distance=2cm, yshift=-0.7cm] {};
143 | \node (out1) [right of=sys, node distance=2cm, yshift=0.7cm]{};
144 | \node (out2) [right of=sys, node distance=2.3cm]{$y(t)$};
145 | \node (out3) [right of=sys, node distance=2cm, yshift=-0.7cm]{};
146 |
147 | \node [int, ellipse, align=center, below of=sys] (algo) {algorithm in\\a DCD (KF)};
148 | \node (algoout) [right of=algo, node distance=3cm] {$\hat{x}(t)$};
149 |
150 | \draw[->] (in1) -- (sys);
151 | \draw[->] (in2) -- (sys);
152 | \draw[->] (in3) -- (sys);
153 | \draw[->] (sys) -- (out1);
154 | \draw[->] (sys) -- (out2);
155 | \draw[->] (sys) -- (out3);
156 |
157 | \draw[->] (-1.4,0.8) -- (-1.4,-1) -- (algo);
158 | \draw[->] (1.4,0.8) -- (1.4,-1) -- (algo);
159 | \draw[->] (algo) -- (algoout);
160 | \end{tikzpicture}
161 | \end{figure}
162 |
163 | \paragraph{Dilemma} When using software sensing and when physical sensing?
164 | \begin{itemize}
165 | \item In some cases there is no option (not feasible installation of a physical sensor)
166 | \item In most cases both options are viable: variable vs fixed cost
167 | \end{itemize}
168 |
169 | \begin{figure}[H]
170 | \centering
171 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
172 | \draw[->] (-0.5,0) -- (4,0) node[right, align=center] {Fixed development costs\\of software sensing algorithm};
173 | \draw[->] (0,-0.5) -- (0,4) node[left, align=right] {Variable cost proportional\\to the number of sensors};
174 | \draw[domain=0:2.5,samples=20,smooth,variable=\x,red] plot ({\x},{sqrt(2.5^2-\x^2)});
175 | \draw [decorate,decoration={brace,amplitude=10pt}] (0,0) -- (0,2.5) node [black,midway,align=right,xshift=-0.3cm] {Low volumes\\better physical sensing};
176 | \draw [decorate,decoration={brace,amplitude=7pt}] (0,3.5) -- (0,2.5) node [black,midway,align=left,xshift=0.3cm] {High volumes\\better software sensing};
177 | \end{tikzpicture}
178 | \caption*{Break-even analysis}
179 | \end{figure}
180 |
--------------------------------------------------------------------------------
/main.tex:
--------------------------------------------------------------------------------
1 | \documentclass[10pt,a4paper,twoside]{book}
2 |
3 | \input{style}
4 |
5 | \usepackage[
6 | left=2.5cm, % inner
7 | right=2.5cm, % outer
8 | top=2.5cm,
9 | bottom=3cm,
10 | %showframe,
11 | ]{geometry}
12 |
13 | \usepackage{xr} % cross-referencing
14 | \makenoidxglossaries
15 |
16 | % Comandi pratici
17 |
18 | % d nell'integrale e i rispettivi usi
19 | \newcommand{\dl}{\de l}
20 | \newcommand{\dr}{\de r}
21 | \newcommand{\dxi}{\de \xi}
22 | \newcommand{\drho}{\de \rho}
23 |
24 | % d nell'integrale con differenziale vettoriale
25 | \newcommand{\dxx}{\de \x}
26 | \newcommand{\dyy}{\de \y}
27 | \newcommand{\dsig}{\de \sigg}
28 |
29 | \allowdisplaybreaks[4] % Consente di rompere equazioni su più pagine
30 |
31 | % MIDA1 acronym
32 | \newacronym{sp}{SP}{Stochastic Process}
33 | \newacronym{ssp}{SSP}{Stationary Stochastic Process}
34 | \newacronym{ma}{MA}{Moving Average}
35 | \newacronym{ar}{AR}{Auto Regressive}
36 | \newacronym{arx}{ARX}{Auto Regressive with Exogenous Input}
37 | \newacronym{arma}{ARMA}{Auto Regressive Moving Average}
38 | \newacronym{armax}{ARMAX}{Auto Regressive Moving Average with Exogenous Input}
39 | \newacronym{mse}{MSE}{Mean Square Error}
40 | \newacronym{wn}{WN}{White Noise}
41 | \newacronym{pem}{PEM}{Prediction Error Minimization}
42 |
43 | % MIDA2 acronym
44 | \newacronym{tf}{TF}{Transfer Function}
45 | \newacronym{ss}{SS}{State-Space}
46 | \newacronym{ir}{IR}{Impulse Response}
47 | \newacronym{bb}{BB}{Black-Box}
48 | \newacronym{wb}{WB}{White-Box}
49 | \newacronym{gb}{GB}{Gray-Box}
50 | \newacronym{kf}{KF}{Kalman Filter}
51 | \newacronym{dre}{DRE}{Difference Riccati Equation}
52 | \newacronym{are}{ARE}{Algebraic Riccati Equation}
53 | \newacronym{sem}{SEM}{Simulation Error Method}
54 |
55 | %c ommon used operator
56 | \DeclareMathOperator{\WN}{WN}
57 |
58 | \begin{document}
59 |
60 | \frontmatter
61 |
62 | \pagestyle{empty}
63 |
64 | % TITLE PAGE
65 |
66 | \hypertarget{mytitlepage}{} % set the hypertarget
67 | \bookmark[dest=mytitlepage,level=chapter]{Title Page} % add the bookmark
68 |
69 | \vspace*{\fill}
70 | \begin{center}
71 | {\large \textsc{Lecture Notes of}}\\
72 |
73 | \vspace*{0.4cm}
74 |
75 | {\Huge
76 | \textsc{Model Identification}\\
77 | \vspace*{0.4cm}
78 | \textsc{and Data Analysis}}\\
79 | \vspace*{0.4cm}
80 | {\huge \textsc{Module 2}}\\
81 |
82 | \vspace*{1cm}
83 |
84 | {\large {From Professor Sergio Savaresi's lectures}}\\
85 |
86 | \vspace*{1cm}
87 |
88 | {\large
89 | Author\\
90 | \vspace*{0.1cm}
91 | \textsc{Edoardo Morassutto}\\
92 |
93 | \vspace*{0.4cm}
94 |
95 | Contributors\\
96 | \vspace*{0.1cm}
97 | \textsc{Marco Donadoni}\\
98 | \textsc{Cosimo Russo}\\
99 | \textsc{Federico Cazzola}\\
100 |
101 | \vspace*{0.4cm}
102 |
103 | Reviewed for the 2022 edition of the course by\\
104 | \vspace*{0.1cm}
105 | \textsc{Andrea Bosisio}\\
106 |
107 | \vspace*{0.4cm}
108 |
109 | Document formatting by\\
110 | \vspace*{0.1cm}
111 | \textsc{Teo Bucci}}\\
112 |
113 | \vspace*{1cm}
114 |
115 | Politecnico di Milano\\A.Y. 2021/2022
116 | \end{center}
117 | \vspace*{\fill}
118 | \clearpage
119 |
120 | % COPYRIGHT PAGE
121 |
122 | \hypertarget{mycopyright}{} % set the hypertarget
123 | \bookmark[dest=mycopyright,level=chapter]{Copyright Page} % add the bookmark
124 | \input{firstpages/copyright}
125 | \clearpage
126 |
127 | % PREFACE
128 |
129 | % \hypertarget{mypreface}{} % set the hypertarget
130 | % \bookmark[dest=mypreface,level=chapter]{Preface} % add the bookmark
131 | % \input{firstpages/preface}
132 | % \clearpage
133 |
134 | % CONTENTS
135 |
136 | \cleardoublepage
137 | \pagestyle{toc}
138 | \hypertarget{mytoc}{} % set the hypertarget
139 | \bookmark[dest=mytoc,level=chapter]{\contentsname} % add the bookmark
140 | \tableofcontents
141 | \cleardoublepage
142 |
143 | % MAIN MATTER
144 |
145 | \pagestyle{fancy}
146 | \mainmatter
147 |
148 | %%TIKZ
149 |
150 | \usetikzlibrary{matrix,shapes.geometric}
151 |
152 | \tikzstyle{block} = [draw, rectangle, inner sep=6pt]
153 | \tikzstyle{every node} = [font=\small]
154 | \tikzstyle{sum} = [draw, circle, inner sep=3pt, minimum size =0.1cm]
155 |
156 | % Cross
157 | \tikzset{cross/.style={cross out, draw=black, minimum size=2*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt},
158 | %default radius will be 1pt.
159 | cross/.default={0.1cm}}
160 |
161 | % double border
162 | \tikzstyle{double border} = [double, double distance=0.5mm]
163 | % pattern in border
164 | \newcounter{tmp}
165 | \newif\ifpathisclosed
166 | \tikzset{dashed border/.style={
167 | preaction={decoration={contour lineto closed, contour distance=2pt},
168 | decorate,
169 | },
170 | postaction={
171 | insert path={%
172 | \pgfextra{%
173 | \pgfinterruptpath
174 | \path[pattern=north west lines, pattern color=black,even odd rule]
175 | \mySecondList \myList
176 | ;
177 | \endpgfinterruptpath}
178 | }},
179 | }}
180 | \def\pgfdecoratedcontourdistance{0pt}
181 | \pgfset{
182 | decoration/contour distance/.code=%
183 | \pgfmathsetlengthmacro\pgfdecoratedcontourdistance{#1}}
184 | \pgfdeclaredecoration{contour lineto closed}{start}{%
185 | \state{start}[
186 | next state=draw,
187 | width=0pt,
188 | persistent precomputation=\let\pgf@decorate@firstsegmentangle\pgfdecoratedangle]{%
189 | %\xdef\myList{}\xdef\mySecondList{}%
190 | \setcounter{tmp}{0}%
191 | \global\pathisclosedfalse%
192 | \pgfpathmoveto{\pgfpointlineattime{.5}
193 | {\pgfqpoint{0pt}{\pgfdecoratedcontourdistance}}
194 | {\pgfqpoint{\pgfdecoratedinputsegmentlength}{\pgfdecoratedcontourdistance}}}%
195 | }%
196 | \state{draw}[next state=draw, width=\pgfdecoratedinputsegmentlength]{%
197 | \ifpgf@decorate@is@closepath@%
198 | \pgfmathsetmacro\pgfdecoratedangletonextinputsegment{%
199 | -\pgfdecoratedangle+\pgf@decorate@firstsegmentangle}%
200 | \fi
201 | \pgfmathsetlengthmacro\pgf@decoration@contour@shorten{%
202 | -\pgfdecoratedcontourdistance*cot(-\pgfdecoratedangletonextinputsegment/2+90)}%
203 | \pgfpathlineto
204 | {\pgfpoint{\pgfdecoratedinputsegmentlength+\pgf@decoration@contour@shorten}
205 | {\pgfdecoratedcontourdistance}}%
206 | \stepcounter{tmp}%
207 | \pgfcoordinate{muemmel\number\value{tmp}}{\pgfpoint{\pgfdecoratedinputsegmentlength+\pgf@decoration@contour@shorten}
208 | {\pgfdecoratedcontourdistance}}%
209 | \pgfcoordinate{feep\number\value{tmp}}{\pgfpoint{\pgfdecoratedinputsegmentlength}{0pt}}%
210 | \ifnum\value{tmp}=1\relax%
211 | \pgfcoordinate{muemmel0}{\pgfpoint{0pt}{\pgfdecoratedcontourdistance}}%
212 | \pgfcoordinate{feep0}{\pgfpoint{0pt}{0pt}}%
213 | \xdef\myList{(muemmel\number\value{tmp})}%
214 | \xdef\mySecondList{(feep\number\value{tmp})}%
215 | \else
216 | \xdef\myList{\myList -- (muemmel\number\value{tmp})}%
217 | \xdef\mySecondList{(feep\number\value{tmp}) -- \mySecondList}%
218 | \fi
219 | \ifpgf@decorate@is@closepath@%
220 | \pgfpathclose
221 | \global\pathisclosedtrue%
222 | \fi
223 | }%
224 | \state{final}{%\typeout{\myList,\mySecondList}%
225 | \ifpathisclosed%
226 | \xdef\myList{\myList -- cycle}%
227 | \xdef\mySecondList{\mySecondList -- cycle}%
228 | %\typeout{closed \mySecondList \myList }
229 | \else
230 | %\typeout{\number\value{tmp}}%
231 | \xdef\myList{(muemmel0) -- \myList -- cycle}%
232 | \xdef\mySecondList{\mySecondList -- (feep0) --}%
233 | %\typeout{not closed \mySecondList \myList }%
234 | \fi
235 | }%
236 | }
237 | \tikzset{
238 | contour/.style={
239 | decoration={
240 | name=contour lineto closed,
241 | contour distance=#1
242 | },
243 | decorate}}
244 |
245 | % pattern
246 | \tikzset{
247 | hatch distance/.store in=\hatchdistance,
248 | hatch distance=10pt,
249 | hatch thickness/.store in=\hatchthickness,
250 | hatch thickness=0.2pt
251 | }
252 | \pgfdeclarepatternformonly[\hatchdistance,\hatchthickness]{flexible hatch}
253 | {\pgfqpoint{0pt}{0pt}}
254 | {\pgfqpoint{\hatchdistance}{\hatchdistance}}
255 | {\pgfpoint{\hatchdistance-1pt}{\hatchdistance-1pt}}%
256 | {
257 | \pgfsetcolor{\tikz@pattern@color}
258 | \pgfsetlinewidth{\hatchthickness}
259 | \pgfpathmoveto{\pgfqpoint{0pt}{0pt}}
260 | \pgfpathlineto{\pgfqpoint{\hatchdistance}{\hatchdistance}}
261 | \pgfusepath{stroke}
262 | }
263 |
264 | %\tikzstyle{input} = [coordinate]
265 | %\tikzstyle{output} = [coordinate]
266 | %\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
267 |
268 | \input{lectures/2022_04_06}
269 | \input{lectures/2022_04_07}
270 | \input{lectures/2022_04_11}
271 | \input{lectures/2022_04_12}
272 | \input{lectures/2022_04_14}
273 | \input{lectures/2022_04_20}
274 | \input{lectures/2022_04_21}
275 | \input{lectures/2022_04_27}
276 | \input{lectures/2022_05_02}
277 | \input{lectures/2022_05_09}
278 | \input{lectures/2022_05_12}
279 |
280 | \glsaddall
281 | \printnoidxglossary[type=\acronymtype,title=Glossary, toctitle=Glossary, nonumberlist]
282 | \cleardoublepage
283 |
284 | \end{document}
285 |
286 | %Aliasing errors occur when components of a signal are above the Nyquist frequency (Nyquist theory states that the sampling frequency must be at least two times the highest frequency component of the signal) or one half the sample rate.
287 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-18.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{18/05/2020}
2 |
3 | \paragraph{Conclusions} In case of black-box software sensing with non-linear systems the problem can be quite complex.
4 | Using \emph{brute-force} approach (1 dynamic neural network) is usually doomed to failure.
5 | The best is to gain some insight into the system and build some \emph{smart} regressors before black-box map.
6 |
7 | \chapter{Gray-box System Identification}
8 |
9 | We'll see two approaches
10 | \begin{itemize}
11 | \item Using Kalman Filter
12 | \item Using Simulation error method
13 | \end{itemize}
14 |
15 | \section{Using Kalman Filter}
16 | Kalman Filter is not a system identification method, it is a variable estimation approach (software-sensor, observer).
17 | However we can use it also for gray-box system identification (\emph{side benefit} of K.F.).
18 |
19 | \paragraph{Problem definition} We have a model, typically built as a white-box model using first principles:
20 | \[
21 | S: \begin{cases}
22 | x(t+1) = f(x(t), u(t), \theta) + v_1(t) \\
23 | y(t) = h(x(t), \theta) + v_2(t)
24 | \end{cases}
25 | \]
26 |
27 | $f$ and $h$ are linear or non-linear functions, depending on some unknown parameter $\theta$ (with a physical meaning, e.g. mass, resistance, friction, \dots).
28 |
29 | The problem is to estimate $\hat{\theta}$.
30 |
31 | K.F. solves this problem by transforming the unknown parameters in extended states: K.F. makes the simultaneous estimation of $\hat{x}(t|t)$ (classic Kalman Filter problem) and $\hat{\theta}(t)$ (parameter identification problem).
32 |
33 | \paragraph{Trick} State extension
34 |
35 | \[
36 | S: \begin{cases}
37 | x(t+1) = f(x(t), u(t), \theta(t)) + v_1(t) \\
38 | \theta(t+1) = \theta(t) + v_\theta(t) \\
39 | y(t) = h(x(t), \theta(t)) + v_2(t)
40 | \end{cases}
41 | \]
42 |
43 | The new extended state vector is $x_E = \begin{bmatrix} x(t) \\ \theta(t) \end{bmatrix}$.
44 | The unknown parameters are transformed in unknown variables.
45 |
46 | The new equation we created
47 | \[
48 | \theta(t+1) = \theta(t) + v_\theta(t)
49 | \]
50 | It is a \emph{fictitious} equation (not a physical equation).
51 |
52 | The core dynamics is $\theta(t+1)=\theta(t)$, it's the equations of something which is constant.
53 | This is exactly the nature of $\theta(t)$ which is indeed a constant vector of parameters.
54 |
55 | We need a \emph{fictitious} noise in order to force Kalman Filter to find the right value of $\theta$ (if no noise in this equation K.F. probably would stay fixed on the initial condition).
56 | We tell K.F. to do not rely on initial conditions.
57 |
58 | Notice that this equation is not of an asymptotic stable system but a simply-stable system.
59 | It's not a problem because K.F. can deal with non-asymptotically stable systems.
60 |
61 | \paragraph{Design choice} The choice of the covariance matrix of $v_\theta(t) \sim WN(0, V_\theta)$.
62 |
63 | We make the empirical assumption that $v_1 \perp v_\theta$ and $v_2 \perp v_\theta$ (there is no reason for $v_\theta$ to be correlated with $v_1$ and $v_2$).
64 | \[
65 | V_\theta = \begin{bmatrix}
66 | \lambda_{1\theta}^2 & & & \\
67 | & \lambda_{2\theta}^2 & & \\
68 | & & \ddots & \\
69 | & & & \lambda_{n_\theta\theta}^2\\
70 | \end{bmatrix}
71 | \]
72 |
73 | It is a $n_\theta\times n_\theta$ and usually it is assumed that $\lambda_{1\theta}^2=\lambda_{2\theta}^2=\dots=\lambda_{n_\theta\theta}^2$.
74 | We assume that $v_\theta(t)$ is a set of independent W.N. all with the same variance $\lambda_\theta^2$ (tuned empirically).
75 |
76 | \begin{figure}[H]
77 | \centering
78 | \begin{tikzpicture}[
79 | node distance=2cm,auto,>=latex',
80 | declare function={
81 | f1(\x) = (\x < 2) * (\x/2*(3-1)) +
82 | (\x >= 2) * (3-1) +
83 | (\x > 0.2) * rand/2.5 +
84 | 1;
85 | f2(\x) = (\x < 4.5) * (\x/4.5*(3-1)) +
86 | (\x >= 4.5) * (3-1) +
87 | (\x > 0.2) * rand/15 +
88 | 1;
89 | }
90 | ]
91 | \draw[->] (0,0) -- (6,0) node[below] {$t$};
92 | \draw[->] (0,0) -- (0,4) node[left] {$\theta$};
93 |
94 | \node[green] at (2.3,1.5) {\footnotesize small $\lambda_\theta^2$};
95 | \node[blue] at (2.3,3.7) {\footnotesize big $\lambda_\theta^2$};
96 |
97 | \draw[dotted] (6,3) -- (0,3) node[left] {$\overline{\theta}$};
98 | \draw[domain=0:5.5,smooth,variable=\x,blue,samples=70] plot ({\x},{f1(\x)});
99 | \draw[domain=0:5.5,smooth,variable=\x,green,samples=70] plot ({\x},{f2(\x)});
100 |
101 | \draw[mark=*] plot coordinates {(0,1)} node[left, align=right] {Initial\\condition};
102 | \end{tikzpicture}
103 | \caption*{Influence of choice of $\lambda_\theta^2$}
104 | \end{figure}
105 |
106 | With a small value of $\lambda_\theta^2$ there is a slow convergence with small oscillations (noise) at steady-state (big trust to initial conditions).
107 | With large values of $\lambda_\theta^2$ there's fast convergence but noisy at steady-state.
108 |
109 | $\lambda_\theta^2$ is selected according to the best compromise for your specific application.
110 |
111 | \paragraph{Notice} This trick can work in principle with any number of unknown parameters (e.g. 3 sensors, 10 states and 20 parameters).
112 | In practice it works well only on a limited number of parameters (e.g. 3 sensors, 5 states and 2 parameters).
113 |
114 | \begin{exa}
115 | \begin{figure}[H]
116 | \centering
117 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
118 | \draw (0,0) -- (6,0);
119 | \draw[pattern=north east lines] (0,0) rectangle (-0.5,2);
120 | \draw[] (2,0) rectangle (4,1.5);
121 | \node at (3,0.75) {$M$};
122 | \draw[decoration={aspect=0.3, segment length=1mm, amplitude=2mm,coil},decorate] (0.5,0.75) -- (1.5,0.75);
123 | \draw (0,0.75) -- (0.5,0.75);
124 | \draw (1.5,0.75) -- (2,0.75);
125 | \draw[->] (4,0.75) -- (5,0.75) node[right] {$F$};
126 | \fill[pattern=north east lines] (1.8,0) rectangle ++(2.4,-0.1) node[above right] {\footnotesize friction $c$};
127 | \draw[->] (3,-0.5) -- (4,-0.5) node[right] {$x$};
128 | \draw (3,-0.55) -- (3,-0.45);
129 | \end{tikzpicture}
130 | \end{figure}
131 |
132 | \begin{description}
133 | \item[Input] $F(t)$
134 | \item[Output] Position $x(t)$ (measured)
135 | \item[Parameters] $K$ and $M$ are known (measured), $c$ is unknown
136 | \end{description}
137 |
138 | \begin{figure}[H]
139 | \centering
140 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
141 | \node[int,align=center] at (0,0) (s) {system\\$c = ?$};
142 | \draw[<-] (s) -- ++(-1.5,0) node[left] {$F(t)$};
143 | \draw[->] (s) -- ++(1.5,0) node[right] {$x(t)$};
144 | \end{tikzpicture}
145 | \end{figure}
146 |
147 | \paragraph{Problem} Estimate $c$ with a K.F.
148 |
149 | Using K.F. we do not need a training dataset.
150 |
151 | \paragraph{Step 1} Model the system
152 | \[
153 | \ddot{x}M = -Kx - c\dot{x} + F
154 | \]
155 | It's a differential, continuous time linear equation.
156 | It's second order so we need 2 state variables: $x_1(t) = x(t)$ and $x_2(t) = \dot{x}(t)$.
157 | \[
158 | \begin{cases}
159 | \dot{x}(t) = x_2(t) \\
160 | M\dot{x}_2(t) = -Kx_1(t) -cx_2(t) + F(t) \\
161 | y(t) = x_1(t)
162 | \end{cases}
163 | \begin{cases}
164 | \dot{x}_1(t) = x_2(t) \\
165 | \dot{x}_2(t) = -\frac{K}{M} x_1(t) - \frac{c}{M} x_2(t) + \frac{1}{M}F(t) \\
166 | y(t) = x_1(t)
167 | \end{cases}
168 | \]
169 |
170 | \paragraph{Step 2} Discretization
171 |
172 | Eulero forward: $\dot{x}(t) \approx \frac{x(t+1)-x(t)}{\Delta}$.
173 |
174 | \[
175 | \begin{cases}
176 | \frac{x_1(t+1)-x_1(t)}{\Delta} &= x_2(t) \\
177 | \frac{x_2(t+1)-x_2(t)}{\Delta} &= -\frac{K}{M} x_1(t) - \frac{c}{M} x_2(t) + \frac{1}{M}F(t) \\
178 | y(t) &= x_1(t)
179 | \end{cases}
180 | \]
181 | \[
182 | \begin{cases}
183 | x_1(t+1) = x_1(t) + \Delta x_2(t) \\
184 | x_2(t+1) = -\frac{K\Delta}{M}x_1(t) + \left(1-\frac{c\Delta}{M}\right)x_2(t) + \frac{\Delta}{M}F(t) \\
185 | y(t) = x_1(t)
186 | \end{cases}
187 | \]
188 |
189 | \paragraph{Step 3} State extension
190 | \[
191 | x_3(t+1) = x_3(t)
192 | \]
193 | \[
194 | \begin{cases}
195 | x_1(t+1) = x_1(t) + \Delta x_2(t) + v_{11}(t) \\
196 | x_2(t+1) = -\frac{K\Delta}{M}x_1(t) + \left(1-\frac{\Delta {\color{red}x_3(t)}}{M}\right)x_2(t) + \frac{\Delta}{M}F(t) + v_{12}(t) \\
197 | {\color{red}x_3(t+1) = x_3(t) + v_{13}(t)} \\
198 | y(t) = x_1(t) + v_2(t)
199 | \end{cases}
200 | \]
201 |
202 | The system is ready for K.F. application: we get at the same time $\hat{x}(t)$ and $\hat{c}(t)$.
203 |
204 | Notice that we need Extended Kalman Filter: even if the original system was linear, state extension moved to a non-linear system.
205 | \end{exa}
206 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-19.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{19/05/2020}
2 |
3 | \section{Using Simulation Error Method}
4 |
5 | Are there alternative ways to solve gray-box system identification problems?
6 | A commonly (and intuitive) used method is parametric identification approach based on Simulation Error Method (SEM).
7 |
8 | \begin{figure}[H]
9 | \centering
10 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
11 | \node[int, align=center] at (0,0) (sys) {Model with\\some unknown\\parameters};
12 | \draw[<-] (sys) -- ++(-2,0) node[left] {$u(t)$};
13 | \draw[->] (sys) -- ++(2,0) node[right] {$y(t)$};
14 | \end{tikzpicture}
15 | \end{figure}
16 |
17 | \paragraph{Step 1} Collect data from an experiment
18 |
19 | \begin{align*}
20 | \{ \tilde{u}(1), \tilde{u}(2), \dots, \tilde{u}(N) \} \\
21 | \{ \tilde{y}(1), \tilde{y}(2), \dots, \tilde{y}(N) \}
22 | \end{align*}
23 |
24 | \paragraph{Step 2} Define model structure
25 | \[
26 | y(t) = \mathcal{M}(u(t), \overline{\theta}, \theta)
27 | \]
28 | Mathematical model (linear or non-linear) usually written from first principle equations. $\overline{\theta}$ is the set of known parameters (mass, resistance, \dots), $\theta$ is the set of unknown parameters (possibly with bounds).
29 |
30 | \paragraph{Step 3} Performance index definition
31 | \[
32 | J_N(\theta) = \frac{1}{N} \sum_{t=1}^N \left( \tilde{y}(t) - \mathcal{M}(\tilde{u}(t), \overline{\theta}, \theta) \right)^2
33 | \]
34 |
35 | \paragraph{Step 4} Optimization
36 |
37 | \[
38 | \hat{\theta}_N = \argmin_\theta J_N(\theta)
39 | \]
40 |
41 | \begin{itemize}
42 | \item Usually no analytic expression of $J_N(\theta)$ is available.
43 | \item Each computation of $J_N(\theta)$ requires an entire simulation of the model from $t=1$ to $t=N$.
44 | \item Usually $J_N(\theta)$ is a non-quadratic and non-convex function. Iterative and randomized optimization methods must be used.
45 | \item It's intuitive but very computationally demanding.
46 | \end{itemize}
47 |
48 | \begin{figure}[H]
49 | \centering
50 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
51 | \draw (0,2) rectangle ++(2,2);
52 | \node[align=center] at (1,3) {Model of\\the system};
53 | \node[draw, ellipse, align=center] at (1,0) (m) {Model\\$\mathcal{M}(\theta)$};
54 | \node[sum] at (4,0) (sum) {};
55 | \node[int] at (4,-1.5) (J) {$J(\theta)$};
56 |
57 | \draw[<-] (m) -- (-1,0) node[left] {$\tilde{F}(t)$};
58 | \draw[->] (m) -- (sum) node[pos=0.8] {+} node[pos=0.5] {$\hat{y}(t)$};
59 | \draw[->] (4,3) -- (sum) node[pos=0.9] {-};
60 | \draw[->] (sum) -- (J) node[pos=0.5, right] {\footnotesize simulation error};
61 | \draw[->] (J) -| (m);
62 |
63 | \draw[<-] (0,3) -- (-1,3) node[left] {$\tilde{F}(t)$};
64 | \draw[->] (2,3) -- (5,3) node[right] {$\tilde{y}(t)$};
65 | \end{tikzpicture}
66 | \end{figure}
67 |
68 | Can S.E.M. be applied also to B.B. methods?
69 |
70 | \begin{exa}
71 | We collect data $\{ \tilde{u}(1), \tilde{u}(2), \dots, \tilde{u}(N) \}$ and $\{ \tilde{y}(1), \tilde{y}(2), \dots, \tilde{y}(N) \}$, we want to estimate from data the I/O model.
72 |
73 | \[
74 | y(t) = \frac{b_0 + b_1z^{-1}}{1+a_1z^{-1} + a_2z^{-2}}u(t-1) \qquad \theta = \begin{bmatrix}
75 | a_1 \\ a_2 \\ b_0 \\ b_1
76 | \end{bmatrix}
77 | \]
78 |
79 | In time domain $y(t) = -a_1y(t-1)-a_2y(t-2)+b_0u(t-1)+b_1u(t-2)$.
80 |
81 | Using P.E.M.
82 | \[
83 | \hat{y}(t|t-1) = -a_1\hat{y}(t-1)-a_2\hat{y}(t-2)+b_0\hat{u}(t-1)+b_1\hat{u}(t-2)
84 | \]
85 | \begin{align*}
86 | J_N(\theta) &= \frac{1}{N}\sum_{t=1}^N \left( \tilde{y}(t) - \hat{y}(t|t-1, \theta) \right)^2 \\
87 | &= \frac{1}{N}\sum_{t=1}^N \left( \tilde{y}(t) +a_1\tilde{y}(t-1)+a_2\tilde{y}(t-2)-b_0\tilde{u}(t-1)-b_1\tilde{u}(t-2) \right)^2 \\
88 | \end{align*}
89 |
90 | Notice that it's a quadratic formula.
91 |
92 | \begin{figure}[H]
93 | \begin{minipage}[t]{0.5\textwidth}
94 | \centering
95 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
96 | \node[int] at (1,1) (zu) {$z^{-1}$};
97 | \node[int] at (1,3.5) (zy) {$z^{-1}$};
98 |
99 | \node at (0,2) (u) {$\tilde{u}(t)$};
100 | \node at (0,4.5) (y) {$\tilde{y}(t)$};
101 |
102 | \node[int,minimum height=5cm,minimum width=1.5cm,align=center] at (3.5,2.5) (sys) {Linear\\function\\of $\theta$};
103 |
104 | \draw[->] (zu) -- (zu-|sys.west) node[pos=0.5] {$\scriptstyle\tilde{u}(t-1)$};
105 | \draw[->] (u) -- (u-|sys.west);
106 | \draw[->] (1,2) -- (zu);
107 | \draw[->] (zy) -- (zy-|sys.west) node[pos=0.5] {$\scriptstyle\tilde{y}(t-1)$};
108 | \draw[->] (y) -- (y-|sys.west);
109 | \draw[->] (1,4.5) -- (zy);
110 | \draw[->] (sys) -- ++(2,0) node[above] {$\scriptstyle\hat{y}(t|t-1)$};
111 | \end{tikzpicture}
112 | \caption*{P.E.M.}
113 | \end{minipage}
114 | \begin{minipage}[t]{0.4\textwidth}
115 | \centering
116 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
117 | \node[int] at (1,1) (zu) {$z^{-1}$};
118 | \node[int] at (1,3) (zy) {$z^{-1}$};
119 | \node[int] at (1,4.5) (zy2) {$z^{-1}$};
120 |
121 | \node at (0,2) (u) {$\tilde{u}(t)$};
122 |
123 | \node[int,minimum height=5cm,minimum width=1.5cm,align=center] at (3.5,2.5) (sys) {Linear\\function\\of $\theta$};
124 |
125 | \draw[->] (zu) -- (zu-|sys.west) node[pos=0.5] {$\scriptstyle\tilde{u}(t-1)$};
126 | \draw[->] (u) -- (u-|sys.west);
127 | \draw[->] (1,2) -- (zu);
128 |
129 | \draw[->] (zy) -- (zy-|sys.west) node[pos=0.5] {$\scriptstyle\hat{y}(t-2)$};
130 | \draw[->] (zy2) -- (zy2-|sys.west) node[pos=0.5] {$\scriptstyle\hat{y}(t-1)$};
131 | \draw[->] (zy2) -- (zy);
132 | \draw[->] (4.8,2.5) -- (4.8,5.5) -- (1,5.5) -- (zy2);
133 |
134 | \draw[->] (sys) -- ++(2,0) node[above] {$\scriptstyle\hat{y}(t|t-1)$};
135 | \end{tikzpicture}
136 | \caption*{S.E.M.}
137 | \end{minipage}
138 | \end{figure}
139 |
140 | Using S.E.M.
141 | \[
142 | \hat{y}(t|t-1) = -a_1\hat{y}(t-1)-a_2\hat{y}(t-2)+b_0\tilde{u}(t-1)+b_1\tilde{u}(t-2)
143 | \]
144 | \begin{align*}
145 | J_N(\theta) &= \frac{1}{N}\sum_{t=1}^N \left( \tilde{y}(t) - \hat{y}(t|t-1, \theta) \right)^2 \\
146 | &= \frac{1}{N}\sum_{t=1}^N \left( \tilde{y}(t) +a_1\hat{y}(t-1)+a_2\hat{y}(t-2)-b_0\tilde{u}(t-1)-b_1\tilde{u}(t-2) \right)^2 \\
147 | \end{align*}
148 |
149 | Notice that it's non-linear with respect to $\theta$.
150 | \end{exa}
151 |
152 | P.E.M. approach looks much better, but do not forget the noise! P.E.M. is much less robust w.r.t. noise, we must include a model of the noise in the estimated model.
153 | We use ARMAX models.
154 |
155 | If we use ARX models:
156 | \[
157 | y(t) = \frac{b_0+b_1z^{-1}}{1+a_1z^{-1}+a_2z^{-2}}u(t-1) + \frac{1}{1+a_1z^{-1}+a_2z^{-2}}e(t)
158 | \]
159 | \[
160 | \hat{y}(t|t-1) = b_0u(t-1)+b_1u(t-2) - a_1y(t-1)-a_2y(t-2)
161 | \]
162 |
163 | If we use ARMAX models the numerator of the T.F. for $e(t)$ is $1+c_1z^{-1}+\ldots+c_mz^{-m}$, in this case $J_N(\theta)$ is non-linear.
164 | This leads to the same complexity of S.E.M.
165 |
166 | The second problem of P.E.M. is high sensitivity to sampling time choice.
167 | Remember that when we write at discrete time $y(t)$ we mean $y(t\cdot \Delta)$.
168 |
169 | \[
170 | \hat{y}(t|t-1) = -a_1\tilde{y}(t-1)-a_2\tilde{y}(t-2) + b_0\tilde{u}(t-1)+b_1\tilde{u}(t-2)
171 | \]
172 |
173 | If $\Delta$ is very small the difference between $\tilde{y}(t)$ and $\tilde{y}(t-1)$ becomes very small.
174 | The effect is that the P.E.M. optimization ends to provide this \emph{trivial} solution:
175 | \[
176 | a_1 = -1 \qquad a_2 \rightarrow 0 \qquad b_0 \rightarrow 0 \qquad b_1 \rightarrow 0 \qquad \Rightarrow \qquad \tilde{y}(t) \approx \tilde{y}(t-1)
177 | \]
178 |
179 | This is a wrong model due to the fact that the recursive part of the model is using past measures of the output instead of past values of the model outputs.
180 |
181 | \section{Conclusion}
182 |
183 | Summary of system identification methods for I/O systems
184 | \begin{figure}[H]
185 | \centering
186 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
187 | \node[int, dashed border, minimum width=1.5cm, minimum height=1.5cm] at (0,0) (sys) {};
188 | \draw[<-] (sys) -- ++(-1.5,0) node[left] {$u(t)$};
189 | \draw[->] (sys) -- ++(1.5,0) node[right] {$y(t)$};
190 | \end{tikzpicture}
191 | \end{figure}
192 |
193 | \begin{itemize}
194 | \item Collect a dataset for training (if needed)
195 | \item Choose a model domain (linear static/non-linear static/linear dynamic/non-linear dynamic), using gray-box or black-box
196 | \item Estimation method: constructive (4SID), parametric (P.E.M. or S.E.M.) or filtering (state extension of K.F.)
197 | \end{itemize}
198 |
199 | Better black-box for system identification and software-sensing or white box?
200 |
201 | It depends on the goals and type of applications.
202 |
203 | \begin{itemize}
204 | \item Black box is very general and very flexible, make maximum use of data and no or little need of domain knowhow
205 | \item White box is very useful when you are the system-designer (not only the control algorithm designer), can provide more insight in the system.
206 | \item Gray box can sometimes be obtained by hybrid systems (part is black-box and part is white-box).
207 | \end{itemize}
208 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-12.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{12/05/2020}
2 |
3 | \subsection{Direct optimization of gain $K$}
4 | \[
5 | S: \begin{cases}
6 | x(t+1) = 2x(t) \\
7 | y(t) = x(t) + v(t) \quad v \sim WN(0, 1)
8 | \end{cases}
9 | \]
10 |
11 | \paragraph{Problem} Compute the steady-state predictor of state $\hat{x}(t+1|t)$.
12 |
13 | We use 2 different methods:
14 | \begin{enumerate}
15 | \item Direct optimization
16 | \item K.F. theory
17 | \end{enumerate}
18 |
19 | \begin{rem}
20 | The system is not stable and the state equation is noise-free.
21 | \end{rem}
22 |
23 | \paragraph{First mehtod} Direct solution
24 |
25 | Let's start from the standard observer structure
26 | \[
27 | \begin{cases}
28 | \hat{x}(t+1|t) = 2\hat{x}(t|t-1) + K(y(t) - \hat{y}(t|t-1)) \\
29 | \hat{y}(t|t-1) = \hat{x}(t|t-1)
30 | \end{cases}
31 | \]
32 |
33 | Find the optimal $K$ by minimizing the variance of the state prediction error $\text{var}\left[x(t)-\hat{x}(t|t-1)\right]$.
34 |
35 | Write the state prediction error expression:
36 | \begin{align*}
37 | x(t+1) - \hat{x}(t+1|t) &= 2x(t) - \left[ 2\hat{x}(t|t-1) + K (y(t) - \hat{y}(t|t-1)) \right] =\\
38 | &= 2x(t) - 2\hat{x}(t|t-1) - K(x(t) + v(t) - \hat{x}(t|t-1)) = \\
39 | &= (2-K)(x(t) - \hat{x}(t|t-1)) - Kv(t)
40 | \end{align*}
41 |
42 | \paragraph{Definition} $\eta(t) = x(t) - \hat{x}(t|t-1)$
43 |
44 | The dynamic equation of the state prediction error is:
45 | \[
46 | \eta(t+1) = (2-K)\eta(t) - Kv(t) \qquad v \sim WN(0,1)
47 | \]
48 | It is an AR(1) process, in canonical form:
49 | \[
50 | \eta(t) = \frac{1}{1-(2-K)z^{-1}}e(t) \qquad e(t) = -Kv(t) \qquad e \sim WN(0, K^2)
51 | \]
52 |
53 | It's easy to find the variance of $\eta(t)$:
54 | \[
55 | \gamma_\eta(0) = \text{var}\left[\eta(t)\right] = \frac{K^2}{1-(2-K)^2}
56 | \]
57 |
58 | By minimizing this function with respect to $K$:
59 | \[
60 | \frac{\partial \text{var} \left[\eta(t)\right]}{\partial K} = 0 \quad\Rightarrow\quad \begin{cases}
61 | K_1 = 0 & \text{(no need of feedback correction)} \\
62 | K_2 = \frac{3}{2}
63 | \end{cases}
64 | \]
65 |
66 | Both are acceptable solutions.
67 |
68 | \paragraph{Second method} Using K.F. theory
69 |
70 | From the system $S$: $F=2$, $H=1$, $V_1 = 0$ so $\Gamma = 0$, $V_2 = 1$, $V_{12} = 0$.
71 |
72 | Theorem 1 requires that $V_{12} = 0$ (ok) and $F$ is asymptotically stable (not ok).
73 |
74 | Theorem 2 requires that $V_{12} = 0$ (ok), $(F, \Gamma)$ not reachable (not ok), $(F, H)$ is observable (ok).
75 |
76 | We cannot skip the analysis of D.R.E.
77 |
78 | \[
79 | \text{D.R.E.} = 4P(t) - \frac{(2P(t))^2}{P(t)+1} \ldots
80 | \]
81 | \[
82 | P(t+1) = \frac{4P(t)}{P(t) + 1}
83 | \]
84 |
85 | Next, find the corresponding the A.R.E. solutions.
86 | \[
87 | \overline{P} = \frac{4\overline{P}}{\overline{P}+1} \quad\Rightarrow\quad \begin{cases}
88 | \overline{P}_1 = 0 \\
89 | \overline{P}_2 = 3
90 | \end{cases}
91 | \quad\Rightarrow\quad \begin{cases}
92 | K_1 = 0 \\
93 | K_2 = \frac{3}{2}
94 | \end{cases}
95 | \]
96 |
97 | We need to make the D.R.E. convergence analysis.
98 | \begin{figure}[H]
99 | \centering
100 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
101 | \fill [pattern=flexible hatch, pattern color=gray!40] (-1.5,-1.5) -- (5.5,-1.5) -- (5.5,0) -- (0,0) -- (0,4.9) -- (-1.5,4.9) -- (-1.5,-2);
102 | \draw[->] (-1.5,0) -- (6,0) node[below] {$P(t)$};
103 | \draw[->] (0,-1.5) -- (0,5) node[above] {$P(t+1)$};
104 | \draw[domain=-0.2:5,smooth,variable=\x,red] plot ({\x},{5*\x/(\x+1)});
105 |
106 | \draw[dashed] (-0.3,-1.5) -- (-0.3,4.9);
107 | \node[above left] at (-0.3,0) {$-1$};
108 | \draw[dashed] (-1.5,4.5) -- (5.5,4.5);
109 | \node[above right] at (0,4.5) {$4$};
110 | \node[below] at (4,0) {$3$};
111 | \draw[dotted] (4,0) -- (4,4);
112 |
113 | \draw (-1.5,-1.5) -- (5,5) node[left] {$P(t+1) = P(t)$};
114 |
115 | \draw[->,dotted] (1,0) -- (1,2.5);
116 | \draw[->,dotted] (1,2.5) -- (2.5,2.5);
117 | \draw[->,dotted] (2.5,2.5) -- (2.5,3.6);
118 | \draw[->,dotted] (2.5,3.6) -- (3.6,3.6);
119 | \draw[->,dotted] (3.6,3.6) -- (3.6,3.9);
120 | \draw[mark=*,red] plot coordinates {(4,4)} node[black,below right] {$\overline{P}_2$};
121 | \draw[mark=*,red] plot coordinates {(0,0)} node[black,below right] {$\overline{P}_1$};
122 | \draw[mark=*,blue] plot coordinates {(1,2.5)};
123 | \draw[mark=*,blue] plot coordinates {(2.5,3.6)};
124 | \draw[mark=*,blue] plot coordinates {(3.6,3.9)};
125 |
126 | \draw[->,red] (1.3,3.4) arc[radius=5,start angle=120,end angle=95];
127 | \node[red,rotate=19] at (2,3.9) {\tiny converges};
128 | \end{tikzpicture}
129 | \end{figure}
130 |
131 | If we start from $P_0=0$ (no uncertainty in the knowledge of $x(1)$) it converges into $\overline{P}_1=0$, the state equation is noise-free and we don't need feedback and the prediction is perfect (open-loop solution).
132 | This is a feasible but ideal situation.
133 |
134 | The standard solution (no perfect initial condition) is when $K=\frac{3}{2}$ (real closed-loop solution).
135 |
136 | \chapter{Software-sensing with Black-Box Methods}
137 |
138 | In chapter 3 we have seen classical technology of software-sensing based on Kalman Filter:
139 | \begin{figure}[H]
140 | \centering
141 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
142 | \node[left] at (0,4) (u) {$u(t)$};
143 | \node[int] at (2,4) (sys) {system};
144 | \node[int] at (2,2.3) (k) {$K$};
145 | \node[sum] at (4,2.3) (sum) {};
146 | \node[right] at (6,4) (y) {$y(t)$};
147 | \node[int] at (2,1) (model) {model};
148 | \node[above] at (2,5) (dist) {disturbances};
149 |
150 | \draw[->] (dist) -- (sys);
151 | \draw[->] (u) -- (sys);
152 | \draw[->] (sys) -- (y);
153 | \draw[<-,red,line width=0.4mm] (sum) -- (4,4) node[pos=0.2] {+};
154 | \draw[->] (sum) -- (k);
155 | \draw[->,red,line width=0.4mm] (1,4) |- (model);
156 | \draw[->] (k) -- (model);
157 | \draw[->] (model) -| (sum) node[pos=0.8] {-};
158 | \draw[->,red,line width=0.4mm,transform canvas={yshift=-0.2cm}] (model) -- (6,1) node[right] {$\hat{x}(t)$};
159 | \draw[dotted] (0,0) rectangle (5,3) node[right] {Kalman Filter};
160 | \end{tikzpicture}
161 | \end{figure}
162 |
163 | Main features of this approach:
164 | \begin{itemize}
165 | \item A (white-box/physical) model must be available.
166 | \item No need (in principle) of a training dataset including measurements of the state to be estimated.
167 | \item It is a feedback estimation algorithm (feedback correction of the model using estimated output error).
168 | \item Constructive method (non-parametric, no optimization involved).
169 | \item Can be used (in principle) to estimate states which are impossible to be measured (also at prototyping/training/design stage).
170 | \end{itemize}
171 |
172 | Are there other classes of software-sensing techniques? Yes, black-box approaches with \emph{learning}/\emph{training} from data.
173 |
174 | In this chapter we see them focusing on the architecture (we do not need new algorithms, just use something we have already studied).
175 |
176 | \section{Linear Time Invariant Systems}
177 |
178 | Let's consider a simplified case (SISO system with one state) to understand the approach.
179 | \[
180 | S: \begin{cases}
181 | x(t+1) = ax(t) + bu(t) + v_1(t) \\
182 | y(t) = cx(t) + v_2(t)
183 | \end{cases}
184 | \]
185 |
186 | \paragraph{Problem} Estimation of $\hat{x}(t)$ from measured signals $u(t)$ and $y(t)$.
187 |
188 | We can start from the observer K.F. architecture:
189 | \begin{figure}[H]
190 | \centering
191 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
192 | \node [left] (u) at (-4,4) {$u(t)$};
193 | \node [int] (b) at (-3,4) {$b$};
194 | \node [int] (z1) at (1,4) {$z^{-1}$};
195 | \node [int] (F1) at (1,3) {$a$};
196 | \node [int] (K) at (1,2) {$K$};
197 | \node [int] (z2) at (1,1) {$z^{-1}$};
198 | \node [int] (F2) at (1,0) {$a$};
199 |
200 | \node [int] (H1) at (4,4) {$c$};
201 | \node [int] (H2) at (4,1) {$c$};
202 |
203 | \node [sum] (sum1) at (6,4) {};
204 | \node [sum] (sum2) at (7,2) {};
205 | \node [sum] (sum3) at (-1.5,4) {};
206 | \node [sum] (sum4) at (-1.5,1) {};
207 |
208 | \node (v1) at (-1.5,5) {$v_1(t)$};
209 | \node (v2) at (6,5) {$v_2(t)$};
210 | \node[right] (y) at (8,4) {$y(t)$};
211 | \node[right] (yhat) at (8,1) {$\hat{y}(t|t-1)$};
212 | \node[right] (xhat) at (8,0) {$\hat{x}(t|t-1)$};
213 |
214 | \draw[->] (u) -- (b);
215 | \draw[->] (b) -- (sum3);
216 | \draw[->] (-2.2,4) |- (sum4);
217 | \draw[->] (v1) -- (sum3);
218 | \draw[->] (sum3) -- (z1) node[pos=0.5] {$x(t+1)$};
219 | \draw[->] (F1) -| (sum3);
220 | \draw[->] (z1) -- (H1) node[pos=0.5] {$x(t)$};
221 | \draw[->] (H1) -- (sum1);
222 | \draw[->] (v2) -- (sum1);
223 | \draw[->] (2.5,4) |- (F1);
224 | \draw[->] (K) -| (sum4);
225 | \draw[->,blue,line width=0.5mm] (sum4) -- (z2) node[pos=0.5,black] {$\hat{x}(t+1|t)$};
226 | \draw[<-] (sum2) -- (7,4) node[pos=0.2] {$+$};
227 | \draw[->] (sum1) -- (y);
228 | \draw[<-] (K) -- (sum2) node[pos=0.5,black] {$e(t)$};
229 | \draw[blue,line width=0.5mm] (z2) -- (2.5,1) node[pos=0.8,black] {$\hat{x}(t|t-1)$};
230 | \draw[->] (2.5,1) -- (H2) {};
231 | \draw[->,blue,line width=0.5mm] (F2) -| (sum4);
232 | \draw[->,blue,line width=0.5mm] (2.5,1) |- (F2);
233 | \draw[->] (H2) |- (yhat);
234 | \draw[->] (7,1) -- (sum2) node[pos=0.8] {$-$};
235 | \draw[->] (2.5,0) -- (xhat);
236 |
237 | \node[blue] at (-0.5,0.5) {$\frac{z^{-1}}{1-az^{-1}}$};
238 | \end{tikzpicture}
239 | \end{figure}
240 |
241 | Let's find the relationship between $u(t) \rightarrow \hat{x}(t)$ and $y(t) \rightarrow \hat{x}(t)$.
242 | \begin{align*}
243 | \hat{x}(t) &= \frac{b {\color{blue}\frac{z^{-1}}{1-az^{-1}}}}{1+Kc{\color{blue}\frac{z^{-1}}{1-az^{-1}}}} u(t) + \frac{ K{\color{blue}\frac{z^{-1}}{1-az^{-1}}} }{1+Kc{\color{blue}\frac{z^{-1}}{1-az^{-1}}}} y(t) \\
244 | &= \frac{b}{1+(Kc-a)z^{-1}}u(t-1) + \frac{K}{1+(Kc-a)z^{-1}} y(t-1)
245 | \end{align*}
246 |
247 | We can make a Black-Box estimation of these two transfer functions from data.
248 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-04-22.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{21/04/2020}
2 |
3 | \paragraph{Step 2} Singular Value Decomposition (SVD) of $\tilde{H}_{qd}$
4 |
5 | \[
6 | \underbrace{\tilde{H}_{qd}}_{q\times d} = \underbrace{\tilde{U}}_{q\times q} \underbrace{\tilde{S}}_{q\times d} \underbrace{\tilde{V}^T}_{d\times d}
7 | \]
8 |
9 | $\tilde{U}$ and $\tilde{V}$ are unitary matrices. A matrix $M$ is unitary if:
10 | \begin{itemize}
11 | \item $\det M = 1$ (so it's invertible)
12 | \item $M^{-1} = M^T$
13 | \end{itemize}
14 |
15 | \[
16 | \tilde{S} = \begin{bmatrix}
17 | \sigma_1 & & & & &\\
18 | & \sigma_2 & & & &\\
19 | & & \ddots & & &\\
20 | & & & \sigma_d & &\\
21 | \end{bmatrix}
22 | \]
23 |
24 | Where $\sigma_1$, $\sigma_2$, $\ldots$, $\sigma_q$ are the singular values of $\tilde{H}_{qd}$.
25 | Those are real, positive numbers, sorted in decreasing order ($\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_q$).
26 |
27 | \begin{rem}
28 | The singular values of a rectangular matrix are a \emph{sort of} eigenvalues of a square matrix.\\
29 | SVD is a \emph{sort of} diagonalization of a rectangular matrix.
30 | \end{rem}
31 |
32 | \begin{rem}
33 | For a square matrix, $\text{eig}(A) = \text{roots}(\det(A-\lambda I))$. If $M$ is rectangular, $SV(M) = \sqrt{\text{eig}(MM^T)}$ (for non zero eigenvalues).
34 | \end{rem}
35 |
36 | \begin{rem}[How to compute SVD]
37 | The optimal numerical computation is not trivial. Use \texttt{svd(M)} in Matlab.
38 |
39 | Theoretical method for SVD computation is to make 2 diagonalization steps:
40 | \[
41 | \underbrace{\tilde{H}_{qd} \tilde{H}_{qd}^T}_{q\times q} = \tilde{U}\tilde{S}\tilde{S}^T\tilde{U}^T
42 | \]
43 | \[
44 | \underbrace{\tilde{H}_{qd}^T \tilde{H}_{qd}}_{d\times d} = \tilde{V}\tilde{S}^T\tilde{S}\tilde{V}^T
45 | \]
46 | \end{rem}
47 |
48 | \paragraph{Step 3} Plot the singular values and cut-off the 3 matrices.
49 |
50 | \begin{figure}[H]
51 | \begin{minipage}[t]{0.5\textwidth}
52 | \centering
53 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
54 | \draw[->] (0,0) -- (5,0) node[right] {$i$};
55 | \draw[->] (0,0) -- (0,2) node[left] {$\sigma_i$};
56 | \node at (0.5,1.8) {\textbullet};
57 | \node at (1.0,1.3) {\textbullet};
58 | \node at (1.5,1.0) {\textbullet};
59 | \node at (2.0,0.9) {\textbullet};
60 | \node at (2.5,0.8) {\textbullet};
61 | \node at (3.0,0.2) {\textbullet};
62 | \node at (3.5,0.2) {\textbullet};
63 | \node at (4.0,0.2) {\textbullet};
64 | \node at (4.5,0.2) {\textbullet};
65 | \draw (2.5,-0.1) -- (2.5,0.1);
66 | \node at (2.5,-0.4) {$n$};
67 |
68 | \draw[decoration={brace}, decorate] (0.5,2) node {} -- (2.5,1);
69 | \node at (2.5,1.8) {signal SV};
70 |
71 | \draw[decoration={brace}, decorate] (3,0.4) node {} -- (4.5,0.4);
72 | \node at (3.75,0.8) {noise SV};
73 | \end{tikzpicture}
74 | \caption*{Ideal case}
75 | \end{minipage}
76 | \begin{minipage}[t]{0.5\textwidth}
77 | \centering
78 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
79 | \draw[->] (0,0) -- (5,0) node[right] {$i$};
80 | \draw[->] (0,0) -- (0,2) node[left] {$\sigma_i$};
81 | \node at (0.5,1.8) {\textbullet};
82 | \node at (1.0,1.3) {\textbullet};
83 | \node at (1.5,1.0) {\textbullet};
84 | \node at (2.0,0.8) {\textbullet};
85 | \node at (2.5,0.6) {\textbullet};
86 | \node at (3.0,0.4) {\textbullet};
87 | \node at (3.5,0.3) {\textbullet};
88 | \node at (4.0,0.2) {\textbullet};
89 | \node at (4.5,0.2) {\textbullet};
90 | \draw (2,-0.1) rectangle ++(1,0.2);
91 | \node at (2.5,-0.4) {$n$};
92 |
93 | \draw[decoration={brace}, decorate] (2,1) node {} -- (3,1);
94 | \node at (2.5,1.4) {transition};
95 | \end{tikzpicture}
96 | \caption*{Real case}
97 | \end{minipage}
98 | \end{figure}
99 |
100 | In the ideal case there is a perfect/clear separation between the signal and the noise S.V. (a jump).
101 | The index of the jump is $n$, that is the order of the system.
102 |
103 | In the real case there is no clear distinction between signal and noise singular values, the order of the system can assume values in an interval.
104 | With some empirical test we can select a good compromise between complexity, precision and overfitting (see \emph{cross-validation}).
105 |
106 | After the decision on the value of $n$ we split $\tilde{U}$, $\tilde{S}$ and $\tilde{V}^T$:
107 |
108 | \begin{figure}[H]
109 | \centering
110 | \begin{tikzpicture}
111 | \tikzset{BarreStyle/.style = {opacity=.3,line width=4 mm,color=blue}}
112 | \node (H) {$\tilde{H}_{qd} =$};
113 | \matrix (U) [right of=H, node distance=2cm,matrix of math nodes, nodes in empty cells,left delimiter={[},right delimiter={]},text depth=0ex,text height=1ex,text width=1ex]
114 | {
115 | & & & & \\
116 | & & & & \\
117 | \hat{U} & & \tilde{U} & & \\
118 | & & & & \\
119 | & & & & \\
120 | };
121 | \matrix (S) [right of=U,node distance=3cm,matrix of math nodes, nodes in empty cells,left delimiter={[},right delimiter={]},text depth=0ex,text height=1ex,text width=1ex]
122 | {
123 | \hat{S} & & & & \\
124 | & & & & \\
125 | & & \tilde{S} & & \\
126 | & & & & \\
127 | & & & & \\
128 | };
129 | \matrix (V) [right of=S,node distance=3cm,matrix of math nodes, nodes in empty cells,left delimiter={[},right delimiter={]},text depth=0ex,text height=1ex,text width=1ex]
130 | {
131 | & & \hat{V}^T & & \\
132 | & & & & \\
133 | & & \tilde{V}^T & & \\
134 | & & & & \\
135 | & & & & \\
136 | };
137 |
138 | \draw[decoration={brace}, decorate] (1,1.2) node {} -- (1.5,1.2);
139 | \node at (1.25,1.5) {$q\times n$};
140 | \draw[decoration={brace}, decorate] (4,1.2) node {} -- (4.5,1.2);
141 | \node at (4.25,1.5) {$n\times n$};
142 | \draw[decoration={brace}, decorate] (7,1.2) node {} -- (9,1.2);
143 | \node at (8,1.5) {$n\times d$};
144 |
145 | \draw [BarreStyle] (U-1-1.north) to (U-5-1.south);
146 | \draw [BarreStyle] (S-1-1.west) to (S-1-1.east);
147 | \draw [BarreStyle] (V-1-1.west) to (V-1-5.east);
148 | \end{tikzpicture}
149 | \end{figure}
150 |
151 |
152 | \[
153 | \tilde{H}_{qd} = \underbrace{\hat{U} \hat{S} \hat{V}^T}_{\hat{H}_{qd}} + H_{res,qd} \qquad \rank \tilde{H}_{qd} = q \quad \rank \hat{H}_{qd} = n \quad \rank H_{res,qd} = q
154 | \]
155 |
156 | From $\tilde{H}_{qd}$ to $\hat{H}_{qd}$ the rank is hugely reduced.
157 |
158 | \paragraph{Step 4} Estimation of $\hat{F}$, $\hat{G}$ and $\hat{H}$ using the cleaned matrix $\hat{H}_{qd}$
159 |
160 | \[
161 | \hat{H}_{qd} = \hat{U} \hat{S} \hat{V}^T = \hat{U} \hat{S}^{\frac{1}{2}} \hat{S}^{\frac{1}{2}} \hat{V}^T
162 | \]
163 |
164 | Where $\hat{S}^{\frac{1}{2}}$ is the matrix with elements the square roots of the elements of $\hat{S}$.
165 |
166 | \[
167 | \hat{O} = \hat{U} \hat{S}^{\frac{1}{2}} \qquad \hat{R} = \hat{S}^{\frac{1}{2}} \hat{V}^T \qquad \implies \qquad \hat{H}_{qd} = \hat{O} \hat{R}
168 | \]
169 |
170 | We can view $\hat{O}$ as the extended observability matrix and the $\hat{R}$ the extended reachability matrix of the system. We can estimate $\hat{H}$ with the first row of $\hat{O}$ and $\hat{G}$ with the first column of $\hat{R}$.
171 |
172 | What about the estimation of $\hat{F}$?
173 | Consider for example $\hat{O}$ and use the \emph{shift-invariance} property.
174 | Define $\hat{O}_1$ as $\hat{O}$ without the last row, and $\hat{O}_2$ as $\hat{O}$ without the first row.
175 |
176 | Therefore $\hat{O}_1\cdot \hat{F} = \hat{O}_2$, but $\hat{O}_1$ is not a square matrix so it's not invertible.
177 | In this case we can use the approximate \emph{least-square} solution of this linear system.
178 |
179 | Consider a generic system $Ax = B$ with dimension $(h\times n) \cdot (n \times 1) = (h \times 1)$, we have 3 different cases:
180 | \begin{enumerate}
181 | \item $h < n$. We have less equations than variables, the system is \emph{under determined} and we have infinite solutions.
182 | \item $h = n$, we have one and only one solution if $A$ is invertible.
183 | \item $h > n$, we have more equations than variables, the system is \emph{over determined} and it's impossible (no solutions).
184 | \end{enumerate}
185 |
186 | In the third case we can use an approximate solution using the least-squares method, which for a generic system is as follows:
187 | \begin{align*}
188 | Ax &= B \\
189 | A^TAx &= A^TB \implies \hat{X} = \underbrace{(A^TA)^{-1}A^T}_{A^+} B
190 | \end{align*}
191 |
192 | $A^+$ is called \emph{pseudo-inverse}, which is ``surrogate inverse'' when $A$ is rectangular.
193 |
194 | Using the pseudo-inverse matrix:
195 | \begin{align*}
196 | \hat{O}_1\hat{F} = \hat{O}_2 &&
197 | \hat{O}_1^T\hat{O}_1\hat{F} = \hat{O}_1^T\hat{O}_2 &&
198 | \hat{F} = \left(\hat{O}_1^T\hat{O}_1\right)^{-1} \hat{O}_1^T\hat{O}_2
199 | \end{align*}
200 |
201 |
202 | \paragraph{Conclusion} Starting from a noisy I.R. $\{\widetilde{\omega}(1), \widetilde{\omega}(2), \ldots, \widetilde{\omega}(N)\}$ we have estimated a model $\{\hat{F}, \hat{G}, \hat{H}\}$ in a non parametric and constructive way.
203 |
204 | \begin{rem}
205 | This method can be extended also to the case where the input signal is generic (i.e. not an impulse).
206 | \end{rem}
207 |
208 | \begin{rem}[Optimality of 4SID]
209 | The method is optimal in the sense that it makes the best possible rank reduction of $\tilde{H}_{qd}$.
210 | \end{rem}
211 |
212 | \begin{exa}[Rank reduction]
213 | In general there are infinite ways to make a rank reduction.
214 | \[
215 | \underbrace{\begin{bmatrix}
216 | 2 & 5 & 3 & 6 & 5 \\
217 | 5 & 3 & 6 & 5 & 7 \\
218 | 3 & 6 & 5 & 7 & 1
219 | \end{bmatrix}}_{\rank = 3}
220 | =
221 | \underbrace{\begin{bmatrix}
222 | 1 & 0 & 0 & 0 & 0 \\
223 | 0 & 1 & 0 & 0 & 0 \\
224 | 0 & 0 & 0 & 0 & 0
225 | \end{bmatrix}}_{\rank = 2}
226 | +
227 | \begin{bmatrix}
228 | 1 & 5 & 3 & 6 & 5 \\
229 | 5 & 2 & 6 & 5 & 7 \\
230 | 3 & 6 & 5 & 7 & 1
231 | \end{bmatrix}
232 | \]
233 | It's not the optimal rank reduction matrix, but it factors out a matrix with lower rank.
234 | \end{exa}
235 |
236 | Our goal is to obtain the desired rank reduction by discarding the minimum amount of information contained in the original matrix.
237 | SVD makes exactly this: $\tilde{H}_{res,qd}$ is the minimum possible (in the sense of the \emph{Frobenius norm}).
238 | \[
239 | \left|\tilde{H}_{res,qd}\right|_F = \sqrt{\sum_{ij} \left(\tilde{H}_{res,qd}^{(ij)} \right)^2}
240 | \]
241 |
242 | \begin{rem}
243 | 4SID is a constructive method that can be implemented in a fully-automatic way, except for these steps:
244 | \begin{itemize}
245 | \item $q$ and $d$ selection (not critical)
246 | \item Choice of $n$ (typically supervised by the designer). It can be made automatic using a cross-validation method.
247 | \end{itemize}
248 | \end{rem}
249 |
250 | \begin{rem}
251 | SVD was an historical turning point in machine learning algorithms because it allows:
252 | \begin{itemize}
253 | \item Very efficient compression of information.
254 | \item Very efficient separation of \emph{important} information from noise.
255 | \end{itemize}
256 | \end{rem}
257 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-06-03.tex:
--------------------------------------------------------------------------------
1 | \chapter{Recursive Identification}
2 | \newlecture{Stefano Dattilo}{03/06/2020}
3 |
4 | \begin{rem}[ARX syatem]
5 | \[
6 | y(t) = \frac{B(z)}{A(z)}u(t-1) + \frac{1}{A(z)}e(t) \qquad e(t) \sim WN(m_e, \lambda_e)
7 | \]
8 | \begin{align*}
9 | B(z) &= b_0 + b_1z^{-1} + \ldots + b_pz^{-p} \\
10 | A(z) &= 1 + a_1z^{-1} + \ldots + a_mz^{-m} \\
11 | \end{align*}
12 |
13 | \[
14 | y(t) = -a_1y(t-1) - \ldots - a_my(t-m) + b_0u(t-1) + \ldots b_pu(t-p-1) + e(t)
15 | \]
16 |
17 | \[
18 | \theta = \begin{bmatrix}
19 | a_1 \\ \vdots \\ a_m \\
20 | b_0 \\ \vdots \\ b_p
21 | \end{bmatrix} \qquad
22 | \phi(t) = \begin{bmatrix}
23 | -y(t-1) \\ \vdots \\ -y(t-m) \\
24 | u(t-1) \\ \vdots \\ u(t-p-1)
25 | \end{bmatrix}
26 | \qquad
27 | y(t) = \phi(t)^T\theta+e(t)
28 | \]
29 |
30 | \paragraph{Objective} Identify $\theta$ starting from an available dataset.
31 | \end{rem}
32 |
33 | \section{Least square}
34 |
35 | \[
36 | \hat{\theta}_N = \argmin_\theta \left\{ J_N(\theta) = \frac{1}{N} \sum_{t=1}^N \left( y(t) - \hat{y}(t|t-1, \theta) \right)^2 \right\}
37 | \]
38 |
39 | We need to find the model predictor $\hat{y}(t|t-1, \theta)$.
40 | \begin{align*}
41 | y(t) = \underbrace{\phi(t)^T\theta}_{\text{known at $t-1$}} + \underbrace{e(t)}_\text{unpredictable}
42 | \end{align*}
43 | $\hat{y}(t|t-1, \theta) = \phi(t)^T\theta$ is the best possible 1-step predictor.
44 |
45 | \[
46 | J_N(\theta) = \frac{1}{N}\sum_{t=1}^N \left( y(t) - \phi(t)^T\theta \right)^2
47 | \]
48 | It is possible to find $\hat{\theta}_N$ (the minimizer) explicitly:
49 | \[
50 | \hat{\theta}_N\text{ is such that } \frac{\partial J_N(\theta)}{\partial \theta} = 0
51 | \]
52 | \begin{align*}
53 | \hat{\theta}_N &= S(N)^{-1} \sum_{t=1}^N \phi(t)y(t) \\
54 | S(N) &= \sum_{t=1}^{N} \phi(t)\phi(t)^T
55 | \end{align*}
56 |
57 | This procedure has a drawback:
58 | \begin{figure}[H]
59 | \centering
60 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
61 | \node at (0,0.5) {$ \left\{ u(1), \ldots, u(N) \right\} $};
62 | \node at (0,0) {$ \left\{ y(1), \ldots, y(N) \right\} $};
63 | \node at (6,0.5) {$ \left\{ u(1), \ldots, u(N), u(N+1) \right\} $};
64 | \node at (6,0) {$ \left\{ y(1), \ldots, y(N), y(N+1) \right\} $};
65 | \node at (0,-0.8) {$\hat{\theta}_N$};
66 | \node at (6,-0.8) {$\hat{\theta}_{N+1}$};
67 |
68 | \draw[->] (1.8,0.25) -- (3.5,0.25) node[pos=0.5] {\footnotesize new data avail.};
69 | \end{tikzpicture}
70 | \end{figure}
71 |
72 | $\hat{\theta}_N$ is not used to compute $\hat{\theta}_{N+1}$, it is necessary to repeat all the computation.
73 | The solution is \emph{Recursive Least Square}.
74 |
75 | \section{Recursive Least Square}
76 |
77 | \begin{figure}[H]
78 | \centering
79 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
80 | \node[int, minimum height=1.5cm, minimum width=1.5cm] at (0,0) (RLS) {RLS};
81 | \draw[<-,transform canvas={yshift=0.4cm}] (RLS) -- (-1.5,0) node[left] {$\hat{\theta}_{N-1}$};
82 | \draw[<-,transform canvas={yshift=-0.4cm}] (RLS) -- (-1.5,0) node[left] {$\phi(N)$};
83 | \draw[->] (RLS) -- (1.5,0) node[right] {$\hat{\theta}_{N}$};
84 | \end{tikzpicture}
85 | \end{figure}
86 |
87 | \textbf{Advantages}
88 | \begin{itemize}
89 | \item Lower computational effort
90 | \item You save memory allocation
91 | \end{itemize}
92 |
93 | \subsection{First form}
94 |
95 | \paragraph{Objective} $\hat{\theta}_N = f(\hat{\theta}_{N-1}, \phi(N))$
96 |
97 | \begin{align}
98 | \hat{\theta}_N &= S(N)^{-1} \sum_{t=1}^N \phi(t)y(t) \\
99 | \sum_{t=1}^N \phi(t)y(t) &= S(N)\hat{\theta}_N \\
100 | \hat{\theta}_{N-1} &= S(N-1)^{-1} \sum_{t=1}^{N-1} \phi(t)y(t) \\
101 | \sum_{t=1}^{N-1} \phi(t)y(t) &= S(N-1)\hat{\theta}_{N-1} \\
102 | \sum_{t=1}^{N} \phi(t)y(t) &= \sum_{t=1}^{N-1} \phi(t)y(t) + \phi(N)y(N) \\
103 | \sum_{t=1}^{N} \phi(t)y(t) &= S(N-1)\hat{\theta}_{N-1} + \phi(N)y(N) = \text{ equation } (7.2) \\
104 | S(N) \hat{\theta}_N &= S(N-1) \hat{\theta}_{N-1} + \phi(N)y(N)
105 | \end{align}
106 |
107 | We need to find an expression of $S(N-1)$:
108 | \begin{align*}
109 | S(N) &= \sum_{t=1}^N \phi(t)\phi(t)^T = \underbrace{\sum_{t=1}^{N-1} \phi(t)\phi(t)^T}_{S(N-1)} + \phi(N)\phi(N)^T \\
110 | S(N-1) &= S(N) - \phi(N)\phi(N)^T \\
111 | S(N)\hat{\theta}_N &= \left( S(N) - \phi(N)\phi(N)^T \right)\hat{\theta}_{N-1} + \phi(N)y(N) \\
112 | S(N)\hat{\theta}_N &= S(N)\hat{\theta}_{N-1} - \phi(N)\phi(N)^T\hat{\theta}_{N-1} + \phi(N)y(N) \\
113 | \hat{\theta}_N &= \hat{\theta}_{N-1} + \underbrace{S(N)^{-1}\phi(N)}_{K(N)\text{ gain}}\underbrace{\left[ y(N) - \phi(N)^T\hat{\theta}_{N-1} \right]}_{\epsilon(N) \text{ prediction error}}
114 | \end{align*}
115 |
116 | \begin{align*}
117 | \hat{\theta}_N &= \hat{\theta}_{N-1} + K(N)\epsilon(N) \\
118 | K(N) &= S(N)^{-1}\phi(N) \\
119 | \epsilon(N) &= y(N) - \phi(N)^T\hat{\theta}_{N-1} \\
120 | S(N) &= S(N-1) + \phi(N)\phi(N)^T
121 | \end{align*}
122 |
123 | This method has a drawback: $S(N) - S(N-1) = \phi(N)\phi(N)^T \ge 0$, so $S(N) \rightarrow \infty$.
124 | It tends to saturate the numeric precision of the digital computing unit.
125 |
126 | \subsection{Second form}
127 |
128 | \paragraph{Trick} Normalize w.r.t. $N$
129 | \begin{align*}
130 | S(N) &= S(N-1) + \phi(N)\phi(N)^T \\
131 | R(N) &= \frac{1}{N} S(N) = \frac{1}{N} \frac{N-1}{N-1} S(N-1) + \frac{1}{N} \phi(N)\phi(N)^T \\
132 | &= \frac{N-1}{N}R(N-1) + \frac{1}{N}\phi(N)\phi(N)^T
133 | \end{align*}
134 |
135 | \begin{align*}
136 | \hat{\theta}_N &= \hat{\theta}_{N-1} + K(N)\epsilon(N) \\
137 | K(N) &= \frac{1}{N}R(N)^{-1}\phi(N) \\
138 | \epsilon(N) &= y(N) - \phi(N)^T\hat{\theta}_{N-1} \\
139 | R(N) &= \frac{N-1}{N}R(N-1) + \frac{1}{N}\phi(N)\phi(N)^T
140 | \end{align*}
141 |
142 | It has a drawback: matrix inversion at each time step.
143 | The solution is the recursive least square in third form.
144 |
145 | \subsection{Third form}
146 |
147 | \begin{lemma}[Matrix inversion]
148 | Consider 4 matrices $F$, $G$, $H$, $K$ such that:
149 | \begin{itemize}
150 | \item $F+GHK$ makes sense (dimensionally)
151 | \item $F$, $H$ and $F+GHK$ square and invertible
152 | \end{itemize}
153 | Then $(F+GHK)^{-1} = F^{-1} - F^{-1}G(H^{-1} + KF^{-1}G)^{-1}KF^{-1}$
154 | \end{lemma}
155 |
156 | In our case $S(N)^{-1} = (\underbrace{S(N-1)}_F + \underbrace{\phi(N)}_G \underbrace{1}_H \underbrace{\phi(N)^T}_K )^{-1}$
157 |
158 | \[
159 | S(N)^{-1} = S(N-1)^{-1} - \underbrace{S(N-1)^{-1}}_{\substack{\text{computed at}\\\text{previous step}}}\phi(N)\underbrace{\left[1 + \phi(N)^TS(N-1)\phi(N) \right]^{-1}}_\text{scalar}\phi(N)^TS(N-1)^{-1}
160 | \]
161 |
162 | Define $V(N) = S(N)^{-1}$
163 | \[
164 | V(N) = V(N-1) - \frac{V(N-1)\phi(N)\phi(N)^TV(N-1)}{1+\phi(N)^TV(N-1)\phi(N)}
165 | \]
166 | \begin{itemize}
167 | \item $V(N)$ does not tend to zero
168 | \item It's no more necessary to invert a matrix
169 | \end{itemize}
170 |
171 | \begin{align*}
172 | \hat{\theta}_N &= \hat{\theta}_{N-1} + K(N)\epsilon(N) \\
173 | K(N) &= V(N)\phi(N) \\
174 | \epsilon(N) &= y(N) - \phi(N)^T\hat{\theta}_{N-1} \\
175 | V(N) &= V(N-1) - \frac{V(N-1)\phi(N)\phi(N)^TV(N-1)}{1+\phi(N)^TV(N-1)\phi(N)}
176 | \end{align*}
177 |
178 | \begin{rem}
179 | RLS is a rigorous version of LS (not an approximation), provided a correct initialization.
180 |
181 | \begin{figure}[H]
182 | \centering
183 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
184 | \draw (0,0.2) -- (2.45,0.2) -- (2.45,0.7) -- (0,0.7) -- (0,0.2);
185 | \node at (1.225, 0.45) {\footnotesize Initialization};
186 | \draw (4.95, 0.2) -- (2.55, 0.2) -- (2.55, 0.7) -- (4.95, 0.7);
187 | \node at (3.75, 0.45) {\footnotesize RLS};
188 |
189 | \draw[->] (0,0) -- (5,0);
190 | \draw (2.5,0.1) -- (2.5,-0.1) node[below] {$t_0$};
191 | \end{tikzpicture}
192 | \end{figure}
193 |
194 | \begin{itemize}
195 | \item Collect a first set of data, till $t_0$
196 | \item Compute $\hat{\theta}_{t_0}$ and $S(t_0)$ with LS
197 | \item Use the recursive to update $\hat{\theta}_t$ and $S(t)$
198 | \end{itemize}
199 |
200 | In practice $\hat{\theta}_0 = 0$ and $S(0) = I$, the error due to the \emph{wrong} initialization will expire with time.
201 | \end{rem}
202 |
203 | \section{Recursive Least Square with Forgetting Factor}
204 |
205 | Consider a time varying parameter
206 | \begin{figure}[H]
207 | \centering
208 | \begin{minipage}[t]{0.48\textwidth}
209 | \centering
210 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
211 | \draw[->] (0,0) -- (5,0) node[below] {$t$};
212 | \draw[->] (0,0) -- (0,3) node[left] {$\alpha(t)$};
213 | \draw[domain=0:4.5,smooth,variable=\x] plot ({\x},{sin(\x*180/3.14*0.8+45)*0.8+1.2});
214 | \draw[dashed, fill] (0,0.45) -- (4.5,0.45) circle (1pt);
215 | \node[left] at (0,0.45) {$\hat{\alpha}_0$};
216 | \end{tikzpicture}
217 | \end{minipage}
218 | \begin{minipage}[t]{0.48\textwidth}
219 | \centering
220 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
221 | \draw[->] (0,0) -- (5,0) node[below] {$t$};
222 | \draw[->] (0,0) -- (0,3) node[left] {$\alpha(t)$};
223 | \draw[domain=0:4.5,smooth,variable=\x] plot ({\x},{sin(\x*180/3.14*0.8+45)*0.8+1.2});
224 | \draw[dashed, fill] (0,1.05) -- (4.5,1.05);
225 | \node[left] at (0,1.05) {$\hat{\alpha}_{LS}$};
226 | \end{tikzpicture}
227 | \end{minipage}
228 | \end{figure}
229 |
230 | $\hat{\alpha}_0$ is the correct estimation at time $N$, but it does not minimizes the objective function $J_N(\alpha)= \frac{1}{N} \sum_{t=1}^N \left( y(t) - \hat{y}(t|t-1, \alpha) \right)^2$ because it considers the entire time history of the system.
231 |
232 | In order to identify a time varying parameter the RLS must be forced to forget old data.
233 | The solution is provided by the minimization of $J_N$:
234 | \[
235 | J_N(\theta) = \frac{1}{N} \sum_{t=1}^N \rho^{N-t}\left( y(t) - \hat{y}(t|t-1,\theta) \right)^2
236 | \]
237 |
238 | Where $0 \le \rho \le 1$ is called \emph{forgetting factor}. If $\rho=1$ it's the previous formulation. If $\rho<1$ the old data has less importance than new data.
239 |
240 | \begin{align*}
241 | \hat{\theta}_N &= \hat{\theta}_{N-1} + K(N)\epsilon(N) \\
242 | K(N) &= S(N)^{-1}\phi(N) \\
243 | \epsilon(N) &= y(N) - \phi(N)^T\hat{\theta}_{N-1} \\
244 | S(N) &= \rho S(N-1) + \phi(N)\phi(N)^T
245 | \end{align*}
246 |
247 | \begin{rem}[Choice of $\rho$]
248 | \begin{figure}[H]
249 | \centering
250 | \begin{tikzpicture}[
251 | node distance=2cm,auto,>=latex',
252 | declare function={
253 | f1(\x) = atan(\x*1.5-2)/180*3+1.5;
254 | f2(\x) = f1(\x) + rand/4;
255 | f3(\x) = f1(\x-0.6) + rand/30;
256 | }]
257 | \draw[->] (0,0) -- (5,0) node[below] {$t$};
258 | \draw[->] (0,0) -- (0,3) node[left] {$\alpha(t)$};
259 |
260 | \node[right, red] at (5,2.5) {$\rho \ll 1$};
261 | \node[right, blue] at (5,2) {$\rho \approx 1$};
262 |
263 | \draw[domain=0:4.5,smooth,variable=\x] plot ({\x},{f1(\x)});
264 | \draw[domain=0:4.5,smooth,variable=\x,red] plot ({\x},{f2(\x)});
265 | \draw[domain=0:4.5,smooth,variable=\x,blue] plot ({\x},{f3(\x)});
266 | \end{tikzpicture}
267 | \end{figure}
268 |
269 | If $\rho \ll 1$ there's high tracking speed but low precision. With $\rho \approx 1$ there's low tracking speed but greater precision.
270 | \end{rem}
271 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-25.tex:
--------------------------------------------------------------------------------
1 | \chapter{Minimum Variance Control}
2 | \newlecture{Sergio Savaresi}{25/05/2020}
3 |
4 | Design and analysis of feedback systems.
5 | It's not system identification nor software sensing.
6 |
7 | \begin{itemize}
8 | \item Control design is the main motivation to system identification and software sensing.
9 | \item MVC is based on \emph{mathematics} of system identification and software sensing (prediction theory).
10 | \end{itemize}
11 |
12 | \paragraph{Setup of the problem} Consider a generic ARMAX model:
13 | \[
14 | y(t) = \frac{B(z)}{A(z)}u(t-k) + \frac{C(z)}{A(z)}e(t) \qquad e(t) \sim WN(0, \lambda^2)
15 | \]
16 | \begin{align*}
17 | B(z) &= b_0 + b_1z^{-1} + \dots + b_pz^{-p} \\
18 | A(z) &= 1 + a_1z^{-1} + \dots + a_mz^{-m} \\
19 | C(z) &= 1 + c_1z^{-1} + \dots + c_nz^{-n}
20 | \end{align*}
21 |
22 | Assumptions:
23 | \begin{itemize}
24 | \item $\frac{C(z)}{A(z)}$ is in canonical form
25 | \item $b_0\ne 0$ ($k$ is the actual delay)
26 | \item $\frac{B(z)}{A(z)}$ is \emph{minimum phase}
27 | \end{itemize}
28 |
29 | \begin{rem}
30 | $\frac{B(z)}{A(z)}$ is said to be \emph{minimum phase} if all the roots of $B(z)$ are strictly inside the unit circle.
31 |
32 | \begin{figure}[H]
33 | \centering
34 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
35 | \draw[->] (0,4) -- (0,7) node[left] {$u(t)$};
36 | \draw[->] (0,4) -- (5,4) node[below] {$t$};
37 | \draw[->] (0,0) -- (0,3) node[left] {$y(t)$};
38 | \draw[->] (0,0) -- (5,0) node[below] {$t$};
39 |
40 | \draw[line width=0.4mm] (0,4) -- (1,4) -- (1,6.5) -- (5,6.5);
41 | \draw[dotted] (1,0) -- (1,4);
42 | \draw[dotted] (0,2.5) -- (5,2.5) node[right] {\footnotesize steady state};
43 |
44 | \draw[domain=1:4.5,smooth,variable=\x,green,samples=70] plot ({\x},{2.5-2.5*(1-(\x-1)/3.5)^5});
45 | \draw[domain=1:4.5,smooth,variable=\x,green,samples=70] plot ({\x},{2.5-2.5*(1-(\x-1)/3.5)^5+sin(\x*180)/\x});
46 | \draw[domain=1:4.5,smooth,variable=\x,red,samples=70] plot ({\x},{2.5-2.5*(1-(\x-1)/3.5)^5+3*sin(\x*180)/(\x^2)});
47 |
48 | \node[red,right] at (1.5,-0.5) {\footnotesize not minimum-phase};
49 | \node[green,right] at (2,1.5) {\footnotesize minimum-phase};
50 | \end{tikzpicture}
51 | \end{figure}
52 |
53 | At the very beginning the response of a non-minimum phase system goes to the opposite direction w.r.t. the final value.
54 |
55 |
56 | Intuitively it's very difficult to control non-minimum phase systems.
57 | You can take the wrong decision if you react immediately.
58 |
59 | Also for human it's difficult, for example \emph{steer to roll} dynamics in a bicycle: if you want to steer left, you must first steer a little to the right and then turn left.
60 |
61 | Design of controller for non-minimum phase is difficult and requires special design techniques (no MVC but generalized MVC).
62 | \end{rem}
63 |
64 | The problem we wish to solve is optimal tracking of the desired behavior of output:
65 | \begin{figure}[H]
66 | \centering
67 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
68 | \node[int,ellipse,align=center] at (-1,0) (cont) {controller\\algorithm};
69 | \node[int] at (2.5,0) (ba) {$\frac{B(z)}{A(z)}$};
70 | \node[int] at (4,1.5) (ca) {$\frac{C(z)}{A(z)}$};
71 | \node[sum] at (4,0) (sum) {};
72 |
73 | \draw[dotted] (0.8,-1) rectangle (5,3.2) node[right] {system};
74 | \draw[->] (cont) -- (ba) node[pos=0.7] {$u(t)$};
75 | \draw[->] (ba) -- (sum);
76 | \draw[->] (ca) -- (sum);
77 | \draw[<-] (cont) -- ++(-2,0) node[left] {$y^0(t)$};
78 | \draw[<-] (ca) -- ++(0,1) node[above] {$e(t)$};
79 | \draw[->] (sum) -- ++(2,0) node[right] {$y(t)$};
80 | \draw[->] (5.5,0) -- (5.5,-1.5) -- (-1,-1.5) -- (cont);
81 | \end{tikzpicture}
82 | \end{figure}
83 |
84 | In a more formal way MVC tries to minimize this performance index:
85 | \[
86 | J = E\left[ (y(t) - y^0(t))^2 \right]
87 | \]
88 | It's the variance of the tracking error, that's why it's called Minimum Variance Control.
89 |
90 | Some additional (small) technical assumptions:
91 | \begin{itemize}
92 | \item $y^0(t)$ and $e(t)$ are not correlated (usually fulfilled)
93 | \item We assume that $y^0(t)$ is known only up to time $t$ (present time), we have no preview of the future desired $y^0(t)$ ($y^0(t)$ is totally unpredictable).
94 | \end{itemize}
95 |
96 | \begin{rem}
97 | There are 2 sub-classes of control problems:
98 | \begin{itemize}
99 | \item When $y^0(t)$ is constant or step-wise (regulation problem)
100 | \item When $y^0(t)$ is varying (tracking problem)
101 | \end{itemize}
102 |
103 | \begin{figure}[H]
104 | \centering
105 | \begin{minipage}[t]{0.48\textwidth}
106 | \centering
107 | \begin{tikzpicture}[
108 | node distance=2cm,auto,>=latex',
109 | declare function={
110 | f(\x) = (\x < 0.5) * 1 +
111 | (\x >= 0.5) * (\x < 2) * 2 +
112 | (\x >= 2) * (\x < 3) * 3 +
113 | (\x >= 3) * (\x < 4) * 1.5 +
114 | (\x >= 4) * 1;
115 | f2(\x) = (f(\x-0.5) + (f(\x) - f(\x-0.5)) / 720 +
116 | f(\x-0.4) + (f(\x) - f(\x-0.4)) / 120 +
117 | f(\x-0.3) + (f(\x) - f(\x-0.3)) / 24 +
118 | f(\x-0.2) + (f(\x) - f(\x-0.2)) / 6 +
119 | f(\x-0.1) + (f(\x) - f(\x-0.1)) / 2) / 5 +
120 | rand/8;
121 | }
122 | ]
123 | \draw[->] (0,0) -- (0,3) node[above] {$y(t)$};
124 | \draw[->] (0,0) -- (5,0) node[below] {$t$};
125 | \draw[domain=0:5,variable=\x,blue,samples=100] plot ({\x},{f(\x)});
126 | \draw[domain=0:5,variable=\x,red,smooth,samples=100] plot ({\x},{f2(\x)});
127 | \end{tikzpicture}
128 | \caption*{Regulation problem}
129 | \end{minipage}
130 | \begin{minipage}[t]{0.48\textwidth}
131 | \centering
132 | \begin{tikzpicture}[
133 | node distance=2cm,auto,>=latex',
134 | declare function={
135 | f(\x) = (sin(\x*180)/2+sin(\x*270)/2)+1.5;
136 | f2(\x) = (f(\x-0.3) + (f(\x) - f(\x-0.3)) / 24 +
137 | f(\x-0.2) + (f(\x) - f(\x-0.2)) / 6 +
138 | f(\x-0.1) + (f(\x) - f(\x-0.1)) / 2) / 3 +
139 | rand/8;
140 | }
141 | ]
142 | \draw[->] (0,0) -- (0,3) node[above] {$y(t)$};
143 | \draw[->] (0,0) -- (5,0) node[below] {$t$};
144 | \draw[domain=0:5,variable=\x,blue,samples=70] plot ({\x},{f(\x)});
145 | \draw[domain=0:5,variable=\x,red,smooth,samples=50] plot ({\x},{f2(\x)});
146 | \end{tikzpicture}
147 | \caption*{Tracking problem}
148 | \end{minipage}
149 | \end{figure}
150 | \end{rem}
151 |
152 | Bottom-up way of presenting M.V.C.
153 |
154 | \paragraph{Simplified problem \#1}
155 | \[
156 | S: y(t) = ay(t-1) + b_0u(t-1) + b_1u(t-2) \qquad y(t) = \frac{b_0+b_1z^{-1}}{1-az^{-1}}u(t-1)
157 | \]
158 |
159 | We assume that $y^0(t)=\overline{y}^0$ (regulation problem) and the system is noise-free.
160 | \begin{itemize}
161 | \item $b_0\ne 0$
162 | \item Root of numerator must be inside the unit circle
163 | \end{itemize}
164 |
165 | To design the minimum variance controller we must minimize the performance index:
166 | \[
167 | J = E\left[ (y(t) - y^0(t))^2 \right]
168 | \]
169 | There is no noise so we can remove the expected value
170 | \begin{align*}
171 | J &= \left( y(t) - y^0(t) \right)^2 = \left( y(t) - \overline{y}^0 \right)^2 = \left( ay(t-1)+b_0u(t-1)+b_1u(t-2) - \overline{y}^0 \right)^2 = \\
172 | &= \left( ay(t) + b_0u(t) + b_1u(t-1)-\overline{y}^0 \right)^2 \\
173 | \frac{\partial J}{\partial u(t)} &= 2\left( ay(t)+b_0u(t)+b_1u(t-1)-\overline{y}^0 \right)\left(b_0\right)
174 | \end{align*}
175 |
176 | Why the derivative is just $b_0$? We are at present time $t$ and at time $t$ the control algorithm must take a decision on the value of $u(t)$.
177 | At time $t$, $y(t)$, $y(t-1)$, \dots, $u(t-1)$, $u(t-2)$, \dots{} are no longer variables but numbers.
178 |
179 | \[
180 | \frac{\partial J}{\partial u(t)} = 0 \qquad ay(t)+b_0u(t)+b_1u(t-1)-\overline{y}^0 = 0 \\
181 | \]
182 | \[
183 | u(t) = \left( \overline{y}^0 - ay(t)\right)\frac{1}{b_0+b_1z^{-1}}
184 | \]
185 | \begin{figure}[H]
186 | \centering
187 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
188 | \node[sum] at (0,0) (sum) {};
189 | \node[int] at (1.5,0) (b1) {$\frac{1}{b_0+b_1z^{-1}}$};
190 | \node[int] at (5,0) (b2) {$z^{-1}\frac{b_0+b_1z^{-1}}{1-az^{-1}}$};
191 | \node[int] at (3,-1.5) (b3) {$a$};
192 |
193 | \draw[->] (sum) -- (b1);
194 | \draw[->] (b1) -- (b2) node[pos=0.5] {$u(t)$};
195 | \draw[->] (b3) -| (sum) node[pos=0.9] {-};
196 | \draw[<-] (sum) -- ++(-1.5,0) node[left] {$\overline{y}^0$} node[pos=0.2] {+};
197 | \draw[->] (b2) -- ++(2.5,0) node[right] {$y(t)$};
198 | \draw[->] (6.5,0) |- (b3);
199 | \end{tikzpicture}
200 | \end{figure}
201 |
202 | \paragraph{Simplified problem \#2}
203 | \[
204 | S: y(t) = ay(t-1) + b_0u(t-1) + b_1u(t-2) + e(t) \qquad e(t) \sim WN(0, \lambda^2)
205 | \]
206 |
207 | The reference variable is $y^0(t)$ (tracking problem).
208 |
209 | The performance index is
210 | \[
211 | J = E\left[ (y(t) - y^0(t))^2 \right]
212 | \]
213 |
214 | The fundamental trick to solve this problem is to re-write $y(t)$ as:
215 | \[
216 | y(t) = \hat{y}(t|t-1) + \epsilon(t)
217 | \]
218 |
219 | Since $k=1$ we know that $\epsilon(t) = e(t)$, so $y(t) = \hat{y}(t|t-1)+e(t)$.
220 | \begin{align*}
221 | J &= E\left[ \left(\hat{y}(t|t-1)+e(t) - y^0(t)\right)^2 \right] \\
222 | &= E\left[ \left((\hat{y}(t|t-1)-y^0(t)) +e(t)\right)^2 \right] \\
223 | &= E\left[ \left(\hat{y}(t|t-1)-y^0(t)\right)^2 \right] + E\left[e(t)^2\right] + \cancel{2E\left[e(t)\left( \hat{y}(t|t-1)-y^0(t) \right)\right]} \\
224 | \end{align*}
225 |
226 | Notice that
227 | \[
228 | \argmin_{u(t)} \left\{ E\left[ \left(\hat{y}(t|t-1)-y^0(t)\right)^2 \right] + \lambda^2 \right\} = \argmin_{u(t)} \left\{ E\left[ \left(\hat{y}(t|t-1)-y^0(t)\right)^2 \right] \right\}
229 | \]
230 | The best result is when $\hat{y}(t|t-1)=y^0(t)$, we can force this relationship.
231 |
232 | Now we must compute the 1-step predictor of the system:
233 | \[
234 | S: y(t) = \frac{b_0+b_1z^{-1}}{1-az^{-1}}u(t-1) + \frac{1}{1-az^{-1}}e(t)
235 | \]
236 | Note that this is an $ARMAX(1,0,1+1)=ARX(1,2)$.
237 | \[
238 | k=1 \qquad B(z) = b_0+b_1z^{-1} \qquad A(z)=1-az^{-1} \qquad C(z) = 1
239 | \]
240 |
241 | General solution for 1-step prediction of ARMAX:
242 | \[
243 | \hat{y}(t|t-1) = \frac{B(z)}{C(z)}u(t-1) + \frac{C(z)-A(z)}{C(z)}y(t)
244 | \]
245 | If we apply this formula we obtain:
246 | \[
247 | \hat{y}(t|t-1) = \frac{b_0+b_1z^{-1}}{1}u(t-1) + \frac{1-1+az^{-1}}{1}y(t) = (b_0+b_1z^{-1})u(t-1)+ay(t-1)
248 | \]
249 |
250 | Now we can impose that $\hat{y}(t|t-1)=y^0(t)$
251 | \[
252 | b_0u(t) + b_1u(t-1) + ay(t) = y^0(t+1) \qquad u(t) = \left( y^0(t+1) - ay(t) \right)\frac{1}{b_0+b_1z^{-1}}
253 | \]
254 | But we don't have $y^0(t+1)$, so we use $y^0(t)$.
255 | \[
256 | u(t) = \left( y^0(t) - ay(t) \right)\frac{1}{b_0+b_1z^{-1}}
257 | \]
258 | \begin{figure}[H]
259 | \centering
260 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
261 | \node[sum] at (0,0) (sum) {};
262 | \node[int] at (1.5,0) (b1) {$\frac{1}{b_0+b_1z^{-1}}$};
263 | \node[int] at (5,0) (b2) {$z^{-1}\frac{b_0+b_1z^{-1}}{1-az^{-1}}$};
264 | \node[int] at (3,-1.5) (b3) {$a$};
265 | \node[int] at (7,1.5) (b4) {$\frac{1}{1-az^{-1}}$};
266 | \node[sum] at (7,0) (sum2) {};
267 |
268 | \draw[->] (sum) -- (b1);
269 | \draw[->] (b1) -- (b2) node[pos=0.5] {$u(t)$};
270 | \draw[->] (b3) -| (sum) node[pos=0.9] {-};
271 | \draw[<-] (sum) -- ++(-1.5,0) node[left] {$y^0(t)$} node[pos=0.2] {+};
272 | \draw[->] (sum2) -- ++(1.5,0) node[right] {$y(t)$};
273 | \draw[->] (b2) -- (sum2);
274 | \draw[->] (b4) -- (sum2);
275 | \draw[<-] (b4) -- ++(0,1) node[above] {$e(t)$};
276 | \draw[->] (8,0) |- (b3);
277 | \end{tikzpicture}
278 | \end{figure}
279 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-04-21.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{21/04/2020}
2 |
3 | \begin{figure}[H]
4 | \centering
5 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
6 | \node (n1) {\#1};
7 | \node (n2) [below of=n1, xshift=-1.8cm] {\#2};
8 | \node (n3) [below of=n1, xshift= 1.8cm] {\#3};
9 |
10 | \draw[->] (n1) edge[bend right] (n2);
11 | \draw[->] (n2) edge[bend right] (n3);
12 | \draw[->] (n1) edge[bend left] (n3);
13 | \draw[->, dashed] (n2) edge[bend right=20] (n1);
14 | \draw[->, dotted] (n3) edge[bend right=20] (n2);
15 | \draw[->, dashed, red] (n3) edge[bend left=20] node {?} (n1);
16 | \end{tikzpicture}
17 | \end{figure}
18 |
19 | \section{Fundamental concepts of observability and controllability}
20 |
21 | \[
22 | \begin{cases}
23 | x(t+1) = Fx(t) + Gu(t) \\
24 | y(t) = Hx(t)
25 | \end{cases}
26 | \]
27 |
28 | \subsection{Fully Observable}
29 | The system is fully observable (from the output) if and only if the observability matrix is full rank:
30 | \[
31 | O = \begin{bmatrix}
32 | H \\
33 | HF \\
34 | \vdots \\
35 | HF^{n-1}
36 | \end{bmatrix}
37 | \qquad
38 | \rank O = n
39 | \]
40 |
41 | \subsection{Fully Controllable}
42 | The system is fully controllable (from the input) if and only if the controllability matrix is full rank:
43 | \[
44 | R = \begin{bmatrix}
45 | G & FG & \cdots & F^{n-1}G
46 | \end{bmatrix}
47 | \qquad
48 | \rank R = n
49 | \]
50 |
51 | $R$ is also called \emph{reachability} matrix.
52 |
53 | \begin{rem}
54 | \begin{description}
55 | \item[Observability] we can observe the state from the output sensors.
56 | \item[Controllability] we can control/move/influence the state using the input signal.
57 | \end{description}
58 | \end{rem}
59 |
60 | \begin{exa}
61 | \begin{align*}
62 | \begin{cases}
63 | x_1(t+1) = \frac{1}{2} x_1(t) + u(t) \\
64 | x_2(t+1) = \frac{1}{3}x_2(t) \\
65 | y(t) = \frac{1}{4}x_1(t)
66 | \end{cases}
67 | \qquad
68 | F = \begin{bmatrix}
69 | \frac{1}{2} & 0 \\
70 | 0 & \frac{1}{3}
71 | \end{bmatrix}
72 | \qquad
73 | H = \begin{bmatrix}
74 | \frac{1}{4} & 0
75 | \end{bmatrix}
76 | \qquad
77 | G = \begin{bmatrix}
78 | 1 \\
79 | 0
80 | \end{bmatrix}
81 | \end{align*}
82 |
83 | \[
84 | O = \begin{bmatrix}
85 | H \\
86 | HF
87 | \end{bmatrix} = \begin{bmatrix}
88 | \frac{1}{4} & 0 \\
89 | \frac{1}{8} & 0
90 | \end{bmatrix}
91 | \qquad
92 | \rank O = 1 < n = 2
93 | \quad\implies\quad \text{not fully observable}
94 | \]
95 |
96 | \[
97 | R = \begin{bmatrix}
98 | G & FG
99 | \end{bmatrix} = \begin{bmatrix}
100 | 0 & 0 \\
101 | 1 & \frac{1}{3}
102 | \end{bmatrix}
103 | \qquad
104 | \rank R = 1 < n = 2
105 | \quad\implies\quad \text{not fully controllable}
106 | \]
107 | \end{exa}
108 |
109 | \begin{rem}[4 sub-systems]
110 | Each system can be internally seen as 4 sub-systems as follows:
111 |
112 | \begin{figure}[H]
113 | \centering
114 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
115 | \node[int, align=center] (noc) {NO\\C};
116 | \node[int, align=center, below of=noc] (onc) {O\\NC};
117 | \node[int, align=center, below of=onc] (oc) {O\\C};
118 | \node[int, align=center, below of=oc] (nonc) {NO\\NC};
119 |
120 | \node at (-5cm,-1.5cm) (u) {$u$};
121 | \node[coordinate] at (-3cm,-1.5cm) (input) {};
122 | \node at (5cm,-2.5cm) (y) {$y$};
123 | \node[coordinate] at (3cm,-2.5cm) (output) {};
124 | \node[right of=noc] (noc_out) {};
125 | \node[right of=nonc] (nonc_out) {};
126 | \node[left of=onc] (onc_in) {};
127 |
128 | \draw[-{Rays[n=4]}] (noc) -- (noc_out);
129 | \draw[-{Rays[n=4]}] (nonc) -- (nonc_out);
130 | \draw[{Rays[n=4]}-] (onc_in) -- (onc);
131 | \draw (input) edge[->, bend left=10] (noc);
132 | \draw[line width=0.5mm] (input) edge[->, bend right=10] (oc);
133 | \draw[line width=0.5mm] (u) edge (input);
134 | \draw (onc) edge[bend left=10] (output);
135 | \draw[line width=0.5mm] (oc) edge[bend right=10] (output);
136 | \draw[line width=0.5mm] (output) edge[->] (y);
137 |
138 | \draw[draw=black] (-4cm,-5.5cm) rectangle ++(8cm,6.5cm);
139 | \end{tikzpicture}
140 | \end{figure}
141 |
142 | Which externally is equivalent to a systems like this:
143 | \begin{figure}[H]
144 | \centering
145 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
146 | \node[int, align=center] (oc) {O\\C};
147 | \node[left of=oc] (in) {$u$};
148 | \node[right of=oc] (out) {$y$};
149 |
150 | \draw[->] (in) -- (oc);
151 | \draw[->] (oc) -- (out);
152 | \end{tikzpicture}
153 | \end{figure}
154 | \end{rem}
155 |
156 | \section{Hankel matrix of order n}
157 |
158 | Starting from $IR = \{\omega(1), \omega(2), \ldots, \omega(N)\}$ we can build the Hankel matrix of order $n$.
159 |
160 | \[
161 | H_n = \begin{bmatrix}
162 | \omega(1) & \omega(2) & \omega(3) & \cdots & \omega(n) \\
163 | \omega(2) & \omega(3) & \omega(4) & \cdots & \omega(n+1) \\
164 | \omega(3) & \omega(4) & \omega(5) & \cdots & \omega(n+2) \\
165 | \vdots & \vdots & \vdots & \ddots & \vdots \\
166 | \omega(n) & \omega(n+1) & \omega(n+2) & \ldots & \omega(2n-1)
167 | \end{bmatrix}
168 | \]
169 |
170 | \textbf{Note} that we need IR up to time $2n-1$.
171 |
172 | \textbf{Note} it starts from $\omega(1)$ and not $\omega(0)$.
173 |
174 | \textbf{Note} the anti-diagonals all have the same element repeated.
175 |
176 | We know that $\omega(t) = \begin{cases}
177 | 0 &\quad \text{if } t = 0 \\
178 | HF^{t-1}G &\quad \text{if } t > 0
179 | \end{cases}$ therefore $H_n$ can be rewritten as
180 |
181 | \[
182 | H_n = \begin{bmatrix}
183 | HG & HFG & HF^2G & \cdots & HF^{n-1}G \\
184 | \vdots & \ddots & & & \vdots \\
185 | \vdots & & \ddots & & \vdots \\
186 | \vdots & & & \ddots & \vdots \\
187 | HF^{n-1}G & \cdots & \cdots & \cdots & HF^{2n-2}G
188 | \end{bmatrix} = \begin{bmatrix}
189 | H \\
190 | HF \\
191 | \vdots \\
192 | HF^{n-1}
193 | \end{bmatrix} \cdot \begin{bmatrix}
194 | G & FG & \cdots & F^{n-1}G
195 | \end{bmatrix} = O \cdot R
196 | \]
197 |
198 | Where $O$ is the observability matrix and $R$ is the reachability matrix.
199 |
200 | \section{Algorithm to obtain $\hat{F}$, $\hat{G}$, $\hat{H}$ from a noise-free measured IR}
201 |
202 | \paragraph{Step 1} Build the Hankel matrix in increasing order and each time compute the rank of the matrix.
203 |
204 | \[
205 | H_1 = \begin{bmatrix}
206 | \omega(1)
207 | \end{bmatrix}
208 | \qquad
209 | H_2 = \begin{bmatrix}
210 | \omega(1) & \omega(2) \\
211 | \omega(2) & \omega(3)
212 | \end{bmatrix}
213 | \qquad
214 | H_3 = \ldots
215 | \qquad
216 | \cdots
217 | \qquad
218 | H_n = \ldots
219 | \]
220 |
221 | Suppose that $\rank H_n = n$ and $\rank H_{n+1} = n$.
222 | With this procedure we know the order of the system.
223 |
224 | \paragraph{Step 2} Take $H_{n+1}$ (with $\rank H_{n+1} = n$), factorize it in two rectangular matrices of size $(n+1) \times n$ and $n \times (n+1)$.
225 |
226 | \[
227 | H_{n+1} = \begin{bmatrix}
228 | \text{extended} \\
229 | \text{observability} \\
230 | \text{matrix} \\
231 | O_{n+1}
232 | \end{bmatrix} \cdot \begin{bmatrix}
233 | \text{extended} \\
234 | \text{controllability} \\
235 | \text{matrix} \\
236 | R_{n+1}
237 | \end{bmatrix}
238 | \]
239 |
240 | Where $O_{n+1} = \begin{bmatrix}
241 | H \\ HF \\ \vdots \\ HF^n
242 | \end{bmatrix}$ of size $(n+1)\times n$ and $R_{n+1} = \begin{bmatrix}
243 | G & FG & \cdots & F^nG
244 | \end{bmatrix}$ of size $n\times (n+1)$.
245 |
246 | \paragraph{Step 3} $H$, $F$, $G$ estimation.
247 |
248 | Using $O_{n+1}$ and $R_{n+1}$ we can easily find:
249 | \begin{align*}
250 | \hat{G} = R_{n+1}(\texttt{:;1}) & \quad\text{first column} \\
251 | \hat{H} = O_{n+1}(\texttt{1;:}) & \quad\text{first row} \\
252 | \end{align*}
253 |
254 | Define $O_1$ as $O_{n+1}$ without the last row, and $O_2$ as $O_{n+1}$ without the first row.
255 | $O_1$ and $O_2$ are $n\times n$ matrices.
256 | This is called \emph{shift-invariance} property.
257 |
258 | \textbf{Note} that $O_1$ is invertible since it's an observability matrix and the subsystem is fully observable.
259 | Moreover $O_1F = O_2$, so $\hat{F} = O_1^{-1}O_2$.
260 |
261 | In conclusion in a simple and constructive way we have estimated a State Space model of the system $\{\hat{H}, \hat{G}, \hat{F}\}$ starting from measured IR, using only $2n+1$ samples of IR.
262 |
263 | \begin{rem}
264 | If the measurement is noisy all this process is useless.
265 | \end{rem}
266 |
267 | \section{Real problem}
268 |
269 | The measurements of IR are noisy: $\tilde{\omega}(t) = \omega(t) + \eta(t)$.
270 |
271 | \begin{figure}[H]
272 | \begin{minipage}[t]{0.5\textwidth}
273 | \centering
274 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
275 | \draw[->] (-0.5,0) -- (3,0) node[right] {$t$};
276 | \draw[->] (0,-1) -- (0,2) node[left] {$u(t)$};
277 | \draw[domain=-0.3:0,smooth,variable=\x,red] plot ({\x},{0});
278 | \draw[domain=0:0.2,smooth,variable=\x,red] plot ({\x},{1.5});
279 | \draw[domain=0.2:2.5,smooth,variable=\x,red] plot ({\x},{0});
280 | \end{tikzpicture}
281 | \caption*{Input}
282 | \end{minipage}
283 | \begin{minipage}[t]{0.5\textwidth}
284 | \centering
285 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
286 | \draw[->] (-0.5,0) -- (3,0) node[right] {$t$};
287 | \draw[->] (0,-1) -- (0,2) node[left] {$y(t)$};
288 | \draw[domain=0:2.5,smooth,variable=\x,red] plot ({\x},{cos(\x*180/3.14*5)*e^(-\x)});
289 | \draw[samples=100, domain=0:2.5,smooth,variable=\x,blue] plot ({\x},{cos(\x*180/3.14*5)*e^(-\x)+rand/4});
290 | \end{tikzpicture}
291 | \caption*{Output}
292 | \end{minipage}
293 | \end{figure}
294 |
295 | \section{4SID procedure (with noise)}
296 |
297 | \paragraph{Step 1} Build the Hankel matrix from data using ``one-shot'' all the available $N$ data points.
298 |
299 | \[
300 | \tilde{H}_{qd} = \begin{bmatrix}
301 | \tilde{\omega}(1) & \tilde{\omega}(2) & \cdots & \tilde{\omega}(d) \\
302 | \tilde{\omega}(2) & \tilde{\omega}(3) & \cdots & \tilde{\omega}(d+1) \\
303 | \vdots & \vdots & \ddots & \vdots \\
304 | \tilde{\omega}(q) & \tilde{\omega}(q+1) & \cdots & \tilde{\omega}(q+d-1) \\
305 | \end{bmatrix}
306 | \]
307 |
308 | $\tilde{H}_{qd}$ is a $q\times d$ matrix. \textbf{Note} that $q+d-1$ must equal to $N$ so that we use all the data set.
309 |
310 | \begin{rem}[Choice of $q$ and $d$]
311 | Hypothesis: $q=latex']
315 | \draw[->] (-0.5,0) -- (3,0) node[right] {$d$};
316 | \draw[->] (0,-0.5) -- (0,3) node[left] {$q$};
317 | \draw[domain=0.3:2.7,smooth,variable=\x,black] plot ({\x},{3-\x});
318 | \draw[line width=0.6mm,domain=1.5:1.8,smooth,variable=\x,green] plot ({\x},{3-\x});
319 | \draw[line width=0.6mm,domain=2.3:2.7,smooth,variable=\x,blue] plot ({\x},{3-\x});
320 | \draw[dotted] (0,0) -- (1.5,1.5);
321 |
322 | \node at (2.3,1.5) {$q \approx d$};
323 | \node at (3.1,0.7) {$q \ll d$};
324 |
325 | \node[below] at (0.3,0) {$1$};
326 | \node[below] at (2.7,0) {$N$};
327 | \node[left] at (0,0.3) {$1$};
328 | \node[left] at (0,2.7) {$N$};
329 | \end{tikzpicture}
330 | \end{figure}
331 |
332 | If $q \approx d$ the method has better accuracy.
333 | If $q \ll d$ it's computationally less intensive.
334 |
335 | If $0.6d < q < d$ we get to a good enough result.
336 | \end{rem}
337 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-04-16.tex:
--------------------------------------------------------------------------------
1 | \setcounter{chapter}{-1}
2 | \chapter{Introduction}
3 | \newlecture{Sergio Savaresi}{16/04/2020}
4 |
5 | \section{General topics of MIDA course}
6 |
7 | \begin{itemize}
8 | \item Collect digitally data from real systems
9 | \item Build black-box (gray-box) models from data, with emphasis on
10 | \begin{itemize}
11 | \item Dynamic systems
12 | \item Control/automation-oriented applications
13 | \end{itemize}
14 | \item Purpose of modelling (area of machine leasing focusing on ``control'')
15 | \begin{itemize}
16 | \item Prediction
17 | \item Software-sensing
18 | \item Modelling for control design
19 | \end{itemize}
20 | \end{itemize}
21 |
22 | \subsection{Super summary of MIDA 1}
23 | The focus is on \emph{time series} (output-only systems) and \emph{input/output} (I/O) systems.
24 |
25 | Models used in MIDA1:
26 | \begin{itemize}
27 | \item ARMA models for T.S.
28 | \item ARMAX models for I/O systems
29 | \end{itemize}
30 |
31 | \begin{figure}[H]
32 | \begin{minipage}[t]{0.4\textwidth}
33 | \centering
34 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
35 | \node [int] (a) {$\frac{C(z)}{A(z)}$};
36 | \node (b) [left of=a, node distance=2cm] {};
37 | \node (end) [right of=a, node distance=2cm]{};
38 | \draw[->] (b) edge node {$e(t)$} (a);
39 | \draw[->] (a) edge node {$y(t)$} (end);
40 | \end{tikzpicture}
41 | \caption*{ARMA model}
42 | \end{minipage}
43 | \begin{minipage}[t]{0.4\textwidth}
44 | \centering
45 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
46 | \node [int] (a) {$z^{-k}\frac{B(z)}{A(z)}$};
47 | \node (b) [left of=a, node distance=2cm] {};
48 | \node [sum] (c) [right of=a, node distance=2cm] {};
49 | \node [int] (d) [above of=c, node distance=1.5cm] {$\frac{C(z)}{A(z)}$};
50 | \node (e) [left of=d, node distance=2cm] {};
51 | \node (end) [right of=c, node distance=2cm]{};
52 | \draw[->] (b) edge node {$u(t)$} (a);
53 | \draw[->] (e) edge node {$e(t)$} (d);
54 | \draw[->] (a) edge node[pos=0.8] {$+$} (c);
55 | \draw[->] (d) edge node[pos=0.8] {$+$} (c);
56 | \draw[->] (c) edge node {$y(t)$} (end);
57 | \end{tikzpicture}
58 | \caption*{ARMAX model}
59 | \end{minipage}
60 | \end{figure}
61 |
62 | The model is indicated as $\mathcal{M}(\theta)$ where $\theta$ is the parameter vector, the coefficients of $A(z)$, $B(z)$, $C(z)$.
63 |
64 | A \textbf{parametric identification method} has been used: the \emph{performance index is defined}
65 | \begin{defn}
66 | $J(\theta) = \frac{1}{N} \sum_{t=1}^N \left(y(t) - \hat{y}(t|t-1, \theta)\right)^2$
67 | \end{defn}
68 |
69 | Which is the variance of the \emph{prediction error} made by the model. The optimal $\theta$ is $\hat{\theta}_N = \argmin_\theta J(\theta)$
70 |
71 | \subsection{MIDA 2}
72 |
73 | The focus is on I/O systems (more close to real applications than T.S.).
74 |
75 | \begin{description}
76 | \item[Chapter 1] non-parametric (direct/constructive) black-box identification of I/O systems using state-space models
77 | \item[Chapter 2] parametric identification fo black-box I/O systems, with a frequency-domain approach
78 | \item[Chapter 3] Kalman-filter for Sw-sensing using feedback on white-box models
79 | \item[Chapter 4] black-box methods for SW-sensing without feedback
80 | \item[Chapter 5] gray-box system identification using Kalman-filter and using \emph{simulation-error methods} (S.E.M,)
81 | \item[Chapter 6] Minimum-Variance Control (M.V.C.), design of optimal feedback controllers using the theory background of the MIDA course
82 | \item[Appendix] Recursive (online) implementation of algorithms for system identification
83 | \end{description}
84 |
85 | \section{Motivation example for the course: ABS}
86 |
87 | \begin{defn}
88 | \textbf{Slip} of the wheel: $\lambda = \frac{v-\omega r}{v}$
89 | \end{defn}
90 |
91 | During a break $0 \le \lambda \le 1$ (from free rolling wheel to locked wheel).
92 | \begin{figure}[H]
93 | \centering
94 | \resizebox{8cm}{!}{%
95 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex',scale=1.5]
96 | \draw[->] (-0.5,0) -- (2.5,0) node[right] {$\lambda$};
97 | \draw[->] (0,-0.5) -- (0,2.3) node[left] {$F_x$};
98 | \begin{scope}[scale=2]
99 | \draw[dotted] (0.23, 1) -- (0.23, 0) node[below] {$\bar{\lambda}$};
100 | \draw[dotted] (1, 0.75) -- (1, 0) node[below] {$1$};
101 | \node[red,rotate=-23] at (0.65,1) {unstable};
102 | \node[green!60!black,rotate=77] at (0.13,0.5) {stable};
103 | \begin{scope}
104 | \clip (0,0) rectangle (0.23, 2);
105 | \draw [green!60!black,line width=0.4mm] plot [smooth] coordinates {(0,0) (0.2, 1) (1, 0.75)};
106 | \end{scope}
107 | \begin{scope}
108 | \clip (0.23, 0) rectangle (1, 2);
109 | \draw [red,line width=0.4mm] plot [smooth] coordinates {(0,0) (0.2, 1) (1, 0.75)};
110 | \end{scope}
111 | \end{scope}
112 | \end{tikzpicture}
113 | }
114 | \caption*{Relation between $\lambda$ and the breaking force.}
115 | \end{figure}
116 |
117 | \begin{figure}[H]
118 | \centering
119 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
120 | \node [int] (abs) {ABS algo};
121 | \node [sum] (sum) [left of=abs, node distance=2cm] {};
122 | \node (in) [left of=sum, node distance=2cm] {};
123 | \node [int] (sys) [right of=abs, node distance=3cm]{System};
124 | \node [coordinate] (split) [right of=sys, node distance=2cm]{};
125 | \node (end) [right of=sys, node distance=4cm]{};
126 | \node [int] (sws) [below of=sys, node distance=1cm]{SW-sensing};
127 |
128 | \draw[->] (in) edge node {$\overline{\lambda}$} (sum);
129 | \draw[->] (sum) edge node {} (abs);
130 | \draw[->] (abs) edge node {$u(t)$} (sys);
131 | \draw[->] (sys) edge node[pos=0.8] {$\lambda$} (end);
132 | \draw[->] (split) |- node {} (sws);
133 | \draw[->] (sws) -| node[pos=0.9] {$-$} (sum);
134 | \end{tikzpicture}
135 | \caption*{ABS system}
136 | \end{figure}
137 |
138 | The problem can be divided into subproblems:
139 | \begin{itemize}
140 | \item Model of the system
141 | \item SW-estimation of $\lambda$ ($v$ is not directly measurable, so $\lambda$ cannot be computed)
142 | \item Design of the ABS control algorithm
143 | \end{itemize}
144 |
145 | Why black-box modelling?
146 | The control variable $v$ (the voltage to the actuator) controls a complex systems from the actuator to $\lambda$.
147 | The system can be seen as a chain of components:
148 | \begin{itemize}
149 | \item Current dynamics and electric motor
150 | \item Position dynamics of the actuator
151 | \item Dynamics of the hydraulic circuit of the break system
152 | \item Tire dynamics
153 | \item Wheel rotational dynamics
154 | \item Vehicle full dynamics
155 | \end{itemize}
156 |
157 | White box (physical) modelling: write the equations from \emph{first principles}.
158 |
159 | Black box modelling: experiment $\rightarrow$ collect data $\rightarrow$ build model.
160 | Using only I/O measured data we can \emph{learn} a mathematical model of the I/O behavior of the system.
161 |
162 | \chapter{Black-box non-parametric identification of I/O systems using state-space models}
163 |
164 | \begin{figure}[H]
165 | \centering
166 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
167 | \node [int, ellipse] (sys) {system};
168 | \node (in) [left of=sys, node distance=2cm] {};
169 | \node (noise) [above of=sys, node distance=1.5cm] {};
170 | \node (end) [right of=sys, node distance=2cm]{};
171 |
172 | \draw[->] (in) edge node {$u(t)$} (sys);
173 | \draw[->,dotted] (noise) edge node {$d(t)$ \emph{(not measured disturbance)}} (sys);
174 | \draw[->] (sys) edge node {$y(t)$} (end);
175 | \end{tikzpicture}
176 | \end{figure}
177 |
178 | \textbf{Measured data}
179 | \begin{align*}
180 | \left\{u(1), u(2), \ldots, u(N)\right\} &\quad \text{(input)} \\
181 | \left\{y(1), y(2), \ldots, y(N)\right\} &\quad \text{(output)}
182 | \end{align*}
183 |
184 | \begin{rem}[general path of a parametric identification methods]
185 |
186 | \begin{enumerate}
187 | \item Collect data: $\left\{u(1), u(2), \ldots, u(N)\right\}$, $\left\{y(1), y(2), \ldots, y(N)\right\}$
188 | \item Select \textbf{a-priori} a class/family of parametric models: $\mathcal{M}(\theta)$
189 | \item Select \textbf{a-priori} a performance index (it gives an order to the quality of the models)
190 | \item Optimization step (minimize $J(\theta)$ w.r.t $\theta$): $\hat{\theta}_N = \argmin_\theta J(\theta)$ $\rightarrow$ optimal model $\mathcal{M}(\hat{\theta}_N)$
191 | \end{enumerate}
192 |
193 | $J(\theta): \RR^{n_\theta} \rightarrow \RR^+$ (where $n_\theta$ is the order of the model).
194 |
195 | $\mathcal{M}(\theta_1)$ is better than $\mathcal{M}(\theta_2)$ if $J(\theta_1) < J(\theta_2)$.
196 |
197 | \end{rem}
198 |
199 | In this chapter we are presenting a totally different system identification approach: \textbf{not parametric}.
200 | \begin{itemize}
201 | \item No a-priori model-class selection
202 | \item No performance index definition
203 | \item No optimization task
204 | \end{itemize}
205 |
206 | \section{Representations}
207 |
208 | \subsection{Representation \#1: state-space}
209 |
210 | \[
211 | \begin{cases}
212 | x(t+1) = F x(t) + G u(t) & \qquad \text{state equations} \\
213 | y(t+1) = H x(t) + D u(t) & \qquad \text{output equations}
214 | \end{cases}
215 | \]
216 |
217 | Where $F$, $G$, $H$ and $D$ are matricies defined as follows:
218 | \begin{align*}
219 | F = \begin{bmatrix}
220 | \\
221 | n \times n \\
222 | \text{state matrix} \\ \\
223 | \end{bmatrix}
224 | &
225 | \qquad
226 | G = \begin{bmatrix}
227 | \\
228 | \\
229 | n \times 1 \\
230 | \text{input} \\
231 | \text{matrix} \\ \\
232 | \end{bmatrix}
233 | \\ \\
234 | H = \begin{bmatrix}
235 | 1 \times n \;\;\; \text{output matrix}
236 | \end{bmatrix}
237 | &
238 | \qquad
239 | D = \begin{bmatrix}
240 | 1 \times 1 \;\;\; \text{i/o matrix}
241 | \end{bmatrix}
242 | \end{align*}
243 |
244 | Assuming 1 input and 1 output, it can be extended for multiple inputs and outputs. Usually $D=0$ for \emph{strictly-proper systems}.
245 |
246 | \begin{rem}[S.S representation is not unique]
247 | $F_1 = TFT^{-1}$, $G_1 = TG$, $H_1 = HT^{-1}$, $D_1 = D$ for any invertible matrix $T$. The system $\{F, G, H, D\}$ is equivalent to $\{F_1, G_1, H_1, D_1\}$.
248 | \end{rem}
249 |
250 | \begin{exa}
251 | \[
252 | \begin{cases}
253 | x_1(t+1) = \frac{1}{2} x_1(t) + 2u(t) \\
254 | x_2(t+1) = x_1(t) + 2x_2(t) + u(t) \\
255 | y(t) = \frac{1}{4}x_1(t) + \frac{1}{2}x_2(t)
256 | \end{cases}
257 | \]
258 | In this case $n=2$, $x(t) = \begin{bmatrix}
259 | x_1(t) \\
260 | x_2(t)
261 | \end{bmatrix}$, one input $u(t)$ and one output $y(t)$.
262 |
263 | \begin{align*}
264 | F = \begin{bmatrix}
265 | \frac{1}{2} & 0 \\
266 | 1 & 2
267 | \end{bmatrix}
268 | & \qquad
269 | G = \begin{bmatrix}
270 | 2 \\ 1
271 | \end{bmatrix}
272 | \\
273 | H = \begin{bmatrix}
274 | \frac{1}{4} & \frac{1}{2}
275 | \end{bmatrix}
276 | & \qquad
277 | D = 0
278 | \end{align*}
279 | \end{exa}
280 |
281 | \subsection{Representation \#2: transfer-function}
282 |
283 | \[
284 | W(z) = \frac{B(z)}{A(z)} z^{-k} = \frac{b_0 + b_1z_{-1} + b_2z^{-2} + \ldots + b_pz^{-p}}{a_0 + a_1z^{-1} + a_2z^{-2} + \ldots + a_nz^{-n}} z^{-k}
285 | \]
286 |
287 | $W(z)$ is a rational function of the \emph{z} operator: it's a \emph{digital filter}.
288 |
289 | It's very easy to move from T.F. representation to a time domain description of the system.
290 |
291 | \begin{exa}
292 | \begin{align*}
293 | & y(t) = \underbrace{\begin{bmatrix}
294 | \frac{1+\frac{1}{2}z^{-1}}{2+\frac{1}{3}z^{-1}+\frac{1}{4}z^{-2}} z^{-1}
295 | \end{bmatrix}}_{W(z)} u(t) \\
296 | & 2y(t) + \frac{1}{3}y(t-1) + \frac{1}{4}y(t-2) = u(t-1) + \frac{1}{2}u(t-2) \\
297 | & y(t) = \underbrace{-\frac{1}{6}y(t-1) - \frac{1}{8}y(t-2)}_\text{old values of $y(t)$} + \underbrace{\frac{1}{2}u(t-1) + \frac{1}{4}u(t-2)}_\text{old values of input}
298 | \end{align*}
299 |
300 | \end{exa}
301 | \begin{rem}[Notational remark]
302 | $\displaystyle W(z) = \frac{z^{-1}}{1 + \frac{1}{3}z^{-1}}$ is called an IIR (\emph{Infinite Impulse Response}) filter.\\
303 | $\displaystyle W(z) = z^{-1} + \frac{1}{2}z^{-2} + \frac{1}{4}z^{-3}$ is called a FIR (\emph{Finite Impulse Response}) filter.
304 | \end{rem}
305 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-05.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{05/05/2020}
2 |
3 | \subsection{Block-scheme representation of K.F.}
4 | \begin{figure}[H]
5 | \centering
6 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
7 | \node [int] (z1) at (1,4) {$z^{-1}$};
8 | \node [int] (F1) at (1,3) {$F$};
9 | \node [int] (K) at (1,2) {$K(t)$};
10 | \node [int] (z2) at (1,1) {$z^{-1}$};
11 | \node [int] (F2) at (1,0) {$F$};
12 |
13 | \node [int] (H1) at (4,4) {$H$};
14 | \node [int] (H2) at (4,1) {$H$};
15 |
16 | \node [sum] (sum1) at (6,4) {};
17 | \node [sum] (sum2) at (7,2) {};
18 | \node [sum] (sum3) at (-1.5,4) {};
19 | \node [sum] (sum4) at (-1.5,1) {};
20 |
21 | \node (v1) at (-1.5,5) {$v_1(t)$};
22 | \node (v2) at (6,5) {$v_2(t)$};
23 | \node[right] (y) at (8,4) {$y(t)$};
24 | \node[right] (yhat) at (8,1) {$\hat{y}(t|t-1)$};
25 | \node[right] (xhat) at (8,0) {$\hat{x}(t|t-1)$};
26 |
27 | \node at (-1,2.3) {\emph{feedback}};
28 |
29 | \draw[->] (v1) -- (sum3);
30 | \draw[->] (sum3) -- (z1) node[pos=0.5] {$x(t+1)$};
31 | \draw[->] (F1) -| (sum3);
32 | \draw[->] (z1) -- (H1) node[pos=0.5] {$x(t)$};
33 | \draw[->] (H1) -- (sum1);
34 | \draw[->] (v2) -- (sum1);
35 | \draw[->] (2.5,4) |- (F1);
36 | \draw[->,red,line width=0.5mm] (K) -| (sum4);
37 | \draw[->] (sum4) -- (z2) node[pos=0.5] {$\hat{x}(t+1|t)$};
38 | \draw[->] (7,4) -- (sum2) node[pos=0.8] {$+$};
39 | \draw[->] (sum1) -- (y);
40 | \draw[<-,red,line width=0.5mm] (K) -- (sum2) node[pos=0.5,black] {$e(t)$};
41 | \draw[->] (z2) -- (H2) node[pos=0.5] {$\hat{x}(t|t-1)$};
42 | \draw[->] (F2) -| (sum4);
43 | \draw[->] (2.5,1) |- (F2);
44 | \draw[->] (H2) |- (yhat);
45 | \draw[->,red,line width=0.5mm] (7,1) -- (sum2) node[pos=0.8] {$-$};
46 | \draw[->] (F2) -- (xhat);
47 | \end{tikzpicture}
48 | \end{figure}
49 |
50 | The idea behind Kalman Filter is simple and intuitive:
51 | \begin{itemize}
52 | \item We make a simulated replica of the system (without noises $v_1$ and $v_2$, not measurable)
53 | \item We compare the true measured output with the estimated/simulated output $\hat{y}(t|t-1)$
54 | \item We make corrections on K.F. main equation, proportional (with gain $K(t)$) to the output error in order to keep K.F. as close as possible to the system
55 | \item We extract the state estimation $\hat{x}(t|t-1)$
56 | \end{itemize}
57 |
58 | Kalman Filter is a feedback system.
59 | Feedback here is not used for control, but for estimation.
60 |
61 | This general structure was known before Kalman Filter development, it's called \emph{state observer}.
62 | Fundamental contribution of Kalman was to find the optimal gain $K(t)$.
63 | $K(t)$ is not a simple scalar gain but is a (maybe very large) $n\times p$ matrix.
64 |
65 | The selection of gain matrix $K(t)$ is very critical:
66 | \begin{itemize}
67 | \item If $K(t)$ is \emph{too small}: the estimation is not optimal because we are \emph{under exploiting} the information in $y(t)$
68 | \item If $K(t)$ is \emph{too big}: risk of over-exploiting $y(t)$ and we can get noise amplification, even risk of instability
69 | \end{itemize}
70 |
71 | Design of Kalman Filter does not require a \emph{training dataset}, but a complete model of the system:
72 | \begin{itemize}
73 | \item $F$, $G$, $H$ matrixes: usually obtained with a white-box physical modelling of the system
74 | \item $V_1$, $V_2$ and $V_{12}$: $V_2$ is easily built from sensor specifications; $V_1$ much more difficult to be designed (it's the most critical design parameter of K.F.)
75 | \end{itemize}
76 |
77 | \section{Extensions of Basic Problem of Basic System}
78 |
79 | \subsection{Exogenous input}
80 | \begin{figure}[H]
81 | \centering
82 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
83 | \node [int] (z1) at (1,4) {$z^{-1}$};
84 | \node [int] (F1) at (1,3) {$F$};
85 | \node [int] (K) at (1,2) {$K(t)$};
86 | \node [int] (z2) at (1,1) {$z^{-1}$};
87 | \node [int] (F2) at (1,0) {$F$};
88 |
89 | \node [int] (H1) at (4,4) {$H$};
90 | \node [int] (H2) at (4,1) {$H$};
91 |
92 | \node [int] (G1) at (-3,4) {$G$};
93 | \node [int] (G2) at (-3,1) {$G$};
94 |
95 | \node[left] (u) at (-4,4) {$u(t)$};
96 |
97 | \node [sum] (sum1) at (6,4) {};
98 | \node [sum] (sum2) at (7,2) {};
99 | \node [sum] (sum3) at (-1.5,4) {};
100 | \node [sum] (sum4) at (-1.5,1) {};
101 |
102 | \node (v1) at (-1.5,5) {$v_1(t)$};
103 | \node (v2) at (6,5) {$v_2(t)$};
104 | \node[right] (y) at (8,4) {$y(t)$};
105 | \node[right] (yhat) at (8,1) {$\hat{y}(t|t-1)$};
106 | \node[right] (xhat) at (8,0) {$\hat{x}(t|t-1)$};
107 |
108 | \node at (-1,2.3) {\emph{feedback}};
109 |
110 | \draw[->,red,line width=0.5mm] (u) -- (G1);
111 | \draw[->,red,line width=0.5mm] (G1) -- (sum3);
112 | \draw[->,red,line width=0.5mm] (-3.8,4) |- (G2);
113 | \draw[->,red,line width=0.5mm] (G2) -- (sum4);
114 | \draw[->] (v1) -- (sum3);
115 | \draw[->] (sum3) -- (z1) node[pos=0.5] {$x(t+1)$};
116 | \draw[->] (F1) -| (sum3);
117 | \draw[->] (z1) -- (H1) node[pos=0.5] {$x(t)$};
118 | \draw[->] (H1) -- (sum1);
119 | \draw[->] (v2) -- (sum1);
120 | \draw[->] (2.5,4) |- (F1);
121 | \draw[->] (K) -| (sum4);
122 | \draw[->] (sum4) -- (z2) node[pos=0.5] {$\hat{x}(t+1|t)$};
123 | \draw[->] (7,4) -- (sum2) node[pos=0.8] {$+$};
124 | \draw[->] (sum1) -- (y);
125 | \draw[<-] (K) -- (sum2) node[pos=0.5,black] {$e(t)$};
126 | \draw[->] (z2) -- (H2) node[pos=0.5] {$\hat{x}(t|t-1)$};
127 | \draw[->] (F2) -| (sum4);
128 | \draw[->] (2.5,1) |- (F2);
129 | \draw[->] (H2) |- (yhat);
130 | \draw[->] (7,1) -- (sum2) node[pos=0.8] {$-$};
131 | \draw[->] (F2) -- (xhat);
132 | \end{tikzpicture}
133 | \end{figure}
134 |
135 | Notice that $K(t)$ remains the same because $P(t)$ is the covariance of the prediction error on $x(t)$ and remains the same because $Gu(t)$ doesn't introduce any additional noise or uncertainties to the system.
136 | $Gu(t)$ is a totally known (deterministic) signal.
137 |
138 | \subsection{Multi-step Prediction}
139 |
140 | Assume that $\hat{x}(t+1|t)$ is known from the basic solution, we can simply obtain a multi-step prediction as:
141 | \begin{align*}
142 | \hat{x}(t+2|t) &= F \hat{x}(t+1|t) \\
143 | \hat{x}(t+3|t) &= F \hat{x}(t+2|t) = F^2\hat{x}(t+1|t) \\
144 | \vdots \\
145 | \hat{x}(t+k|t) &= F^{k-1} \hat{x}(t+1|t) \\
146 | \hat{y}(t+k|t) &= H\hat{x}(t+k|t)
147 | \end{align*}
148 |
149 | \subsection{Filter ($\hat{x}(t|t)$)}
150 |
151 | \[
152 | \hat{x}(t+1|t) = F\hat{x}(t|t) \quad \implies \quad \hat{x}(t|t) = F^{-1}\hat{x}(t+1|t)
153 | \]
154 |
155 | This formula can be used only if the $F$ is invertible.
156 | If $F$ is not invertible, the filter can be obtained with a specific \emph{filter} formulation of K.F.
157 |
158 | Kalman Filter in the filter form is:
159 | \begin{align*}
160 | \hat{x}(t|t) &= F\hat{x}(t-1|t-1) + Gu(t-1) + K_0(t)e(t) \\
161 | \hat{y}(t|t-1) &= H\hat{x}(t|t-1) \\
162 | e(t) &= y(t) - \hat{y}(t|t-1) \\
163 | K_0(t) &= \left(P(t)H^T\right) \left(HP(t)H^T+V_2\right)^{-1} \\
164 | \text{DRE}& \text{ unchanged}
165 | \end{align*}
166 |
167 | \begin{rem}
168 | These equations are valid under the restrictive assumption $V_{12} = 0$.
169 | \end{rem}
170 |
171 | \begin{rem}
172 | Gain of K.F. in prediction form:
173 | \[
174 | K(t) = \left( FP(t)H^T \right) \left( HP(t)H^T+V_2 \right)^{-1}
175 | \]
176 |
177 | Gain of K.F. in filter form:
178 | \[
179 | K_0(t) = \left( \underline{\phantom{F}} P(t)H^T \right) \left( HP(t)H^T+V_2 \right)^{-1}
180 | \]
181 | \end{rem}
182 |
183 |
184 | \subsection{Time-varying systems}
185 |
186 | \[
187 | S: \begin{cases}
188 | x(t+1) = F(t)x(t) + G(t)u(t) + v_1(t) \\
189 | y(t) = H(t)x(t) + v_2(t)
190 | \end{cases}
191 | \]
192 |
193 | Kalman Filter equations are exactly the same.
194 |
195 | \subsection{Non Linear Systems}
196 |
197 | This extensions is much more complicated: Extended Kalman Filter (EKF).
198 |
199 | \section{Asymptotic Solution of K.F.}
200 |
201 | Observe that K.F. is not itself an LTI system but is a LTV system, because the gain $K(t)$ is time-varying.
202 |
203 | The fact that K.F. is a LTV system is the source of 2 problems:
204 | \begin{itemize}
205 | \item Checking the stability of K.F. algorithm is very difficult. The stability check of an LTV system is not simple as the stability check for LTI.
206 | \item Computational problem: $K(t)$ must be computed at each sampling time (e.g. every 5ms), including the inversion of $HP(t)H^T+V_2$ ($p\times p$ matrix).
207 | \end{itemize}
208 |
209 | \begin{rem}
210 | For LTI: $x(t+1) = Fx(t) + Gu(t)$ the stability check considers the eigenvalues of $F$.
211 |
212 | For LTV: $x(t+1) = F(t)x(t) + G(t)u(t)$, even if all the eigenvalues of $F(t)$ are strictly inside the unit circle at any time, the system is not guaranteed to be asymptotically stable.
213 | In practice it is, if the time-variations are \emph{slow}, like in aging.
214 | \end{rem}
215 |
216 | Because of those problems in real/practical applications the asymptotic version of K.F. is preferred.
217 |
218 | \paragraph{Basic idea}
219 | If $P(t)$ converges to a constant value $\overline{P}$ (steady-state value of $P(t)$), then also $K(t)$ will converge to $\overline{K}$ (steady-state value of $K(t)$).
220 | Using $\overline{K}$ the K.F. becomes an LTI system.
221 |
222 | Let's analyze the asymptotic stability of K.F. when $\overline{K}$ is used (assuming it exists).
223 |
224 | \begin{align*}
225 | \hat{x}(t+1|t) &= F\hat{x}(t|t-1) + Gu(t) + \overline{K}e(t) \\
226 | &= F\hat{x}(t|t-1) + Gu(t) + \overline{K}(y(t) - \hat{y}(t|t-1)) \\
227 | &= F\hat{x}(t|t-1) + Gu(t) + \overline{K}(y(t) - H\hat{x}(t|t-1)) \\
228 | &= \underbrace{(F - \overline{K}H)}_{\text{new state matrix}} \hat{x}(t|t-1) + Gu(t) + \overline{K}y(t)
229 | \end{align*}
230 |
231 | \begin{figure}[H]
232 | \centering
233 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
234 | \node[int] (K) at (1,1) {$\overline{K}$};
235 | \node[int] (G) at (1,2) {$G$};
236 | \node[sum] (sum) at (3,1) {};
237 | \node[int] (z) at (6,1) {$z^{-1}$};
238 | \node[int] (fb) at (6,0) {$F-\overline{K}H$};
239 |
240 | \node[left] (y) at (0,1) {$y(t)$};
241 | \node[left] (u) at (0,2) {$u(t)$};
242 |
243 | \draw[->] (y) -- (K);
244 | \draw[->] (u) -- (G);
245 | \draw[->] (K) -- (sum);
246 | \draw[->] (sum) -- (z) node[pos=0.5] {$\hat{x}(t+1|t)$};
247 | \draw[->] (z) -- (9,1) node[pos=0.5] {$\hat{x}(t|t-1)$};
248 | \draw[->] (fb) -| (sum);
249 | \draw[->] (G) -| (sum);
250 | \draw[->] (7.5,1) |- (fb);
251 | \end{tikzpicture}
252 | \end{figure}
253 |
254 | If $\overline{K}$ exists, the K.F. is asymptotically stable if and only if all the eigenvalues of $F-\overline{K}H$ are strictly inside the unit circle.
255 |
256 | \begin{rem}
257 | The stability of the system $S$ is related to matrix $F$, whereas the stability of K.F. is related to matrix $F-\overline{K}H$.
258 |
259 | K.F. can be asymptotically stable even if the system is unstable.
260 | \end{rem}
261 |
262 | \paragraph{Existance of $\overline{K}$}
263 |
264 | \[
265 | \overline{K} = \left(F\overline{P}H^T + V_{12}\right)\left(H\overline{P}H^T+V_2\right)^{-1}
266 | \]
267 |
268 | $\overline{K}$ exists if $\overline{P}$ exists.
269 | We need to check the converge properties of D.R.E.
270 |
271 | To find the equilibrium of a dynamical autonomous system:
272 |
273 | \begin{center}
274 | \begin{tabular}{c|c}
275 | \textbf{Continuous time} & \textbf{Discrete time} \\
276 | \hline
277 | $\dot{x} = f(x)$ & $x(t+1) = f(x(t))$ \\
278 | equilibrium when $\dot{x} = 0$ & equilibrium when $x(t+1) = x(t)$ \\
279 | $f(\overline{x}) = 0$ & $f(\overline{x}) = \overline{x}$ \\
280 | \end{tabular}
281 | \end{center}
282 |
283 | D.R.E. is an autonomous discrete time system:
284 | \[
285 | \overline{P} = f(\overline{P}) = \left( F\overline{P}F^T + V_1 \right)-\left(F\overline{P}H^T + V_{12}\right)\left(H\overline{P}H^T + V_2\right)^{-1}\left(F\overline{P}H^T+V_{12}\right)^T
286 | \]
287 |
288 | It's a non linear algebraic equation, known as Algebraic Riccati Equation (A.R.E.).
289 |
290 | If a steady state $\overline{P}$ solution of D.R.E. does exists, it must be a solution of A.R.E.
291 | There remains 3 questions:
292 | \begin{description}
293 | \item[Existence] Does A.R.E. have a semi-definite positive solution?
294 | \item[Convergence] If exists, does the D.R.E. converges to $\overline{P}$?
295 | \item[Stability] Is the corresponding $\overline{K}$ such that the K.F. is asymptotically stable?
296 | \end{description}
297 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-04.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{04/05/2020}
2 |
3 | \paragraph{Key questions for software sensing}
4 |
5 | \begin{itemize}
6 | \item Is software-sensing feasible? Test is the observability of the states from measured outputs.
7 | \item Quality of estimation error (\emph{noise of measurement} for the software sensor).
8 | \end{itemize}
9 |
10 | \begin{exa}[Slip estimation for ABS/traction control]
11 | \begin{figure}[H]
12 | \centering
13 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
14 | \draw (0.5,0) -- (0,0) -- (0,0.5) -- (1,0.5) -- (1.5,1) -- (2.5,1) -- (2.8,0.5) -- (3.3,0.5) -- (3.3,0) -- (3.1,0);
15 | \draw (1.1,0) -- (2.5,0);
16 | \draw (0.8,0) circle (0.3);
17 | \draw (2.8,0) circle (0.3);
18 |
19 | \draw[->] (-0.1,0.5) -- (-0.6,0.5) node[left] {$v$};
20 | \draw[->] (0.8,0) -- (0.8,-0.3) node[below] {$r$};
21 | \draw[->] (1.146,0.2) arc[radius=0.4, start angle=30, end angle=90];
22 | \node at (1.3,0.5) {$\omega$};
23 | \end{tikzpicture}
24 | \end{figure}
25 |
26 | \paragraph{Problem} Estimation of $v$.
27 |
28 | Measure of $v$ can be done with:
29 | \begin{itemize}
30 | \item Optical sensor
31 | \item GPS
32 | \end{itemize}
33 | Both have a problem of availability (not guaranteed). Physical sensing is not an option for industrial production.
34 |
35 | Intuitive solution: install a longitudinal accelerometer ($a_x$) and integrate.
36 | \begin{figure}[H]
37 | \centering
38 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
39 | \draw (0.5,0) -- (0,0) -- (0,0.5) -- (1,0.5) -- (1.5,1) -- (2.5,1) -- (2.8,0.5) -- (3.3,0.5) -- (3.3,0) -- (3.1,0);
40 | \draw (1.1,0) -- (2.5,0);
41 | \draw (0.8,0) circle (0.3);
42 | \draw (2.8,0) circle (0.3);
43 |
44 | \draw[->] (2.3,0.5) -- (1.7,0.5) node[above] {$a_x$};
45 | \end{tikzpicture}
46 | \end{figure}
47 | \[
48 | \hat{v} = \int a_x(t) dt \qquad \iff \qquad a_x(t) \rightarrow 1/s \rightarrow \hat{v}(t)
49 | \]
50 |
51 | In discrete time domain: discretization using approximation of derivative (Eulero forward method)
52 | \[
53 | \frac{d}{dt} v(t) = a_x(t) \qquad \frac{dv(t)}{dt} \approx \frac{v(t+1)-v(t)}{\Delta T_s} = a_x(t)
54 | \]
55 |
56 | Where $\Delta T_s$ is the sampling interval (e.g. 10ms).
57 |
58 | \[
59 | \hat{v}(t) = \hat{v}(t-1) + \Delta T_s a_x(t-1)
60 | \]
61 |
62 | \begin{figure}[H]
63 | \centering
64 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
65 | \node [int] (sys) {$\frac{\Delta T_s}{1-z^{-1}}$};
66 | \node (in) [left of=sys, node distance=2cm] {};
67 | \node (end) [right of=sys, node distance=2cm]{};
68 |
69 | \draw[->] (in) edge node {$a_x(t)$} (sys);
70 | \draw[->] (sys) edge node {$\hat{v}(t)$} (end);
71 | \end{tikzpicture}
72 | \end{figure}
73 |
74 | Unfortunately the measured signal is not $a_x(t)$ but $a_x(t)+d_{a_x}(t)$.
75 |
76 | \begin{figure}[H]
77 | \centering
78 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
79 | \begin{axis}[axis lines=none,ymax=6]
80 | \addplot[color=blue,smooth]
81 | coordinates {
82 | (0.00,2.35)(0.40,2.87)(0.80,2.99)(1.20,2.75)(1.60,2.83)(2.00,2.86)(2.40,3.19)(2.80,2.76)(3.20,2.45)(3.60,2.85)(4.00,2.55)(4.40,2.50)(4.80,2.64)(5.20,2.72)(5.60,3.26)(6.00,3.68)(6.40,3.95)(6.80,3.9)(7.20,4.00)(7.60,3.51)
83 | };
84 | \addplot[color=red,smooth]
85 | coordinates {
86 | (0.00,2.35)(0.40,2.91)(0.80,3.07)(1.20,2.87)(1.60,2.99)(2.00,3.06)(2.40,3.43)(2.80,3.04)(3.20,2.77)(3.60,3.21)(4.00,2.95)(4.40,2.94)(4.80,3.12)(5.20,3.24)(5.60,3.82)(6.00,4.28)(6.40,4.59)(6.80,5.17)(7.20,5.0)(7.60,5.27)
87 | };
88 | \draw[->] (-0.5,0) -- (800,0) node[right] {$t$};
89 | \draw[->] (0.5,-0.5) -- (0.5,300) node[left] {};
90 | \end{axis}
91 | \end{tikzpicture}
92 | \end{figure}
93 |
94 | Integrating noise generates a \emph{drift}. Integrator is not an asymptotic stable system.
95 |
96 | \begin{figure}[H]
97 | \centering
98 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
99 | \node [int] (sys) {$\frac{\Delta T_s}{1-z^{-1}}$};
100 | \node [sum] (in) [left of=sys, node distance=1.5cm] {};
101 | \node (in1) [above of=in, node distance=1cm] {$d_{a_x}(t)$};
102 | \node (in2) [below of=in, node distance=1cm] {$a_x(t)$};
103 | \node (end) [right of=sys, node distance=2cm]{};
104 |
105 | \draw[->] (in) -- (sys);
106 | \draw[->] (in1) -- (in) node[left, pos=0.8] {$+$};
107 | \draw[->] (in2) -- (in) node[left, pos=0.8] {$+$};
108 | \draw[->] (sys) edge node {$\hat{v}(t)$} (end);
109 | \end{tikzpicture}
110 | \end{figure}
111 |
112 | \paragraph{Solution} Use a Kalman Filter.
113 |
114 | \begin{figure}[H]
115 | \centering
116 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
117 | \node [int, align=center, minimum width=3cm] (sys) {car};
118 | \node [int, align=center, minimum width=3cm, below of=sys] (algo) {Kalman Filter};
119 | \node (algoout) [right of=algo, node distance=3cm] {$\hat{v}(t)$};
120 |
121 | \draw[->,transform canvas={xshift=-1.2cm}] (sys) -- (algo) node[pos=0.5] {$\omega_1$};
122 | \draw[->,transform canvas={xshift=-0.6cm}] (sys) -- (algo) node[pos=0.5] {$\omega_2$};
123 | \draw[->] (sys) -- (algo) node[pos=0.5] {$\omega_3$};
124 | \draw[->,transform canvas={xshift=0.6cm}] (sys) -- (algo) node[pos=0.5] {$\omega_4$};
125 | \draw[->,transform canvas={xshift=1.2cm}] (sys) -- (algo) node[pos=0.5] {$a_x$};
126 |
127 | \draw[->] (algo) -- (algoout);
128 | \end{tikzpicture}
129 | \end{figure}
130 | \end{exa}
131 |
132 | \begin{exa}[State of charge estimation of a battery]
133 | \begin{figure}[H]
134 | \centering
135 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
136 | \draw (0,0) rectangle ++(1.5cm,3cm);
137 | \draw (0.6cm,3cm) rectangle ++(0.3,0.15);
138 |
139 | \draw [pattern=north west lines, pattern color=green] (0,0) rectangle (1.5,2);
140 |
141 | \draw [decorate,decoration={brace,amplitude=10pt}] (0,0) -- (0,3) node [black,midway,align=right,xshift=-0.3cm] {100\%};
142 | \draw [decorate,decoration={brace,amplitude=10pt}] (1.5,2) -- (1.5,0) node [black,midway,align=right,xshift=0.3cm] {SoC};
143 |
144 | \node [int, align=center] (sys) at (6,1.5) {SoC\\internal\\state};
145 | \node [left of=sys, node distance=2cm] (in1) {$i(t)$};
146 | \node [above of=sys, node distance=2cm] (in2) {$T(t)$};
147 | \node [right of=sys, node distance=2cm] (out) {$v(t)$};
148 |
149 | \draw[->] (in1) -- (sys);
150 | \draw[->] (in2) -- (sys);
151 | \draw[->] (sys) -- (out);
152 | \end{tikzpicture}
153 | \end{figure}
154 | \[
155 | \text{SoC}(t) = 1 - \frac{\int i(t)dt}{I} \qquad 0 \le \text{SoC} \le 1
156 | \]
157 | Where $I$ is the total amount of \emph{current} that can be extracted by the user of the battery.
158 | This solution is not feasible since it integrates the noise on $i(t)$.
159 | \end{exa}
160 |
161 | \section{Kalman Filter on Basic Systems}
162 |
163 | \begin{itemize}
164 | \item No external inputs ($\cancel{Gu(t)}$): time series
165 | \item Linear systems
166 | \item Time invariant systems
167 | \end{itemize}
168 |
169 | After the description of the solution of Kalman Filter for the basic system, we make the extensions to a more general system, in particular with $Gu(t)$.
170 |
171 | \subsection{Detailed description of Basic System}
172 |
173 | \[
174 | S: \begin{cases}
175 | x(t+1) = Fx(t) + \cancel{Gu(t)} + v_1(t) & \text{state equation}\\
176 | y(t) = Hx(t) + v_2(t) & \text{output equation}
177 | \end{cases}
178 | \]
179 | \[
180 | x(t) = \begin{bmatrix}
181 | x_1(t) \\
182 | x_2(t) \\
183 | \vdots \\
184 | x_n(t)
185 | \end{bmatrix}
186 | \qquad
187 | \left(\;u(t) = \begin{bmatrix}
188 | u_1(t) \\
189 | u_2(t) \\
190 | \vdots \\
191 | u_m(t)
192 | \end{bmatrix}\;\right)
193 | \qquad
194 | y(t) = \begin{bmatrix}
195 | y_1(t) \\
196 | y_2(t) \\
197 | \vdots \\
198 | y_p(t)
199 | \end{bmatrix}
200 | \]
201 |
202 | System with $n$ states, ($m$ inputs) and $p$ outputs.
203 |
204 | $v_1(t)$ is a vector white-noise.
205 | \[
206 | v_1(t) \sim WN(0, V_1) \qquad v_1(t) = \begin{bmatrix}
207 | v_{11}(t) \\
208 | v_{12}(t) \\
209 | \vdots \\
210 | v_{1n}(t)
211 | \end{bmatrix}
212 | \]
213 |
214 | $v_1(t)$ is called state noise or model noise.
215 | It accounts for the modelling errors of the state equation of the system.
216 |
217 | \begin{itemize}
218 | \item $E[v_1(t)] = \vec{0}$
219 | \item $E[v_1(t) \cdot v_1(t)^T] = V_1$, where $V_1$ is an $n\times n$ covariance matrix (symmetric and semi-definite positive)
220 | \item $E[v_1(t) \cdot v_1(t-\tau)^T] = 0 \quad \forall t \forall \tau \ne 0$
221 | \end{itemize}
222 |
223 | $v_2(t)$ is a vector white-noise.
224 | \[
225 | v_2(t) \sim WN(0, V_2) \qquad v_2(t) = \begin{bmatrix}
226 | v_{21}(t) \\
227 | v_{22}(t) \\
228 | \vdots \\
229 | v_{2p}(t)
230 | \end{bmatrix}
231 | \]
232 |
233 | $v_2(t)$ is called output noise or measurement (or sensor) noise.
234 | \begin{itemize}
235 | \item $E[v_2(t)] = \vec{0}$
236 | \item $E[v_2(t) \cdot v_2(t)^T] = V_2$, where $V_2$ is a $p\times p$ covariance matrix (symmetric and \textbf{definite} positive)
237 | \item $E[v_2(t) \cdot v_2(t-\tau)^T] = 0 \quad \forall t \forall \tau \ne 0$
238 | \end{itemize}
239 |
240 | Assumptions of the relationships between $v_1(t)$ and $v_2(t)$:
241 | \[
242 | E[v_1(t) \cdot v_2(t-\tau)^T] = \underbrace{V_{12}}_{n\times p} = \begin{cases}
243 | 0 & \text{if } \tau \ne 0 \\
244 | \text{can be non-zero} & \text{if } \tau = 0
245 | \end{cases}
246 | \]
247 |
248 | They can be correlated but only at the same time (in practice $V_{12}=0$ is the most common assumption).
249 |
250 | Since the system $S$ is dynamic we need to define the initial conditions:
251 | \[
252 | E[x(1)] = \underbrace{X_0}_{n\times 1} \qquad E[\left(x(1) - x(0)\right)\left(x(1)-x(0)\right)^T] = \underbrace{P_0}_{n\times n} \ge 0
253 | \]
254 |
255 | If $P_0 = 0$ the initial state is perfectly known.
256 |
257 | Finally we assume that the two noises $v_1(t)$ and $v_2(t)$ are uncorrelated with the initial state:
258 | \[
259 | x(1) \perp v_1(t) \qquad x(1) \perp v_2(t)
260 | \]
261 |
262 | \subsection{Basic Solution}
263 |
264 | \begin{align*}
265 | & \hat{x}(t+1|t) = F\hat{x}(t|t-1) + K(t)e(t) && \qquad \text{state equation} \\
266 | & \hat{y}(t|t-1) = H\hat{x}(t|t-1) &&\qquad \text{output equation} \\
267 | & e(t) = y(t) - \hat{y}(t|t-1) &&\qquad \text{output prediction error} \\
268 | & K(t) = \left( FP(t)H^T+V_{12} \right) \left( HP(t)H^T+V_2 \right)^{-1} &&\qquad \text{gain of the K.F.} \\
269 | & P(t+1) = \left( FP(t)F^T + V_1 \right) + &&\\
270 | & - \left( FP(t)H^T + V_{12} \right)\left( HP(t)H^T + V_{2} \right)^{-1}\left( FP(t)H^T + V_{12} \right)^T && \qquad\text{difference Riccati equation}
271 | \end{align*}
272 |
273 | These equations must be completed with 2 initial conditions (2 are dynamic equations)
274 |
275 | \begin{align*}
276 | \hat{x}(1|0) = E[x(1)] = X_0 & \qquad\text{state equation} \\
277 | P(1) = \text{var}[x(1)] = P_0 & \qquad\text{DRE}
278 | \end{align*}
279 |
280 | \begin{rem}[Structure or $K(t)$ and D.R.E]
281 | Notice that $K(t)$ and DRE have a \emph{blockset} structure having this form: $AP(t)B^T+N$
282 |
283 | There are 3 different types of blocks:
284 | \begin{align*}
285 | \text{state} \qquad& FP(t)F^T+V_1 \\
286 | \text{output} \qquad& HP(t)H^T+V_2 \\
287 | \text{mix} \qquad& FP(t)H^T+V_{12}
288 | \end{align*}
289 |
290 | \begin{align*}
291 | \text{gain} \qquad& (\text{mix})(\text{output})^{-1} \\
292 | \text{DRE} \qquad& (\text{state}) - (\text{mix})(\text{output})^{-1}(\text{mix})^T
293 | \end{align*}
294 | \end{rem}
295 |
296 | \begin{rem}[Riccati equation]
297 | Riccati equation is a special type of nonlinear matrix difference equation.
298 |
299 | Notice that DRE is an autonomous, non-linear, discrete time, multi-variable system, described by a non-linear difference matrix equation.
300 | \[
301 | \text{DRE: } P(t+1) = f(P(t)) \qquad P(1) = P_0
302 | \]
303 | \end{rem}
304 |
305 | \begin{rem}[Existance of DRE]
306 | In order to guarantee the existance of DRE for all $t$ the only critical part is the inversion of the \emph{output} block:
307 | \[
308 | ( \underbrace{HP(t)H^T}_{\ge 0} + \underbrace{V_2}_{>0})^{-1} \qquad \text{Thanks to $V_2>0$ it's invertible}
309 | \]
310 | \end{rem}
311 |
312 | \begin{rem}[Meaning of $P(t)$]
313 | It can be proven that $P(t)$ has a very important meaning.
314 |
315 | \[
316 | P(t) = \text{var}[x(t) - \hat{x}(t|t-1)] = E[(x(t) - \hat{x}(t|t-1))(x(t) - \hat{x}(t|t-1))^T]
317 | \]
318 |
319 | $P(t)$ is the covariance of the 1-step prediction error of the state.
320 | \end{rem}
321 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-27.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{27/05/2020}
2 |
3 | \begin{rem}
4 | For stability let's recall a result of feedback system:
5 | \begin{figure}[H]
6 | \centering
7 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
8 | \node[int] at (0,1.5) (f1) {$F_1(t)$};
9 | \node[int] at (0,0.5) (f2) {$F_2(t)$};
10 | \node[sum] at (-1.5,1.5) (sum) {};
11 |
12 | \draw[<-] (sum) -- ++(-1,0) node[pos=0.2] {+};
13 | \draw[->] (f2) -| (sum) node[pos=0.9] {-};
14 | \draw[->] (sum) -- (f1);
15 | \draw[->] (f1) -- ++(2,0);
16 | \draw[->] (1.5,1.5) |- (f2);
17 | \end{tikzpicture}
18 | \end{figure}
19 |
20 | To check the closed-loop stability:
21 | \begin{itemize}
22 | \item compute the \emph{loop-function} $L(z) = F_1(z) F_2(z)$ (\textbf{do not simplify!})
23 | \item Build the \emph{characteristic polynomial} $\chi(z) = L_N(z) + L_D(z)$ (sum of numerator and denominator)
24 | \item Find the roots of $\chi(z)$, closed loop system is asymptotically stable iff all the roots of $\chi(z)$ are strictly inside the unit circle
25 | \end{itemize}
26 | \end{rem}
27 |
28 | \[
29 | L(z) = \frac{1}{b_0+b_1z^{-1}} \cdot \frac{z^{-1}(b_0+b_1z^{-1})}{1-az^{-1}} \cdot a
30 | \]
31 | \[
32 | \chi(z) = az^{-1}(b_0+b_1z^{-1}) + (1-az^{-1})(b_0+b_1z^{-1}) = b_0+b_1z^{-1} = B(z)
33 | \]
34 |
35 | The closed loop system is asymptotically stable thanks to the minimum phase assumption.
36 |
37 | Performance analysis
38 | \begin{figure}[H]
39 | \centering
40 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
41 | \node[int, minimum width=2cm, align=center] at (0,0) (sys) {closed\\loop\\system};
42 | \draw[<-,transform canvas={yshift=0.3cm}] (sys) -- ++(-1.5,0) node[left] {$y^0(t)$};
43 | \draw[<-,transform canvas={yshift=-0.3cm}] (sys) -- ++(-1.5,0) node[left] {$e(t)$};
44 | \draw[->] (sys) -- ++(1.5,0) node[right] {$y(t)$};
45 | \end{tikzpicture}
46 | \end{figure}
47 |
48 | Since the system is L.T.I. we can use the superposition principle:
49 | \[
50 | y(t) = \underbrace{F_{y^0y}(z)y^0(t)}_\text{TF from $y^0$ to $y$} + \underbrace{F_{ey}(z)e(t)}_\text{TF from $e$ to $y$}
51 | \]
52 |
53 | Let's compute these transfer functions:
54 | \begin{align*}
55 | F_{y^0y} &= \frac{ \frac{1}{b_0+b_1z^{-1}} \frac{z^{-1}(b_0+b_1z^{-1})}{1-az^{-1}} }{ 1 + \frac{1}{b_0+b_1z^{-1}} \frac{z^{-1}(b_0+b_1z^{-1})}{1-az^{-1}}a } = z^{-1} \\
56 | F_{ey} &= \frac{ \frac{1}{1-az^{-1}} }{ 1 + \frac{1}{b_0+b_1z^{-1}} \frac{z^{-1}(b_0+b_1z^{-1})}{1-az^{-1}}a } = 1
57 | \end{align*}
58 |
59 | Notice that that the closed loop system has a very simple closed-loop behavior:
60 | \[
61 | y(t) = z^{-1}y^0(t) + e(t) = y^0(t-1) + e(t)
62 | \]
63 |
64 | $y(t)$ follows exactly $y^0(t)$ (but with a 1-step delay), disturbed by noise $e(t)$.
65 | This is the best possible solution.
66 |
67 | \section{General solution}
68 |
69 | \[
70 | S: y(t) = \frac{B(z)}{A(z)}u(t-k) + \frac{C(z)}{A(z)}e(t) \qquad e(t) \sim WN(0, \lambda^2)
71 | \]
72 |
73 | With the assumptions:
74 | \begin{itemize}
75 | \item $b_0 \ne 0$
76 | \item $B(z)$ has all the roots strictly inside the unit circle (minimum phase)
77 | \item $\frac{C(z)}{A(z)}$ is canonical representation
78 | \item $y^0(t) \perp e(t)$
79 | \item $y^0(t)$ is unpredictable
80 | \end{itemize}
81 |
82 | \paragraph{Goal} Minimize $J = E\left[ \left( y(t) - y^0(t) \right)^2 \right]$
83 |
84 | The trick is to rewrite $y(t) = \hat{y}(t|t-k) + \epsilon(t)$.
85 |
86 | \begin{align*}
87 | J &= E\left[ \left( \hat{y}(t|t-k) + \epsilon(t) - y^0(t) \right)^2 \right] = E\left[ \left( (\hat{y}(t|t-k) - y^0(t)) + \epsilon(t) \right)^2 \right] \\
88 | & = E\left[ \left(\hat{y}(t|t-k) - y^0(t)\right)^2 \right] + E\left[ \epsilon(t)^2 \right] + \cancel{2E\left[ \epsilon(t)\left( \hat{y}(t|t-k) - y^0(t) \right) \right]} \\
89 | &= E\left[ (\hat{y}(t|t-k) - y^0(t))^2 \right] + \text{constant w.r.t. $u(t)$}
90 | \end{align*}
91 |
92 | General formula for ARMAX predictor:
93 | \[
94 | \frac{C(z)}{A(z)} = \underbrace{E(z)}_\text{solution} + \underbrace{\frac{\tilde{R}(z)z^{-n}}{A(z)}}_\text{residual} \qquad \text{(after $n$ steps of long division)}
95 | \]
96 |
97 | \[
98 | \hat{y}(t|t-k) = \frac{B(z)E(z)}{C(z)}u(t-k) + \frac{\tilde{R}(z)}{C(z)}y(t-k)
99 | \]
100 | Shift ahead $k$-steps:
101 | \[
102 | \hat{y}(t+k|t) = \frac{B(z)E(z)}{C(z)}u(t) + \frac{\tilde{R}(z)}{C(z)}y(t)
103 | \]
104 |
105 | Impose $\hat{y}(t+k|t) = y^0(t+k)$, at time $t$ we don't know $y^0(t+k)$, we replace it with $y^0(t)$.
106 | \[
107 | \hat{y}(t+k|t) = y^0(t)
108 | \]
109 |
110 | \[
111 | \frac{B(z)E(z)}{C(z)}u(t) + \frac{\tilde{R}(z)}{C(z)}y(t) = y^0(t)
112 | \]
113 | \[
114 | u(t) = \frac{1}{B(z)E(z)}\left(C(z)y^0(t)-\tilde{R}(z)y(t)\right)
115 | \]
116 | \begin{figure}[H]
117 | \centering
118 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
119 | \node[int] at (0,1.5) (c) {$C(z)$};
120 | \node[sum] at (1.5,1.5) (s1) {};
121 | \node[int] at (3,1.5) (b1) {$\frac{1}{B(z)E(z)}$};
122 | \node[int] at (6,1.5) (b2) {$z^{-1}\frac{B(z)}{A(z)}$};
123 | \node[sum] at (7.5,1.5) (s2) {};
124 | \node[int] at (3,0) (b3) {$\tilde{R}(z)$};
125 | \node[int] at (7.5,3) (b4) {$\frac{C(z)}{A(z)}$};
126 |
127 | \draw[<-] (c) -- ++(-1.5,0) node[left] {$y^0(t)$};
128 | \draw[->] (c) -- (s1) node[pos=0.8] {+};
129 | \draw[->] (s1) -- (b1);
130 | \draw[->] (b1) -- (b2) node[pos=0.7] {$\scriptstyle u(t)$};
131 | \draw[->] (b2) -- (s2);
132 | \draw[->] (b3) -| (s1) node[pos=0.9] {-};
133 | \draw[->] (b4) -- (s2);
134 | \draw[->] (s2) -- ++(2,0) node[right] {$y(t)$};
135 | \draw[<-] (b4) -- ++(0,1) node[above] {$e(t)$};
136 | \draw[->] (8.5,1.5) |- (b3);
137 |
138 | \draw[dashed, green] (-1,-0.7) rectangle (4,2.5) node[above left] {\footnotesize controller};
139 | \draw[dashed, blue] (4.5,-0.7) rectangle (9,4.7) node[above left] {\footnotesize system};
140 | \end{tikzpicture}
141 | \end{figure}
142 |
143 | \subsection{Stability check}
144 |
145 | \[
146 | L(z) = \frac{1}{B(z)E(z)}\cdot \frac{z^{-k}B(z)}{A(z)}\cdot\tilde{R}(z)
147 | \]
148 | \begin{align*}
149 | \chi(z) = z^{-k}B(z)\tilde{R}(z) + B(z)E(z)A(z) = B(z) \left( z^{-k}\tilde{R}(z)+E(z)A(z) \right) = B(z)C(z)
150 | \end{align*}
151 |
152 | The system is asymptotically stable iff:
153 | \begin{itemize}
154 | \item All roots of $B(z)$ are stable (minimum phase assumption)
155 | \item All roots of $C(z)$ are stable (canonical representation)
156 | \end{itemize}
157 |
158 | \subsection{Performance analysis}
159 |
160 | \[
161 | y(t) = F_{y^0y}(z)y^0(t) + F_{ey}(z)e(t)
162 | \]
163 | \begin{align*}
164 | F_{y^0y} &= \frac{ C(z) \frac{1}{B(z)E(z)}\frac{z^{-k}B(z)}{A(z)} }{1 + \frac{1}{B(z)E(z)}\frac{z^{-k}B(z)}{A(z)}\tilde{R}(z) } = z^{-k} \\
165 | F_{y^0y} &= \frac{ \frac{C(z)}{A(z)}}{1 + \frac{1}{B(z)E(z)}\frac{z^{-k}B(z)}{A(z)}\tilde{R}(z) } = E(z)\\
166 | \end{align*}
167 |
168 | At closed loop the behavior is very simple:
169 | \[
170 | y(t) = y^0(t-k)+E(z)e(t)
171 | \]
172 |
173 | $y(t)$ exactly tracks/follows $y^0(t)$ but with $k$ steps of delay and it's disturbed by noise $E(z)e(t)$.
174 | This is the best possible solution.
175 |
176 | \begin{rem}
177 | The closed-loop behavior is very simple.
178 |
179 | \begin{figure}[H]
180 | \centering
181 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
182 | \node[int] at (0,1.5) (c) {};
183 | \node[sum] at (1,1.5) (s1) {};
184 | \node[int] at (2,1.5) (b1) {};
185 | \node[int] at (3.5,1.5) (b2) {};
186 | \node[sum] at (4.5,1.5) (s2) {};
187 | \node[int] at (2,0) (b3) {};
188 | \node[int] at (4.5,3) (b4) {};
189 |
190 | \draw[<-] (c) -- ++(-1,0) node[left] {$y^0(t)$};
191 | \draw[->] (c) -- (s1) node[pos=0.8] {+};
192 | \draw[->] (s1) -- (b1);
193 | \draw[->] (b1) -- (b2) node[pos=0.7] {};
194 | \draw[->] (b2) -- (s2);
195 | \draw[->] (b3) -| (s1) node[pos=0.9] {-};
196 | \draw[->] (b4) -- (s2);
197 | \draw[->] (s2) -- ++(1,0) node[right] {$y(t)$};
198 | \draw[<-] (b4) -- ++(0,1) node[above] {$e(t)$};
199 | \draw[->] (5,1.5) |- (b3);
200 |
201 | \node[int] at (9,1.5) (z) {$z^{-k}$};
202 | \node[int] at (10,3) (e) {$E(z)$};
203 | \node[sum] at (10,1.5) (s3) {};
204 |
205 | \draw[<-] (z) -- ++(-1,0) node[left] {$y^0(t)$};
206 | \draw[->] (s3) -- ++(1,0) node[right] {$y(t)$};
207 | \draw[->] (z) -- (s3);
208 | \draw[->] (e) -- (s3);
209 | \draw[<-] (e) -- ++(0,1) node[above] {$e(t)$};
210 |
211 | \draw[dashed] (-0.7,-0.7) rectangle (5.2,4.7);
212 | \draw[dashed] (8.2,0.7) rectangle (10.7,4.7);
213 |
214 | \node at (6.7,3) {$\equiv$};
215 | \end{tikzpicture}
216 | \end{figure}
217 |
218 | Where are all the poles of the original system?
219 |
220 | The M.V. controller \emph{pushes} all the system poles into the non-observable and/or non-controllable parts of the system (it makes internal cancellations).
221 | It's not a problem since we verified it's internally asymptotically stable.
222 | \end{rem}
223 |
224 | \section{Main limits of Minimum Variance Controllers}
225 |
226 | \begin{itemize}
227 | \item Can be applied only to minimum phase systems
228 | \item We cannot moderate the control/actuation effort
229 | \item We cannot design a specific behavior from $y^0(t)$ to $y(t)$
230 | \end{itemize}
231 |
232 | To overcome these limits there is an extension called G.M.V.C. (Generalized Minimum Variance Control).
233 | Main difference: extension of the performance index.
234 |
235 | \begin{align*}
236 | \text{MVC: } J &= E\left[ \left(y(t) - y^0(t)\right)^2 \right] \\
237 | \text{GMVC: } J &= E\left[ \left(P(z)y(t) - y^0(t) + Q(z)u(t)\right)^2 \right]
238 | \end{align*}
239 | \begin{itemize}
240 | \item $P(z)$ is the \emph{reference model}
241 | \item $Q(z)$ is a T.F. that makes a penalty to big values of $u(t)$
242 | \end{itemize}
243 |
244 | \begin{rem}[Reference model $P(t)$]
245 | \begin{figure}[H]
246 | \centering
247 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
248 | \node[int] at (0,1.5) (c) {C};
249 | \node[int] at (2,1.5) (s) {S};
250 |
251 | \draw[->] (c) -- (s) node[pos=0.5] {$u(t)$};
252 | \draw[->] (c) -- (s);
253 | \draw[<-] (c) -- ++(-1,0) node[left] {$y^0(t)$};
254 | \draw[->] (s) -- ++(2,0) node[right] {$y(t)$};
255 | \draw[->] (3,1.5) -- (3,0.5) -| (c);
256 | \end{tikzpicture}
257 | \end{figure}
258 |
259 | The typical goal is to obtain the best possible tracking $y(t) = y^0(t)$, however perfect tracking may not be the best solution, but the best solution is to track a \emph{reference model}: $y(t) = P(z)y^0(t)$.
260 | \end{rem}
261 |
262 | \begin{exa}[Cruise control in a car]
263 | \begin{figure}[H]
264 | \centering
265 | \begin{tikzpicture}[node distance=2cm,auto,>=latex']
266 | \node[int] at (0,1.5) (c) {C};
267 | \node[int] at (2,1.5) (s) {Car};
268 |
269 | \draw[->] (c) -- (s) node[pos=0.5] {};
270 | \draw[->] (c) -- (s);
271 | \draw[<-] (c) -- ++(-1,0) node[left, align=center] {desired\\speed\\$v^0(t)$};
272 | \draw[->] (s) -- ++(2,0) node[right] {speed};
273 | \draw[->] (3,1.5) -- (3,0.5) -| (c);
274 | \end{tikzpicture}
275 | \end{figure}
276 |
277 | \begin{figure}[H]
278 | \centering
279 | \begin{tikzpicture}[
280 | node distance=2cm,auto,>=latex',
281 | declare function={
282 | f(\x) = (\x < 0.5) * 1 +
283 | (\x >= 0.5) * (\x < 2) * 2 +
284 | (\x >= 2) * (\x < 4) * 3 +
285 | (\x >= 4) * 1.5;
286 | f2(\x) = f(\x) - (
287 | (f(\x) - f(\x-0*0.1)) * 0.8 +
288 | (f(\x) - f(\x-1*0.1)) * 0.4 +
289 | (f(\x) - f(\x-2*0.1)) * 0.2 +
290 | (f(\x) - f(\x-3*0.1)) * 0.1
291 | ) / 1.5;
292 | f3(\x) = f(\x) - (
293 | (f(\x) - f(\x-0*0.1)) * 0.5 +
294 | (f(\x) - f(\x-1*0.1)) * 0.4 +
295 | (f(\x) - f(\x-2*0.1)) * 0.4 +
296 | (f(\x) - f(\x-3*0.1)) * 0.3 +
297 | (f(\x) - f(\x-4*0.1)) * 0.3 +
298 | (f(\x) - f(\x-5*0.1)) * 0.2 +
299 | (f(\x) - f(\x-6*0.1)) * 0.2 +
300 | (f(\x) - f(\x-7*0.1)) * 0.2 +
301 | (f(\x) - f(\x-8*0.1)) * 0.1 +
302 | (f(\x) - f(\x-9*0.1)) * 0.1 +
303 | (f(\x) - f(\x-10*0.1))* 0.05
304 | ) / 2.75;
305 | }
306 | ]
307 | \draw[->] (0,0) -- (0,3) node[above] {$v(t)$};
308 | \draw[->] (0,0) -- (5,0) node[below] {$t$};
309 | \draw[domain=0:5,variable=\x,blue,samples=100] plot ({\x},{f(\x)}) node[right,black] {$v^0(t)$};
310 | \draw[domain=0:5,variable=\x,red,smooth,samples=50] plot ({\x},{f2(\x)});
311 | \draw[domain=0:5,variable=\x,green,smooth,samples=50] plot ({\x},{f3(\x)});
312 | \node[red, right] at (3,1) {$\scriptstyle P(z) = 1$};
313 | \node[green, right] at (3,0.7) {$\scriptstyle P(z)$ \footnotesize to smooth the behavior};
314 | \end{tikzpicture}
315 | \end{figure}
316 | \end{exa}
317 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-05-07.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{07/05/2020}
2 |
3 | To answer those questions we need two fundamental theorems (K.F. asymptotic theorems).
4 | They provide \emph{sufficient} conditions only.
5 |
6 | \paragraph{First asymptotic theorem}
7 |
8 | Assumption: $V_{12} = 0$ and the system is asymptotically stable (all eigenvalues of $F$ are strictly inside the unit circle).
9 | Then:
10 | \begin{itemize}
11 | \item A.R.E. has one and only one semi-definite positive solution: $\overline{P} \ge 0$
12 | \item D.R.E. converges to $\overline{P}$, $\forall P_0 \ge 0$
13 | \item The corresponding $\overline{K}$ is s.t. the K.F. is asymptotically stable
14 | \end{itemize}
15 |
16 | \begin{rem}
17 | \paragraph{Observability} the pair $(F, H)$ is observable if and only if
18 | \[
19 | O = \begin{bmatrix}
20 | H \\
21 | HF \\
22 | \vdots \\
23 | HF^{n-1}
24 | \end{bmatrix}
25 | \qquad
26 | \text{is max rank}
27 | \]
28 |
29 | \paragraph{Controllability from the noise}
30 |
31 | \begin{align*}
32 | x(t+1) = Fx(t) + Gu(t) + v_1(t) \qquad v_1(t) \sim WN(0, V_1)
33 | \end{align*}
34 |
35 | We need controllability from $v_1(t)$ (and don't care about $u(t)$).
36 |
37 | \begin{align*}
38 | x(t+1) = Fx(t) + v_1(t)
39 | \end{align*}
40 |
41 | It's always possible to factorize $V_1 = \Gamma\cdot\Gamma^T$ rewriting
42 | \[
43 | x(t+1) = Fx(t) + \Gamma\omega(t) \qquad \omega(t) \sim WN(0, I)
44 | \]
45 |
46 | We can say that the state $x$ is controllable/reachable from the input noise $v_1(t)$ if and only if:
47 | \[
48 | R = \begin{bmatrix}
49 | \Gamma & F\Gamma & \cdots & F^{n-1}\Gamma
50 | \end{bmatrix}
51 | \]
52 | \end{rem}
53 |
54 | \paragraph{Second asymptotic theorem}
55 |
56 | Assumption: $V_{12} = 0$, $(F, H)$ is observable and $(F, \Gamma)$ is controllable.
57 | Then:
58 | \begin{itemize}
59 | \item A.R.E. has one and only one definite positive solution $\overline{P} > 0$
60 | \item D.R.E. converges to $\overline{P}$, $\forall P_0 \ge 0$
61 | \item The corresponding $\overline{K}$ is such that the K.F. is asymptotically stable
62 | \end{itemize}
63 |
64 | There theorems are very useful in practice because we can fully avoid the (very difficult) convergence analysis of D.R.E.
65 |
66 | \textbf{Note} that the two theorems provide only sufficient conditions.
67 |
68 | \begin{exercise}
69 | \[
70 | S: \begin{cases}
71 | x(t+1) = \frac{1}{2}x(t) + v_1(t) \quad& v_1 \sim WN(0, \frac{19}{20}) \\
72 | y(t) = 2x(t) + v_2(t) \quad& v_2 \sim WN(0, 1)
73 | \end{cases}
74 | \qquad
75 | v_1 \perp v_2
76 | \]
77 |
78 | \paragraph{Question} Find (if exists) the steady state (asymp.) K.F. $\hat{x}(t+1|t)$ and $\hat{x}(t|t)$.
79 |
80 | \[
81 | n = 1 \qquad F = \frac{1}{2} \qquad G = 0 \qquad H = 2 \qquad V_1 = \frac{19}{20} \qquad V_2 = 1 \qquad V_{12} = 0
82 | \]
83 |
84 | Since $V_{12} = 0$ we can try to use the asymptotic theorems.
85 |
86 | \paragraph{First step} Compute the D.R.E.
87 | \begin{align*}
88 | P(t+1) &= \left( FP(t)F^T+V_1 \right) - \left( FP(t)H^T+V_{12} \right) \left( HP(t)H^T+V_2 \right)^{-1}\left( FP(t)H^T+V_{12} \right)^T \\
89 | &= \frac{1}{4}P(t) + \frac{19}{20} - \frac{ \left(\frac{1}{\cancel{2}}P(t)\cancel{2}\right)^2 }{4P(t)+1} \\
90 | &= \frac{\cancel{P(t)^2} + \frac{1}{4}P(t) + \frac{19}{5} P(t) + \frac{19}{20} - \cancel{P(t)^2} }{4P(t) + 1}
91 | \end{align*}
92 |
93 | \textbf{Note} The second order terms must cancel out.
94 |
95 | \[
96 | P(t+1) = \frac{81P(t) + 19}{80P(t)+20}
97 | \]
98 |
99 | \paragraph{Second step} Compute and solve the A.R.E.
100 |
101 | \[
102 | \overline{P} = \frac{81\overline{P} + 19}{80\overline{P}+20} \quad \implies \quad 80\overline{P}^2 + 20\overline{P}-81\overline{P}-19 = 0
103 | \]
104 | \[
105 | \overline{P}_1 = 1 \qquad \cancel{\overline{P}_2 = -\frac{19}{80}} < 0
106 | \]
107 |
108 |
109 | $\overline{P}=1$ is the only definite positive solution of A.R.E.
110 |
111 | \paragraph{Question} Does D.R.E. converges to $\overline{P}=1$, $\forall P_0 \ge 0$?
112 |
113 | There are 2 methods for addressing this question:
114 | \begin{itemize}
115 | \item Direct analysis of D.R.E.
116 | \item Using asymptotic theorems
117 | \end{itemize}
118 |
119 | \paragraph{First methods} Direct analysis of D.R.E.
120 |
121 | \begin{align*}
122 | P(t+1) = f(P(t)) \qquad \text{we need to plot $f(\cdot)$ in the $P(t)$ -- $P(t+1)$ plane}
123 | \end{align*}
124 |
125 | \[
126 | \overline{P} = \frac{81\overline{P} + 19}{80\overline{P}+20}
127 | \qquad
128 | \begin{cases}
129 | \text{vertical asy. value} & P(t) = -\frac{20}{80} = -\frac{1}{4} \\
130 | \text{horizontal asy. value} & P(t) = \frac{81}{80}
131 | \end{cases}
132 | \]
133 |
134 | \begin{figure}[H]
135 | \centering
136 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
137 | \fill [pattern=flexible hatch, pattern color=gray!40] (-2.5,-2) -- (5.5,-2) -- (5.5,0) -- (0,0) -- (0,4.9) -- (-2.5,4.9) -- (-2.5,-2);
138 | \draw[->] (-2.5,0) -- (6,0) node[below] {$P(t)$};
139 | \draw[->] (0,-2) -- (0,5) node[above] {$P(t+1)$};
140 | \draw[domain=-1.25:5,smooth,variable=\x,red] plot ({\x},{5*(\x+1)/(\x+2)});
141 |
142 | \draw[dashed] (-1.5,-2) -- (-1.5,4.9);
143 | \node[above left] at (-1.5,0) {$-\frac{1}{4}$};
144 | \draw[dashed] (-2.5,4.5) -- (5.5,4.5);
145 | \node[below left] at (0,4.5) {$\frac{81}{80}$};
146 | \node[above left] at (0,2.5) {$\frac{19}{20}$};
147 |
148 | \draw (-1.8,-1.8) -- (5,5) node[left] {$P(t+1) = P(t)$};
149 |
150 | \draw[->,dotted] (1,0) -- (1,3.3);
151 | \draw[->,dotted] (1,3.3) -- (3.3,3.3);
152 | \draw[->,dotted] (3.3,3.3) -- (3.3,4.0);
153 | \draw[->,dotted] (3.3,4.0) -- (4.0,4.0);
154 | \draw[->,dotted] (4.0,4.0) -- (4.0,4.2);
155 | \draw[mark=*,red] plot coordinates {(4.2,4.2)} node[black,below] {$\overline{P}_1$};
156 | \draw[mark=*,red] plot coordinates {(-1.2,-1.2)} node[black,below right] {$\overline{P}_2$};
157 | \draw[mark=*,blue] plot coordinates {(1,3.35)} node[black,above] {\tiny$P(2)$};
158 | \draw[mark=*,blue] plot coordinates {(3.3,4.05)} node[black,above] {\tiny$P(3)$};
159 | \draw[mark=*,blue] plot coordinates {(4,4.2)};
160 | \node[below] at (1,0) {\tiny$P(1) = P_0 \ge 0$};
161 |
162 | \draw[->,red] (1.3,3.9) arc[radius=5,start angle=115,end angle=95];
163 | \node[red,rotate=15] at (2,4.3) {\tiny converges};
164 | \end{tikzpicture}
165 | \end{figure}
166 |
167 | By direct analysis/inspection of D.R.E. dynamics we can conclude that $\forall P_0\ge 0$, D.R.E. always converges to $\overline{P}_1=1$.
168 |
169 | If $n=1$ the direct inspection is feasible, but it's very difficult for $n\ge2$.
170 |
171 | \paragraph{Second method} Use theorems
172 |
173 | \[
174 | V_{12} = 0 \qquad F = \frac{1}{2} \text{ ($S$ is stable)} \quad \implies \quad \text{First theorem is fulfilled}
175 | \]
176 |
177 | The observability matrix of $\{F, H\}$ is $O=\begin{bmatrix} 2 \end{bmatrix}$ with full $\rank O = 1$, the system is fully observable.
178 |
179 | Controllability from noise $v_1(t)$
180 | \[
181 | V_1 = \frac{19}{20} \qquad \Gamma=\sqrt{\frac{19}{20}}
182 | \]
183 | The controllability matrix of $\{F, \Gamma\}$ is $R = \begin{bmatrix} \sqrt{\frac{19}{20}} \end{bmatrix}$ with full $\rank R = 1$, the system is fully controllable from noise.
184 |
185 | Both theorems are fulfilled, so A.R.E. has one and only one solution $\overline{P} > 0$, D.R.E. converges to $\overline{P}$, $\forall P_0\ge0$ and $\overline{K}$ makes the K.F. asymptotically stable.
186 |
187 | \paragraph{Third step} Compute $\overline{K}$
188 | \[
189 | \overline{K} = \left(F\overline{P}H^T + V_{12}\right)\left(H\overline{P}H^T+V_2\right) = \left(\frac{1}{2}\cdot 1 \cdot 2 + 0\right) \left(2\cdot 1 \cdot 2 + 1\right)^{-1} = \frac{1}{5}
190 | \]
191 |
192 | Double-check the asymptotical stability of K.F.
193 | \[
194 | F - \overline{K}H = \frac{1}{2} - \frac{1}{5}\cdot 2 = \frac{5-4}{10} = \frac{1}{10}
195 | \]
196 |
197 | \begin{figure}[H]
198 | \centering
199 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
200 | \node [int] (z1) at (1,4) {$z^{-1}$};
201 | \node [int] (F1) at (1,3) {$\frac{1}{2}$};
202 | \node [int] (K) at (1,2) {$\frac{1}{5}$};
203 | \node [int] (z2) at (1,1) {$z^{-1}$};
204 | \node [int] (F2) at (1,0) {$\frac{1}{2}$};
205 |
206 | \node [int] (H1) at (4,4) {$2$};
207 | \node [int] (H2) at (4,1) {$2$};
208 |
209 | \node [sum] (sum1) at (6,4) {};
210 | \node [sum] (sum2) at (7,2) {};
211 | \node [sum] (sum3) at (-1.5,4) {};
212 | \node [sum] (sum4) at (-1.5,1) {};
213 |
214 | \node (v1) at (-1.5,5) {$v_1(t)$};
215 | \node (v2) at (6,5) {$v_2(t)$};
216 | \node[right] (y) at (8,4) {$y(t)$};
217 | \node[right] (yhat) at (8,1) {$\hat{y}(t|t-1)$};
218 | \node[right] (xhat) at (8,0) {$\hat{x}(t|t-1)$};
219 |
220 | \draw[->] (v1) -- (sum3);
221 | \draw[->] (sum3) -- (z1) node[pos=0.5] {$x(t+1)$};
222 | \draw[->] (F1) -| (sum3);
223 | \draw[->] (z1) -- (H1) node[pos=0.5] {$x(t)$};
224 | \draw[->] (H1) -- (sum1);
225 | \draw[->] (v2) -- (sum1);
226 | \draw[->] (2.5,4) |- (F1);
227 | \draw[->] (K) -| (sum4);
228 | \draw[->] (sum4) -- (z2) node[pos=0.5] {$\hat{x}(t+1|t)$};
229 | \draw[->] (7,4) -- (sum2) node[pos=0.8] {$+$};
230 | \draw[->] (sum1) -- (y);
231 | \draw[<-] (K) -- (sum2) node[pos=0.5,black] {$e(t)$};
232 | \draw[->] (z2) -- (H2) node[pos=0.5] {$\hat{x}(t|t-1)$};
233 | \draw[->] (F2) -| (sum4);
234 | \draw[->] (2.5,1) |- (F2);
235 | \draw[->] (H2) |- (yhat);
236 | \draw[->] (7,1) -- (sum2) node[pos=0.8] {$-$};
237 | \draw[->] (F2) -- (xhat);
238 | \end{tikzpicture}
239 | \end{figure}
240 |
241 | \paragraph{Question} Find T.F. from $y(t)$ to $\hat{x}(t|t-1)$
242 |
243 | \textbf{Recall} T.F. from block schemes of feedback systems.
244 |
245 | \begin{figure}[H]
246 | \centering
247 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
248 | \node[int] (G1) at (0,1) {$G_1(z)$};
249 | \node[int] (G2) at (0,0) {$G_2(z)$};
250 | \node[sum] (sum) at (-1.5,1) {};
251 | \node (u) at (-3,1) {$u(t)$};
252 | \node (y) at (2.5,1) {$y(t)$};
253 |
254 | \draw[->] (u) -- (sum) node[pos=0.8] {$+$};
255 | \draw[->] (sum) -- (G1);
256 | \draw[->] (G1) -- (y);
257 | \draw[->] (G2) -| (sum) node[pos=0.8] {$\mp$};
258 | \draw[->] (1.5,1) |- (G2);
259 | \end{tikzpicture}
260 | \end{figure}
261 |
262 | \[
263 | y(t) = G_1(z) \left(u(t) \mp G_2(z)y(t)\right) \quad \implies \quad y(t) = \frac{G_1(z)}{1 \pm G_1(z)G_2(z)}u(t)
264 | \]
265 |
266 | The K.F. is composed of 2 nested loops.
267 |
268 | \begin{figure}[H]
269 | \centering
270 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
271 | \node [int] (z1) at (1,4) {$z^{-1}$};
272 | \node [int] (F1) at (1,3) {$\frac{1}{2}$};
273 | \node [int] (K) at (1,2) {$\frac{1}{5}$};
274 | \node [int] (z2) at (1,1) {$z^{-1}$};
275 | \node [int] (F2) at (1,0) {$\frac{1}{2}$};
276 |
277 | \node [int] (H1) at (4,4) {$2$};
278 | \node [int] (H2) at (4,1) {$2$};
279 |
280 | \node [sum] (sum1) at (6,4) {};
281 | \node [sum] (sum2) at (7,2) {};
282 | \node [sum] (sum3) at (-1.5,4) {};
283 | \node [sum] (sum4) at (-1.5,1) {};
284 |
285 | \node (v1) at (-1.5,5) {$v_1(t)$};
286 | \node (v2) at (6,5) {$v_2(t)$};
287 | \node[right] (y) at (8,4) {$y(t)$};
288 | \node[right] (yhat) at (8,1) {$\hat{y}(t|t-1)$};
289 | \node[right] (xhat) at (8,0) {$\hat{x}(t|t-1)$};
290 |
291 | \draw[->] (v1) -- (sum3);
292 | \draw[->] (sum3) -- (z1) node[pos=0.5] {$x(t+1)$};
293 | \draw[->] (F1) -| (sum3);
294 | \draw[->] (z1) -- (H1) node[pos=0.5] {$x(t)$};
295 | \draw[->] (H1) -- (sum1);
296 | \draw[->] (v2) -- (sum1);
297 | \draw[->] (2.5,4) |- (F1);
298 | \draw[->,red,line width=0.5mm] (K) -| (sum4);
299 | \draw[->,red,line width=0.5mm] (sum4) -- (z2) node[pos=0.5,black] {$\hat{x}(t+1|t)$};
300 | \draw[->] (7,4) -- (sum2) node[pos=0.8] {$+$};
301 | \draw[->] (sum1) -- (y);
302 | \draw[<-] (K) -- (sum2) node[pos=0.5,black] {$e(t)$};
303 | \draw[->,red,line width=0.5mm] (z2) -- (H2) node[pos=0.5,black] {$\hat{x}(t|t-1)$};
304 | \draw[->,red,line width=0.5mm] (F2) -| (sum4);
305 | \draw[->,red,line width=0.5mm] (2.5,1) |- (F2);
306 | \draw[->] (H2) |- (yhat);
307 | \draw[->] (7,1) -- (sum2) node[pos=0.8] {$-$};
308 | \draw[->] (2.5,0) -- (xhat);
309 |
310 | \node[red] at (-0.5,0.5) {$\frac{z^{-1}}{1-\frac{1}{2}z^{-1}}$};
311 | \end{tikzpicture}
312 | \end{figure}
313 |
314 | Predictor of state:
315 | \[
316 | \hat{x}(t|t-1) = \frac{ \frac{1}{5} \frac{z^{-1}}{1-\frac{1}{2}z^{-1}} }{ 1 + \frac{1}{5} \frac{z^{-1}}{1-\frac{1}{2}z^{-1}} 2 }y(t) = \frac{ \frac{1}{5}z^{-1} }{1-\frac{1}{10}z^{-1}}y(t)
317 | \]
318 |
319 | Predictor of output:
320 | \[
321 | \hat{y}(t|t-1) = H\hat{x}(t|t-1) = \frac{2}{5} \frac{ 1 }{1-\frac{1}{10}z^{-1}}y(t-1)
322 | \]
323 |
324 | Filter of state:
325 | \[
326 | \hat{x}(t|t) = F^{-1}\hat{x}(t+1|t) = \frac{2}{5} \frac{ 1 }{1-\frac{1}{10}z^{-1}}y(t)
327 | \]
328 | \end{exercise}
329 |
--------------------------------------------------------------------------------
/style.tex:
--------------------------------------------------------------------------------
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 | % Template Dispense
3 | % Autore: Teo Bucci
4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 |
6 | %---------------------------
7 | % FONTS AND LANGUAGE
8 | %---------------------------
9 |
10 | \usepackage[T1]{fontenc}
11 | \usepackage[utf8]{inputenc}
12 | \usepackage[english]{babel}
13 |
14 | %---------------------------
15 | % PACKAGES
16 | %---------------------------
17 |
18 | \usepackage{dsfont} % for using \mathds{1} characteristic function
19 | \usepackage{amsmath, amssymb, amsthm} % amssymb also loads amsfonts
20 | \usepackage{latexsym}
21 |
22 | \usepackage{booktabs}
23 | \usepackage{pgfplots}
24 | \usepackage{tikz}
25 | \usetikzlibrary{
26 | positioning,
27 | shapes.misc,
28 | intersections,
29 | shapes.symbols,
30 | patterns,
31 | fadings,
32 | shadows.blur,
33 | decorations.pathreplacing,
34 | arrows.meta,
35 | arrows
36 | }
37 | \usepackage{mathdots}
38 | \usepackage{cancel}
39 | \usepackage{color}
40 | \usepackage{siunitx}
41 | \usepackage{array}
42 | \usepackage{multirow}
43 | \usepackage{makecell}
44 | \usepackage{tabularx}
45 | \usepackage{caption}
46 | \captionsetup{belowskip=12pt,aboveskip=4pt}
47 | \usepackage{subcaption}
48 | \usepackage{placeins} % \FloatBarrier
49 | \usepackage{flafter} % The flafter package ensures that floats don't appear until after they appear in the code.
50 | \usepackage[shortlabels]{enumitem}
51 | \usepackage[english]{varioref}
52 | \renewcommand{\ref}{\vref}
53 |
54 | %---------------------------
55 | % INCLUSIONE FIGURE
56 | %---------------------------
57 |
58 | \usepackage{import}
59 | \usepackage{pdfpages}
60 | \usepackage{transparent}
61 | \usepackage{xcolor}
62 | \usepackage{graphicx}
63 | \graphicspath{ {./images/} } % Path relative to the main .tex file
64 | \usepackage{float}
65 |
66 | \newcommand{\fg}[3][\relax]{%
67 | \begin{figure}[H]%[htp]%
68 | \centering
69 | \captionsetup{width=0.7\textwidth}
70 | \includegraphics[width = #2\textwidth]{#3}%
71 | \ifx\relax#1\else\caption{#1}\fi
72 | \label{#3}
73 | \end{figure}%
74 | \FloatBarrier%
75 | }
76 |
77 | %---------------------------
78 | % PARAGRAPHS AND LINES
79 | %---------------------------
80 |
81 | \usepackage[none]{hyphenat} % no hyphenation
82 |
83 | \emergencystretch 3em % to prevent the text from going beyond margins
84 |
85 | \usepackage[skip=0.2\baselineskip+2pt]{parskip}
86 |
87 | % \renewcommand{\baselinestretch}{1.5} % line spacing
88 |
89 | %---------------------------
90 | % HEADERS AND FOOTERS
91 | %---------------------------
92 |
93 | \usepackage{fancyhdr}
94 |
95 | \fancypagestyle{toc}{%
96 | \fancyhf{}%
97 | \fancyfoot[C]{\thepage}%
98 | \renewcommand{\headrulewidth}{0pt}%
99 | \renewcommand{\footrulewidth}{0pt}
100 | }
101 |
102 | \fancypagestyle{fancy}{%
103 | \fancyhf{}%
104 | \fancyhead[RE]{\nouppercase{\leftmark}}%
105 | \fancyhead[LO]{\nouppercase{\rightmark}}%
106 | \fancyhead[LE,RO]{\thepage}%
107 | \renewcommand{\footrulewidth}{0pt}%
108 | \renewcommand{\headrulewidth}{0.4pt}
109 | }
110 |
111 | % Removes the header from odd empty pages at the end of chapters
112 | \makeatletter
113 | \renewcommand{\cleardoublepage}{
114 | \clearpage\ifodd\c@page\else
115 | \hbox{}
116 | \vspace*{\fill}
117 | \thispagestyle{empty}
118 | \newpage
119 | \fi}
120 |
121 | %---------------------------
122 | % CUSTOM
123 | %---------------------------
124 |
125 | \usepackage{xspace}
126 | \newcommand{\latex}{\LaTeX\xspace}
127 | \newcommand{\tex}{\TeX\xspace}
128 |
129 | \newcommand{\Tau}{\mathcal{T}}
130 | \newcommand{\Ind}{\mathds{1}} % indicatrice
131 |
132 | \newcommand{\transpose}{^{\mathrm{T}}}
133 | \newcommand{\complementary}{^{\mathrm{C}}} % alternative ^{\mathrm{C}} ^{\mathrm{c}} ^{\mathsf{c}}
134 | \newcommand{\degree}{^\circ\text{C}} % simbolo gradi
135 |
136 | \newcommand{\notimplies}{\mathrel{{\ooalign{\hidewidth$\not\phantom{=}$\hidewidth\cr$\implies$}}}}
137 | \newcommand{\questeq}{\overset{?}{=}} % è vero che?
138 |
139 | \newcommand{\indep}{\perp \!\!\! \perp} % indipendenza
140 | \newcommand{\iid}{\stackrel{\mathrm{iid}}{\sim}}
141 | \newcommand{\event}[1]{\emph{``#1''}} % evento
142 |
143 | % variazioni del simbolo "="
144 | \newcommand{\iideq}{\overset{\text{\tiny iid}}{=}}
145 | \newcommand{\ideq}{\overset{\text{\tiny id}}{=}}
146 | \newcommand{\indepeq}{\overset{\perp \!\!\! \perp}{=}}
147 |
148 | \newcommand{\boxedText}[1]{\noindent\fbox{\parbox{\textwidth}{#1}}}
149 |
150 | \renewcommand{\emptyset}{\varnothing}
151 | \renewcommand{\tilde}{\widetilde}
152 | \renewcommand{\hat}{\widehat}
153 |
154 | \DeclareMathOperator{\sgn}{sgn}
155 | \DeclareMathOperator{\Var}{Var}
156 | \DeclareMathOperator{\Cov}{Cov}
157 | \DeclareMathOperator*{\rank}{rank}
158 | \DeclareMathOperator*{\eig}{eig}
159 | \DeclareMathOperator{\tr}{tr}
160 | \DeclareMathOperator{\Grad}{grad}
161 | \DeclareMathOperator{\Div}{div}
162 | \DeclareMathOperator{\Span}{span}
163 | \let\Im\undefined % redefine \Im
164 | \DeclareMathOperator{\Im}{Im}
165 | \DeclareMathOperator{\Ker}{Ker}
166 | \DeclareMathOperator*{\argmin}{arg\,min}
167 | \DeclareMathOperator*{\argmax}{arg\,max}
168 | \DeclareMathOperator*{\esssup}{ess\ sup}
169 | \DeclareMathOperator*{\essinf}{ess\ inf}
170 | \DeclareMathOperator*{\supp}{supp}
171 |
172 | \newcommand{\eps}{\varepsilon}
173 |
174 | \usepackage{mathtools} % Serve per i comandi dopo
175 | \DeclarePairedDelimiter{\abs}{\lvert}{\rvert} % absolute value
176 | \DeclarePairedDelimiter{\norm}{\lVert}{\rVert} % norm
177 | \DeclarePairedDelimiter{\sca}{\langle}{\rangle} % scalar product
178 |
179 | % Bold
180 | \renewcommand{\AA}{\mathbb A}
181 | \newcommand{\BB}{\mathbb{B}}
182 | \newcommand{\CC}{\mathbb{C}}
183 | \newcommand{\DD}{\mathbb{D}}
184 | \newcommand{\EE}{\mathbb{E}}
185 | \newcommand{\FF}{\mathbb{F}}
186 | \newcommand{\GG}{\mathbb{G}}
187 | \newcommand{\HH}{\mathbb{H}}
188 | \newcommand{\II}{\mathbb{I}}
189 | \newcommand{\JJ}{\mathbb{J}}
190 | \newcommand{\KK}{\mathbb{K}}
191 | \newcommand{\LL}{\mathbb{L}}
192 | \newcommand{\MM}{\mathbb{M}}
193 | \newcommand{\NN}{\mathbb{N}}
194 | \newcommand{\OO}{\mathbb{O}}
195 | \newcommand{\PP}{\mathbb{P}}
196 | \newcommand{\QQ}{\mathbb{Q}}
197 | \newcommand{\RR}{\mathbb{R}}
198 | \renewcommand{\SS}{\mathbb S}
199 | \newcommand{\TT}{\mathbb{T}}
200 | \newcommand{\UU}{\mathbb{U}}
201 | \newcommand{\VV}{\mathbb{V}}
202 | \newcommand{\WW}{\mathbb{W}}
203 | \newcommand{\XX}{\mathbb{X}}
204 | \newcommand{\YY}{\mathbb{Y}}
205 | \newcommand{\ZZ}{\mathbb{Z}}
206 |
207 | % Calligraphic
208 | \newcommand{\Ac}{\mathcal{A}}
209 | \newcommand{\Bc}{\mathcal{B}}
210 | \newcommand{\Cc}{\mathcal{C}}
211 | \newcommand{\Dc}{\mathcal{D}}
212 | \newcommand{\Ec}{\mathcal{E}}
213 | \newcommand{\Fc}{\mathcal{F}}
214 | \newcommand{\Gc}{\mathcal{G}}
215 | \newcommand{\Hc}{\mathcal{H}}
216 | \newcommand{\Ic}{\mathcal{I}}
217 | \newcommand{\Jc}{\mathcal{J}}
218 | \newcommand{\Kc}{\mathcal{K}}
219 | \newcommand{\Lc}{\mathcal{L}}
220 | \newcommand{\Mc}{\mathcal{M}}
221 | \newcommand{\Nc}{\mathcal{N}}
222 | \newcommand{\Oc}{\mathcal{O}}
223 | \newcommand{\Pc}{\mathcal{P}}
224 | \newcommand{\Qc}{\mathcal{Q}}
225 | \newcommand{\Rc}{\mathcal{R}}
226 | \newcommand{\Sc}{\mathcal{S}}
227 | \newcommand{\Tc}{\mathcal{T}}
228 | \newcommand{\Uc}{\mathcal{U}}
229 | \newcommand{\Vc}{\mathcal{V}}
230 | \newcommand{\Wc}{\mathcal{W}}
231 | \newcommand{\Xc}{\mathcal{X}}
232 | \newcommand{\Yc}{\mathcal{Y}}
233 | \newcommand{\Zc}{\mathcal{Z}}
234 |
235 | % differenziale
236 | \newcommand{\dspace}{\,} % \, aggiunge un piccolo spazio
237 | \newcommand{\de}{\mathrm{d}}
238 | \newcommand{\dx}{\dspace \de x}
239 | \newcommand{\dy}{\dspace \de y}
240 | \newcommand{\dt}{\dspace \de t}
241 | \newcommand{\ds}{\dspace \de s}
242 | \newcommand{\dz}{\dspace \de z}
243 | \newcommand{\dw}{\dspace \de w}
244 | \newcommand{\du}{\dspace \de u}
245 | \newcommand{\dv}{\dspace \de v}
246 | \newcommand{\dteta}{\dspace \de \vartheta}
247 | \newcommand{\dxy}{\dspace \de x \de y}
248 | \newcommand{\duv}{\dspace \de u \de v}
249 | \newcommand{\dst}{\dspace \de s \de t}
250 | \newcommand{\dP}{\dspace \de P}
251 | \newcommand{\dPP}{\dspace \de \PP}
252 |
253 | \newcommand{\SDP}{(\Omega,\Ac,\PP)} % spazio di probabilità
254 | \newcommand{\Cz}{\Cc^0}
255 | \newcommand{\Cu}{\Cc^1}
256 | \newcommand{\Lu}{\mathcal{L}^1}
257 |
258 | \newcommand{\fXY}{f_{(X,Y)}}
259 | \newcommand{\fXYxy}{\fXY(x,y)}
260 |
261 | % spaziature https://tex.stackexchange.com/questions/438612/space-between-exists-and-forall
262 | % questo aggiunge un piccolo spazio dopo \forall
263 | \let\oldforall\forall
264 | \renewcommand{\forall}{\oldforall \, }
265 | % questo aggiunge un piccolo spazio dopo \exists
266 | \let\oldexist\exists
267 | \renewcommand{\exists}{\oldexist \: }
268 | % questo aggiunge un comando \existsu per l'esiste ed è unico
269 | \newcommand\existu{\oldexist! \: }
270 |
271 | %---------------------------
272 | % APPENDICE
273 | %---------------------------
274 |
275 | \usepackage[title,titletoc]{appendix}
276 |
277 | %---------------------------
278 | % THEOREMS
279 | %---------------------------
280 |
281 | \definecolor{grey245}{RGB}{245,245,245}
282 |
283 | \newtheoremstyle{blacknumbox} % Theorem style name
284 | {0pt}% Space above
285 | {0pt}% Space below
286 | {\normalfont}% Body font
287 | {}% Indent amount
288 | {\bf\scshape}% Theorem head font --- {\small\bf}
289 | {.\;}% Punctuation after theorem head
290 | {0.25em}% Space after theorem head
291 | {\small\thmname{#1}\nobreakspace\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
292 | %{\small\thmname{#1}% Theorem text (e.g. Theorem)
293 | \thmnote{\nobreakspace\the\thm@notefont\normalfont\bfseries---\nobreakspace#3}}% Optional theorem note
294 |
295 | \newtheoremstyle{unnumbered} % Theorem style name
296 | {0pt}% Space above
297 | {0pt}% Space below
298 | {\normalfont}% Body font
299 | {}% Indent amount
300 | {\bf\scshape}% Theorem head font --- {\small\bf}
301 | {.\;}% Punctuation after theorem head
302 | {0.25em}% Space after theorem head
303 | {\small\thmname{#1}\thmnumber{\@ifnotempty{#1}{}\@upn{#2}}% Theorem text (e.g. Theorem 2.1)
304 | %{\small\thmname{#1}% Theorem text (e.g. Theorem)
305 | \thmnote{\nobreakspace\the\thm@notefont\normalfont\bfseries---\nobreakspace#3}}% Optional theorem note
306 |
307 | \newcounter{dummy}
308 | \numberwithin{dummy}{chapter}
309 |
310 | \theoremstyle{blacknumbox}
311 | \newtheorem{definitionT}[dummy]{Definition}
312 | \newtheorem{theoremT}[dummy]{Theorem}
313 | \newtheorem{corollaryT}[dummy]{Corollary}
314 | \newtheorem{lemmaT}[dummy]{Lemma}
315 |
316 | % Per gli unnumbered tolgo il \nobreakspace subito dopo {\small\thmname{#1} perché altrimenti c'è uno spazio tra Teorema e il ".", lo spazio lo voglio solo se sono numerati per distanziare Teorema e "(2.1)"
317 | \theoremstyle{unnumbered}
318 | \newtheorem*{remarkT}{Remark}
319 | \newtheorem*{proofT}{Proof}
320 | \newtheorem*{exampleT}{Example}
321 |
322 | \RequirePackage[framemethod=default]{mdframed} % Required for creating the theorem, definition, exercise and corollary boxes
323 |
324 | % orange box
325 | \newmdenv[skipabove=7pt,
326 | skipbelow=7pt,
327 | rightline=false,
328 | leftline=true,
329 | topline=false,
330 | bottomline=false,
331 | linecolor=orange,
332 | backgroundcolor=orange!0,
333 | innerleftmargin=5pt,
334 | innerrightmargin=5pt,
335 | innertopmargin=5pt,
336 | leftmargin=0cm,
337 | rightmargin=0cm,
338 | linewidth=2pt,
339 | innerbottommargin=5pt]{oBox}
340 |
341 | % green box
342 | \newmdenv[skipabove=7pt,
343 | skipbelow=7pt,
344 | rightline=false,
345 | leftline=true,
346 | topline=false,
347 | bottomline=false,
348 | linecolor=green,
349 | backgroundcolor=green!0,
350 | innerleftmargin=5pt,
351 | innerrightmargin=5pt,
352 | innertopmargin=5pt,
353 | leftmargin=0cm,
354 | rightmargin=0cm,
355 | linewidth=2pt,
356 | innerbottommargin=5pt]{gBox}
357 |
358 | % blue box
359 | \newmdenv[skipabove=7pt,
360 | skipbelow=7pt,
361 | rightline=false,
362 | leftline=true,
363 | topline=false,
364 | bottomline=false,
365 | linecolor=blue,
366 | backgroundcolor=blue!0,
367 | innerleftmargin=5pt,
368 | innerrightmargin=5pt,
369 | innertopmargin=5pt,
370 | leftmargin=0cm,
371 | rightmargin=0cm,
372 | linewidth=2pt,
373 | innerbottommargin=5pt]{bBox}
374 |
375 | % dim box
376 | \newmdenv[skipabove=7pt,
377 | skipbelow=7pt,
378 | rightline=false,
379 | leftline=true,
380 | topline=false,
381 | bottomline=false,
382 | linecolor=black,
383 | backgroundcolor=grey245!0,
384 | innerleftmargin=5pt,
385 | innerrightmargin=5pt,
386 | innertopmargin=5pt,
387 | leftmargin=0cm,
388 | rightmargin=0cm,
389 | linewidth=2pt,
390 | innerbottommargin=5pt]{blackBox}
391 |
392 | \newenvironment{defn}{\begin{bBox}\begin{definitionT}}{\end{definitionT}\end{bBox}}
393 | \newenvironment{thm}{\begin{gBox}\begin{theoremT}}{\end{theoremT}\end{gBox}}
394 | \newenvironment{coro}{\begin{oBox}\begin{corollaryT}}{\end{corollaryT}\end{oBox}}
395 | \newenvironment{lemma}{\begin{oBox}\begin{lemmaT}}{\end{lemmaT}\end{oBox}}
396 | \newenvironment{rem}{\begin{oBox}\begin{remarkT}}{\end{remarkT}\end{oBox}}
397 | \newenvironment{exa}{\begin{blackBox}\begin{exampleT}}{\end{exampleT}\end{blackBox}}
398 |
399 | \renewcommand\qedsymbol{$\blacksquare$}
400 | \renewenvironment{proof}{\begin{blackBox}\begin{proofT}}{\[\qed\]\end{proofT}\end{blackBox}}
401 |
402 | %---------------------------
403 | % CONTENTS
404 | %---------------------------
405 |
406 | \setcounter{secnumdepth}{3} % \subsubsection is level 3
407 | \setcounter{tocdepth}{2}
408 |
409 | \usepackage{bookmark}% loads hyperref too
410 | \hypersetup{
411 | %pdftitle={Fundamentos de C\'alculo},
412 | %pdfsubject={C\'alculo diferencial},
413 | bookmarksnumbered=true,
414 | bookmarksopen=true,
415 | bookmarksopenlevel=1,
416 | hidelinks,% remove border and color
417 | pdfstartview=Fit, % Fits the page to the window.
418 | pdfpagemode=UseOutlines, %Determines how the file is opening in Acrobat; the possibilities are UseNone, UseThumbs (show thumbnails), UseOutlines (show bookmarks), FullScreen, UseOC (PDF 1.5), and UseAttachments (PDF 1.6). If no mode if explicitly chosen, but the bookmarks option is set, UseOutlines is used.
419 | }
420 |
421 | \usepackage{glossaries} % certain packages that must be loaded before glossaries, if they are required: hyperref, babel, polyglossia, inputenc and fontenc
422 | \setacronymstyle{long-short}
423 |
424 | % hide section from the ToC \tocless\section{hide}
425 | \newcommand{\nocontentsline}[3]{}
426 | \newcommand{\tocless}[2]{\bgroup\let\addcontentsline=\nocontentsline#1{#2}\egroup}
427 |
428 | \usepackage[textsize=tiny, textwidth=1.5cm]{todonotes} % add disable to options to not show in pdf
429 |
--------------------------------------------------------------------------------
/lectures_AY2020/2020-04-27.tex:
--------------------------------------------------------------------------------
1 | \newlecture{Sergio Savaresi}{27/04/2020}
2 |
3 | The general ideal of the method is:
4 | \begin{itemize}
5 | \item Make a set of ``single sinusoid'' (``single-tune'') excitation experiments
6 | \item From each experiment estimate a single point of the frequency response of the system
7 | \item Fit the estimated and modeled frequency response to obtain the optimal model
8 | \end{itemize}
9 |
10 | \begin{exa}[Car steer dynamics]
11 | \begin{figure}[H]
12 | \centering
13 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
14 | \draw (0,0) rectangle ++(2,3.5);
15 |
16 | \draw[rotate around={30:(0,3.5)}] (-0.15,3) rectangle ++(0.3,1);
17 | \draw[rotate around={30:(2,3.5)}] (1.85,3) rectangle ++(0.3,1);
18 |
19 | \draw[dotted] (0,3.5) -- (0,5);
20 | \draw[dotted, rotate around={30:(0,3.5)}] (0,3.5) -- (0,5);
21 | \node at (-0.3,4.9) {$\delta_F$};
22 |
23 | \draw (1,1.75) circle [radius=0.2];
24 | \draw (1,2.05) -- (1,1.45);
25 | \draw (0.7,1.75) -- (1.3,1.75);
26 |
27 | \draw[->,>=stealth',semithick] (1.5,1.75) arc[radius=0.5, start angle=0, end angle=90];
28 | \node at (1.5,2.25) {$\omega_z$};
29 | \end{tikzpicture}
30 | \end{figure}
31 |
32 |
33 | This is the dynamic relationship linking the input (steer) to the output (yaw-rate).
34 | This kind of relationship is very important for stability control design and autonomous car.
35 |
36 | There are 3 possible situations:
37 | \begin{figure}[H]
38 | \centering
39 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
40 | \node[int] (sys1) {1};
41 | \node[left of=sys1] (in1) {$\delta_F$};
42 | \node[right of=sys1] (out1) {$\omega_z$};
43 | \draw[->, red] (in1) -- (sys1);
44 | \draw[->] (sys1) -- (out1);
45 |
46 | \node[int, right of=sys1, node distance=4cm] (sys2) {2};
47 | \node[left of=sys2] (in2) {$\delta_R$};
48 | \node[above of=sys2, node distance=1cm] (in2b) {$\delta_F$};
49 | \node[right of=sys2] (out2) {$\omega_z$};
50 | \draw[->, red] (in2) -- (sys2);
51 | \draw[->] (in2b) -- (sys2);
52 | \draw[->] (sys2) -- (out2);
53 |
54 | \node[int, right of=sys2, node distance=4cm] (sys3) {3};
55 | \node[left of=sys3, yshift=0.3cm] (in3a) {$\delta_F$};
56 | \node[left of=sys3, yshift=-0.3cm] (in3b) {$\delta_R$};
57 | \node[right of=sys3] (out3) {$\omega_z$};
58 | \draw[->, red] (in3a) -- (sys3);
59 | \draw[->, red] (in3b) -- (sys3);
60 | \draw[->] (sys3) -- (out3);
61 | \end{tikzpicture}
62 | \end{figure}
63 |
64 | \begin{enumerate}
65 | \item The control variable is the front steer: application is autonomous car
66 | \item The driver controls $\delta_F$ which is a measurable disturbance, the system controls the rear steer
67 | \item Both $\delta_R$ and $\delta_F$ are control variables: application high performance autonomous car
68 | \end{enumerate}
69 | \end{exa}
70 |
71 | \paragraph{Step 1} In the experiment design step we first have to select a set of excitation frequencies.
72 |
73 | \begin{figure}[H]
74 | \centering
75 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
76 | \draw[->] (0,0) -- (5,0) node[right] {$\omega$};
77 | \draw (0,0.1) -- (0,-0.1) node[below] {$0$};
78 | \draw (0.8,0.1) -- (0.8,-0.1) node[below] {$\omega_1$};
79 | \draw (1.6,0.1) -- (1.6,-0.1) node[below] {$\omega_2$};
80 | \draw (2.4,0.1) -- (2.4,-0.1) node[below] {$\omega_3$};
81 | \draw (3.2,0.1) -- (3.2,-0.1) node[below] {$\ldots$};
82 | \draw (4,0.1) -- (4,-0.1) node[below] {$\omega_H$};
83 | \end{tikzpicture}
84 | \end{figure}
85 |
86 | The maximum frequency is $\omega_H$.
87 | We have $\{\omega_1, \omega_2, \cdots, \omega_H\}$ usually evenly spaced ($\Delta \omega$ is constant).
88 | $\omega_H$ must be selected according to the bandwidth of the control system.
89 |
90 | We make $H$ independent experiments.
91 |
92 | \begin{figure}[H]
93 | \centering
94 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
95 | \node[int] (sys) {system};
96 | \node[left of=sys, node distance=3cm] (in) {};
97 | \node[left of=in] (in2) {};
98 | \node[right of=sys, node distance=2.5cm] (out) {};
99 | \node[right of=out, node distance=2cm] (out2) {};
100 | \node[below of=in, node distance=0.5cm] {$u_1(t) = A_1\sin(\omega_1t)$};
101 | \draw[xshift=-4cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x] plot ({\x},{sin(\x*180/3.14)});
102 |
103 | \node[below of=out, node distance=0.5cm] {$y_1(t)$};
104 | \draw[xshift=1.5cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x] plot ({\x},{1.5*sin(\x*180/3.14+30)});
105 | \draw[->] (in2) -- (sys);
106 | \draw[->] (sys) -- (out2);
107 | \end{tikzpicture}
108 | \caption*{Experiment \#1}
109 | \end{figure}
110 |
111 | \begin{figure}[H]
112 | \centering
113 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
114 | \node[int] (sys) {system};
115 | \node[left of=sys, node distance=3cm] (in) {};
116 | \node[left of=in] (in2) {};
117 | \node[right of=sys, node distance=2.5cm] (out) {};
118 | \node[right of=out, node distance=2cm] (out2) {};
119 | \node[below of=in, node distance=0.5cm] {$u_2(t) = A_2\sin(\omega_2t)$};
120 | \draw[xshift=-4cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x] plot ({\x},{sin(2*\x*180/3.14)});
121 |
122 | \node[below of=out, node distance=0.5cm] {$y_2(t)$};
123 | \draw[xshift=1.5cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x] plot ({\x},{1.5*sin(2*\x*180/3.14+30)});
124 | \draw[->] (in2) -- (sys);
125 | \draw[->] (sys) -- (out2);
126 | \end{tikzpicture}
127 | \caption*{Experiment \#2}
128 | \end{figure}
129 |
130 | \begin{figure}[H]
131 | \centering
132 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
133 | \node[int] (sys) {system};
134 | \node[left of=sys, node distance=3cm] (in) {};
135 | \node[left of=in] (in2) {};
136 | \node[right of=sys, node distance=2.5cm] (out) {};
137 | \node[right of=out, node distance=2cm] (out2) {};
138 | \node[below of=in, node distance=0.5cm] {$u_H(t) = A_H\sin(\omega_Ht)$};
139 | \draw[xshift=-4cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x,samples=50] plot ({\x},{sin(5*\x*180/3.14)});
140 |
141 | \node[below of=out, node distance=0.5cm] {$y_H(t)$};
142 | \draw[xshift=1.5cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x,samples=50] plot ({\x},{1.5*sin(5*\x*180/3.14+30)});
143 | \draw[->] (in2) -- (sys);
144 | \draw[->] (sys) -- (out2);
145 | \end{tikzpicture}
146 | \caption*{Experiment \#$H$}
147 | \end{figure}
148 |
149 |
150 | \begin{rem}
151 | The amplitudes $A_1$, $A_2$, \ldots, $A_H$ can be equal (constant) or, more frequently, they decrease as the frequency increases to fulfill the power constraint on the input.
152 |
153 | \paragraph{Example} $\delta(t)$ is the steering angle (moved by an actuator).
154 | The requested steer torque is proportional to $\delta$: $T(t) = K \delta(t)$.
155 | Therefore the steer power is proportional to $T(t) \dot{\delta}(t) = K \delta(t)\dot{\delta}(t)$.
156 | If $\delta(t) = A_i\sin(\omega_it)$ the steering power is $KA_i\sin(\omega_it)\omega_iA_i\cos(\omega_it)$ which is proportional to $KA_i^2\omega_i$.
157 |
158 | If we have a limit to this power, this power should be constant during the $H$ experiments.
159 | \[KA_i^2\omega_i = \text{const} \qquad A_i=\sqrt{\frac{\text{const}}{K\omega_i}}\]
160 | \end{rem}
161 |
162 | Focusing on the $i$-th experiment.
163 | \begin{figure}[H]
164 | \centering
165 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
166 | \node[int] (sys) {system};
167 | \node[left of=sys, node distance=3cm] (in) {};
168 | \node[left of=in] (in2) {};
169 | \node[right of=sys, node distance=2.5cm] (out) {};
170 | \node[right of=out, node distance=2cm] (out2) {};
171 | \node[below of=in, node distance=0.5cm] {$u_i(t) = A_i\sin(\omega_it)$};
172 | \draw[xshift=-4cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x] plot ({\x},{sin(2*\x*180/3.14)});
173 |
174 | \node[below of=out, node distance=0.5cm] {$y_i(t)$};
175 | \draw[xshift=1.5cm,yshift=0.5cm,scale=0.2,domain=0:10,smooth,variable=\x,samples=100] plot ({\x},{1.5*sin(2*\x*180/3.14+30)+rand/3});
176 | \draw[->] (in2) -- (sys);
177 | \draw[->] (sys) -- (out2);
178 | \end{tikzpicture}
179 | \end{figure}
180 |
181 | \begin{rem}
182 | If the system is LTI (linear time-invariant), the frequency response theorem says the if the input is a sine input of frequency $\omega_i$ the output must be a sine with frequency $\omega_i$.
183 | \end{rem}
184 |
185 | However $y_i(t)$ in real applications is not a perfect sinusoid.
186 | \begin{itemize}
187 | \item Noise on output measurements
188 | \item Noise on the system (not directly on the output)
189 | \item (Small) non-linear effects (that we neglect)
190 | \end{itemize}
191 |
192 | In pre-processing of I/O data we want to extract from $y_i(t)$ a perfect sinusoid of frequency $\omega_i$.
193 | We force the assumption that the system is LTI, so the output must be a pure sine wave of frequency $\omega_i$ (all the remaining signal is noise).
194 |
195 | The model of the output signal is
196 | \[ \hat{y}_i = B_i \sin(\omega_it+\phi_i) = a_i\sin(\omega_it) + b_i\cos(\omega_it) \]
197 | There are 2 unknowns: $B_i$ and $\phi_i$ (or $a_i$ and $b_i$).
198 | We try to estimate $a_i$ and $b_i$ since they are \emph{linear}.
199 |
200 | The unknown parameters are $a_i$ and $b_i$ and we can find them by parametric identification.
201 | \[ \{ \hat{a}_i, \hat{b}_i \} = \argmin_{\{a_i, b_i\}} J_N(a_i, b_i) \]
202 | \[ J_N(a_i, b_i) = \frac{1}{N} \sum_{t=1}^N ( \underbrace{y_i(t)}_{\text{measurement}} \underbrace{- a_i\sin(\omega_it) - b_i\cos(\omega_it)}_\text{model output})^2 \]
203 |
204 | $J_N$ is a quadratic function of $a_i$ and $b_i$, so we can solve the problem explicitly.
205 |
206 | \begin{align*}
207 | \frac{\partial J_N}{\partial a_i} &= \frac{2}{N} \sum_{t=1}^N (-\sin(\omega_it))(y_i(t) - a_i\sin(\omega_it)-b_i\cos(\omega_it)) = 0 \\
208 | \frac{\partial J_N}{\partial b_i} &= \frac{2}{N} \sum_{t=1}^N (-\cos(\omega_it))(y_i(t) - a_i\sin(\omega_it)-b_i\cos(\omega_it)) = 0
209 | \end{align*}
210 |
211 | \[
212 | \begin{bmatrix}
213 | \sum_{t=1}^N \sin(\omega_it)^2 & \sum_{t=1}^N \sin(\omega_it)\cos(\omega_it) \\
214 | \sum_{t=1}^N \sin(\omega_it)\cos(\omega_it) & \sum_{t=1}^N \cos(\omega_it)^2
215 | \end{bmatrix}
216 | \begin{bmatrix}
217 | a_i \\ b_i
218 | \end{bmatrix} =
219 | \begin{bmatrix}
220 | \sum_{t=1}^N y_i(t)\sin(\omega_it) \\
221 | \sum_{t=1}^N y_i(t)\cos(\omega_it)
222 | \end{bmatrix}
223 | \]
224 |
225 | At this point we prefer to go back to a \emph{sin-only} form ($B_i$, $\phi_i$):
226 | \[
227 | \hat{B}_i\sin(\omega_it + \phi_i) = \hat{B}_i\sin(\omega_it)\cos(\hat{\phi}_i) + \hat{B}_i\cos(\omega_it)\sin(\hat{\phi_i}) = \hat{a}_i\sin(\omega_it) + \hat{b}_i\cos(\omega_it)
228 | \]
229 |
230 | \begin{align*}
231 | \hat{B}_i\cos(\hat{\phi}_i) = \hat{a}_i \\
232 | \hat{B}_i\sin(\hat{\phi}_i) = \hat{b}_i \\
233 | \end{align*}
234 | \[
235 | \frac{\hat{b}_i}{\hat{a}_i} = \frac{\sin\hat{\phi}_i}{\cos{\hat{\phi}_i}} = \tan(\hat{\phi_i}) \qquad \hat{\phi}_i = \arctan \left( \frac{\hat{b}_i}{\hat{a}_i} \right)
236 | \]
237 | \[
238 | \hat{B}_i = \frac{\frac{\hat{a}_i}{\cos\hat{\phi}_i} + \frac{\hat{b}_i}{\sin\hat{\phi}_i}}{2}
239 | \]
240 |
241 | Repeating the experiment and pre-processing for the $H$ experiments we obtain
242 |
243 | \begin{align*}
244 | \{ \hat{B}_1, \hat{\phi}_1 \} &\implies \frac{\hat{B}_1}{A_1} e^{j\hat{\phi_1}} \\
245 | \{ \hat{B}_2, \hat{\phi}_2 \} &\implies \frac{\hat{B}_2}{A_2} e^{j\hat{\phi_2}} \\
246 | \vdots& \\
247 | \{ \hat{B}_H, \hat{\phi}_H \} &\implies \frac{\hat{B}_H}{A_H} e^{j\hat{\phi_H}} \\
248 | \end{align*}
249 |
250 | We obtain $H$ complex numbers, the estimated $H$ points of the frequency response of the transfer function $W(z)$ from the input $u(t)$ to the output $y(t)$ of the system.
251 |
252 | \begin{figure}[H]
253 | \centering
254 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
255 | \draw[->] (0,0) -- (5,0) node[right] {$\omega$};
256 | \draw[->] (0,-1.5) -- (0,3) node[left] {$|\cdot|$};
257 | \draw[domain=0:4,mark=*,only marks,samples=8,variable=\x] plot ({\x},{5*log10(2/(1+((2^\x)^2)/100))});
258 |
259 | \draw[->] (0,-3) -- (5,-3) node[right] {$\omega$};
260 | \draw[->] (0,-4.5) -- (0,-1.7) node[left] {$\angle\cdot$};
261 | \draw[domain=0:4,mark=*,only marks,samples=8,variable=\x] plot ({\x},{2*(atan(2/(1+((2^\x)^2)/100))/180*3.14)-5.2});
262 | \end{tikzpicture}
263 | \end{figure}
264 |
265 | At the end of \emph{step 1} we have a frequency-domain dataset ($H$ values) representing $H$ estimated points of the frequency response of the system.
266 |
267 | \paragraph{Step 2} Model class selection (T.F.)
268 |
269 | \[
270 | \mathcal{M}(\theta): W(z; \theta) = \frac{b_0+b_1z^{-1}+\cdots+b_pz^{-p}}{1+a_1z^{-1}+\cdots+a_nz^{-n}}z^{-1}
271 | \qquad
272 | \theta = \begin{bmatrix}
273 | a_1 \\ \vdots \\ a_n \\ b_0 \\ \vdots \\ b_p
274 | \end{bmatrix}
275 | \]
276 |
277 | \begin{rem}[Model order selection]
278 | In this case the order is composed by 2 parameters $n$ and $p$.
279 | Use cross-validation approach (or visual fitting in the Bode diagram).
280 | \end{rem}
281 |
282 | \paragraph{Step 3} New performance index (frequency domain).
283 |
284 | \[
285 | J_H(\theta) = \frac{1}{H} \sum_{i=1}^H \left(W(e^{j\omega_i}; \theta) - \frac{\hat{B}_i}{A_i}e^{j\hat{\phi}_i} \right)^2
286 | \]
287 |
288 | \paragraph{Step 4} Optimization
289 |
290 | \[
291 | \hat{\theta} = \argmin_\theta J_H(\theta)
292 | \]
293 |
294 | Usually $J_H(\theta)$ is a non-quadratic and non-convex function, iterative optimization methods are needed.
295 |
296 | \begin{rem}[Frequency bandwidth selection $\omega_H =\; ?$]
297 | Theoretically the standard best solution should be $H$ points distributed uniformly from 0 to $\Omega_N$ (Nyquist).
298 |
299 | In practice it's better to concentrate the experimental effort in a smaller and more focused bandwidth.
300 |
301 | \begin{figure}[H]
302 | \centering
303 | \begin{tikzpicture}[node distance=1.5cm,auto,>=latex']
304 | \draw[->] (0,0) -- (5,0) node[right] {$\omega$};
305 | \draw (0,0.1) -- (0,-0.1) node[below] {$0$};
306 | \draw (0.8,0.1) -- (0.8,-0.1) node[below] {$\omega_c$};
307 | \draw (2,0.1) -- (2,-0.1) node[below] {$\Omega_N$};
308 | \draw (4,0.1) -- (4,-0.1) node[below] {$\Omega_S$};
309 | \end{tikzpicture}
310 | \end{figure}
311 |
312 | $\omega_c$ is the expected cut-off frequency of the closed system.
313 | A rule of thumb: $\omega_H \approx 3\omega_c$
314 |
315 | \paragraph{Example} The ESC (electronic stability control) has an expected bandwidth of $\omega_c \approx 2 \text{Hz}$, so $\omega_H \approx 6\text{Hz}$.
316 | \end{rem}
317 |
--------------------------------------------------------------------------------
/lectures/2022_04_27.tex:
--------------------------------------------------------------------------------
1 | %!TEX root = ../main.tex
2 |
3 | \externaldocument{2022_04_21}
4 | \externaldocument{2022_05_02}
5 |
6 | \section{Extensions of the \gls{kf} for General System}\label{sec:KF-extensions}
7 |
8 | \subsection{Exogenous input}
9 | \begin{figure}[H]
10 | \centering
11 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
12 | \node [block] (z1) at (1,5) {$z^{-1}$};
13 | \node [block] (F1) at (1,4) {$F$};
14 | \node [block] (K) at (1,2) {$K(t)$};
15 | \node [block] (z2) at (1,1) {$z^{-1}$};
16 | \node [block] (F2) at (1,0) {$F$};
17 |
18 | \node [block] (H1) at (4,5) {$H$};
19 | \node [block] (H2) at (4,1) {$H$};
20 |
21 | \node [block] (G1) at (-3,5) {$G$};
22 | \node [block] (G2) at (-3,1) {$G$};
23 |
24 | \node[left] (u) at (-4,5) {$u(t)$};
25 |
26 | \node [sum] (sum1) at (6,5) {};
27 | \node [sum] (sum2) at (7,2) {};
28 | \node [sum] (sum3) at (-1.5,5) {};
29 | \node [sum] (sum4) at (-1.5,1) {};
30 |
31 | \node (v1) at (-1.5,6) {$v_1(t)$};
32 | \node (v2) at (6,6) {$v_2(t)$};
33 | \node[right] (y) at (8,5) {$y(t)$};
34 | \node[right] (yhat) at (8,1) {$\hat{y}(t|t-1)$};
35 | \node[right] (xhat) at (8,0) {$\hat{x}(t|t-1)$};
36 |
37 | \node at (-1,2.3) {\emph{feedback}};
38 |
39 | \draw[->,red,line width=0.5mm] (u) -- (G1);
40 | \draw[->,red,line width=0.5mm] (G1) -- (sum3);
41 | \draw[->,red,line width=0.5mm] (-3.8,5) |- (G2);
42 | \draw[->,red,line width=0.5mm] (G2) -- (sum4);
43 | \draw[->] (v1) -- (sum3);
44 | \draw[->] (sum3) -- (z1) node[pos=0.5] {$x(t+1)$};
45 | \draw[->] (F1) -| (sum3);
46 | \draw[->] (z1) -- (H1) node[pos=0.5] {$x(t)$};
47 | \draw[->] (H1) -- (sum1);
48 | \draw[->] (v2) -- (sum1);
49 | \draw[->] (2.5,5) |- (F1);
50 | \draw[->] (K) -| (sum4);
51 | \draw[->] (sum4) -- (z2) node[pos=0.5] {$\hat{x}(t+1|t)$};
52 | \draw[->] (7,5) -- (sum2) node[pos=0.8] {$+$};
53 | \draw[->] (sum1) -- (y);
54 | \draw[<-] (K) -- (sum2) node[pos=0.5,black] {$e(t)$};
55 | \draw[->] (z2) -- (H2) node[pos=0.5] {$\hat{x}(t|t-1)$};
56 | \draw[->] (F2) -| (sum4);
57 | \draw[->] (2.5,1) |- (F2);
58 | \draw[->] (H2) -- (yhat);
59 | \draw[->] (7,1) -- (sum2) node[pos=0.8] {$-$};
60 | \draw[->] (F2) -- (xhat);
61 |
62 | \draw[dashed, blue] ($(G2) + (-1,-2)$) rectangle ($(sum2) + (1,1)$)
63 | node[left=1cm of G2] {$\mathcal{KF}$:};
64 |
65 | \end{tikzpicture}
66 | \end{figure}
67 |
68 | Notice that $K(t)$ remains the same because $P(t)$ is the covariance of the prediction error on $x(t)$ which remains the same because $Gu(t)$ doesn't introduce any additional noise or uncertainties to the system.
69 | That's because $Gu(t)$ is a totally known (deterministic) signal.
70 |
71 | \subsection{Multi-step Prediction}
72 |
73 | Assuming that $\hat{x}(t+1|t)$ is known from the basic solution, we can simply obtain a multi-step prediction as:
74 | \begin{align*}
75 | \hat{x}(t+2|t) &= F \hat{x}(t+1|t) \\
76 | \hat{x}(t+3|t) &= F \hat{x}(t+2|t) = F^2\hat{x}(t+1|t) \\
77 | \vdots \\
78 | \begin{cases}
79 | \hat{x}(t+k|t) = F^{k-1} \hat{x}(t+1|t) \\
80 | \hat{y}(t+k|t) = H\hat{x}(t+k|t)
81 | \end{cases}
82 | \end{align*}
83 |
84 |
85 | \subsection{Filter ($\hat{x}(t|t)$)}
86 |
87 | \[
88 | \hat{x}(t+1|t) = F\hat{x}(t|t) \quad \implies \quad \hat{x}(t|t) = F^{-1}\hat{x}(t+1|t)
89 | \]
90 | This formula can be used only if $F$ is invertible.
91 | If $F$ is not invertible, the filter can be obtained with a specific \emph{filter} formulation of \gls{kf}
92 |
93 | \begin{defn}[Kalman Filter in Filter Form] \label{KF-Filter_Form_sol}
94 | Reformulation of the equations described in \ref{subsec:KF-basic_sol}.\\
95 | State equation (\ref{eq:KF-DRE}) and Gain equation (\ref{eq:KF-gain}) becomes
96 | \begin{align*}
97 | \hat{x}(t|t) &= F\hat{x}(t-1|t-1) + Gu(t-1) + K_0(t)e(t) \\
98 | K_0(t) &= \left(P(t)H\transpose\right) \left(HP(t)H\transpose+V_2\right)^{-1} \\
99 | \end{align*}
100 | while the \gls{dre} equation (\ref{eq:KF-DRE}) remains unchanged.\\
101 |
102 | The initial condition for the new State equation is
103 | \begin{align*}
104 | \hat{x}(1|1) &= X_0
105 | \end{align*}
106 | \end{defn}
107 |
108 | \begin{rem}
109 | These equations are valid under the (legit) assumption $V_{12} = 0$.
110 | \end{rem}
111 |
112 | \begin{rem}
113 | Gain of \gls{kf} in prediction form (eq. \ref{eq:KF-gain} assuming $V_{12}=0$):
114 | \[
115 | K(t) = \left( FP(t)H\transpose \right) \left( HP(t)H\transpose+V_2 \right)^{-1}
116 | \]
117 |
118 | Gain of \gls{kf} in filter form:
119 | \[
120 | K_0(t) = \left(\textcolor{gray}{\cancel{F}} P(t)H\transpose \right) \left( HP(t)H\transpose+V_2 \right)^{-1}
121 | \]
122 |
123 | Therefore, the only difference is the elimination of $F$.
124 | \end{rem}
125 |
126 |
127 | \subsection{Time-varying systems}\label{subsec:time-varying_extension}
128 | In case of time-varying systems we have to perform the following substitutions:
129 | \begin{align*}
130 | F \mapsto F(t) \\
131 | G \mapsto G(t) \\
132 | H \mapsto H(t)
133 | \end{align*}
134 |
135 | Therefore
136 | \[
137 | \Sc: \begin{cases}
138 | x(t+1) = F(t)x(t) + G(t)u(t) + v_1(t) \\
139 | y(t) = H(t)x(t) + v_2(t)
140 | \end{cases}
141 | \]
142 |
143 | \begin{defn} [Linear Time Varying (LTV) system]
144 | The system $\Sc$ is a \emph{Linear Time Varying (LTV)} system, since its parameters ($F,G,H$) depends on the time instant $t$.
145 | \end{defn}
146 |
147 | Kalman Filter equations remain of the same form as the ones described in \ref{subsec:KF-basic_sol}: we just need to replace the parameter matrices ($F,G,H$) with the time-varying ones ($F(t),G(t),H(t)$).
148 |
149 | \subsection{Non-Linear Systems}
150 |
151 | This extensions is much more complicated. We will see Extended Kalman Filter (EKF) in section \ref{subsec:KF_non-lin_ext}.
152 |
153 | \section{Asymptotic Solution of Kalman Filter}
154 |
155 | \begin{rem}
156 | Even when the system $\Sc$ is an LTI, the Kalman Filter is not itself an LTI system: it is an LTV system, since it depends on the gain $K(t)$ which is time-varying.
157 | \end{rem}
158 |
159 |
160 | The fact that \gls{kf} is an LTV system is the source of 2 problems:
161 | \begin{itemize}
162 | \item Checking the asymptotic stability of \gls{kf} algorithm is very difficult, since the stability check of an LTV system is not simple as the stability check for LTI.
163 | \item Computational problem: $K(t)$ must be computed at each sampling time (e.g. every 5ms), including the inversion of $HP(t)H\transpose+V_2$ ($p\times p$ matrix) and the computation of $P(t)$ using the \gls{dre}.
164 | \end{itemize}
165 |
166 | \begin{rem}[Asymptotic Stability of a system]
167 |
168 | If the system is:
169 | \begin{itemize}
170 | \item LTI: $x(t+1) = Fx(t) + Gu(t)$ \\
171 | \qquad the stability check considers only the sign of the eigenvalues of $F$.
172 |
173 | \item LTV: $x(t+1) = F(t)x(t) + G(t)u(t)$ \\
174 | \qquad even if all the eigenvalues of $F(t)$ are strictly inside the unit circle at any time, the system is not guaranteed asymptotically stable.
175 | In practice it is, if the time-variations are \emph{slow} (e.g. aging).
176 | \end{itemize}
177 |
178 | \end{rem}
179 |
180 | Because of those problems in real/practical applications the asymptotic version of \gls{kf} is preferred.
181 |
182 | \paragraph{Basic idea}
183 | Since the dependency on $t$ of $K(t)$ derives from the presence of $P(t)$, if $P(t)$ converges to a constant value $\bar{P}$ (steady-state value of $P(t)$), then also $K(t)$ will converge to $\bar{K}$ (steady-state value of $K(t)$).
184 | \\
185 | Using $\bar{K}$ the \gls{kf} becomes an LTI system.
186 |
187 | Let's analyze the asymptotic stability of the State equation (eq. \ref{eq:KF-state}) of the asymptotic \gls{kf} when $\bar{K}$ is used (assuming it exists).
188 |
189 | \begin{align*}
190 | \hat{x}(t+1|t) &= F\hat{x}(t|t-1) + Gu(t) + \bar{K}e(t) \\
191 | &= F\hat{x}(t|t-1) + Gu(t) + \bar{K}(y(t) - \hat{y}(t|t-1)) \\
192 | &= F\hat{x}(t|t-1) + Gu(t) + \bar{K}(y(t) - H\hat{x}(t|t-1)) \\
193 | &= \underbrace{(F - \bar{K}H)}_{\text{new state matrix}} \hat{x}(t|t-1) + Gu(t) + \bar{K}y(t)
194 | \end{align*}
195 |
196 | \begin{figure}[H]
197 | \centering
198 | \begin{tikzpicture}[node distance=2.5cm,auto,>=latex']
199 | \node[block ] (K) at (1,1) {$\bar{K}$};
200 | \node[block ] (G) at (1,2) {$G$};
201 | \node[sum] (sum) at (3,1) {};
202 | \node[block ] (z) at (6,1) {$z^{-1}$};
203 | \node[block ] (fb) at (6,0) {$F-\bar{K}H$};
204 |
205 | \node[left] (y) at (0,1) {$y(t)$};
206 | \node[left] (u) at (0,2) {$u(t)$};
207 |
208 | \draw[->] (y) -- (K);
209 | \draw[->] (u) -- (G);
210 | \draw[->] (K) -- (sum);
211 | \draw[->] (sum) -- (z) node[pos=0.5] {$\hat{x}(t+1|t)$};
212 | \draw[->] (z) -- (9,1) node[pos=0.5] {$\hat{x}(t|t-1)$};
213 | \draw[->] (fb) -| (sum);
214 | \draw[->] (G) -| (sum);
215 | \draw[->] (7.5,1) |- (fb);
216 | \end{tikzpicture}
217 | \caption*{Asymptotic Kalman Filter with Exogenous input}
218 | \end{figure}
219 |
220 | \paragraph{Condition for Asymptotic Stability of \gls{kf}}
221 |
222 | If $\bar{K}$ exists, the \gls{kf} is asymptotically stable if and only if all the eigenvalues of $F-\bar{K}H$ are strictly inside the unit circle.
223 |
224 | \begin{rem}
225 | The stability of the system $\Sc$ is related to matrix $F$, whereas the stability of \gls{kf} is related to matrix $F-\bar{K}H$.
226 |
227 | Therefore, \gls{kf} can be asymptotically stable even if the system is unstable.
228 | \end{rem}
229 |
230 | \paragraph{Existance of $\bar{K}$}
231 | Starting from the equation \ref{eq:KF-gain}, if exists $P(t)$ such that $P(t) = \bar{P}$ then $K(t)$ becomes
232 |
233 | \[
234 | \bar{K} = \left(F\bar{P}H\transpose + V_{12}\right)\left(H\bar{P}H\transpose+V_2\right)^{-1}
235 | \]
236 |
237 | Thus, $\bar{K}$ exists if $\bar{P}$ exists.\\
238 |
239 | In order to check that, we need to check the converge properties of \gls{dre}
240 |
241 | \begin{rem}[Stability of a dynamical autonomous system]
242 | How to find the equilibrium points of a dynamical autonomous system?
243 | \begin{center}
244 | \begin{tabular}{c|c}
245 | \textbf{Continuous time} & \textbf{Discrete time} \\
246 | \hline\hline
247 | $\dot{x} = f(x(t))$ & $x(t+1) = f(x(t))$ \\
248 | \hline \\
249 | equilibrium when $\dot{x} = 0$ & equilibrium when $x(t+1) = x(t)$ \\
250 | $\downarrow$ & $\downarrow$ \\
251 | $f(\bar{x}) = 0$ & $f(\bar{x}) = \bar{x}$ \\
252 | \end{tabular}
253 | \end{center}
254 | \end{rem}
255 | \gls{dre} is an autonomous discrete time system, thus we impose $\bar{P} = f(\bar{P})$, where $f(\bar{P})$ is the \gls{dre} (eq. \ref{eq:KF-DRE}) evaluated in $\bar{P}$:
256 |
257 | \begin{flalign}\label{eq:KF-ARE}
258 | \nameeq{\bar{P} = \left( F\bar{P}F\transpose + V_1 \right)-\left(F\bar{P}H\transpose + V_{12}\right)\left(H\bar{P}H\transpose + V_2\right)^{-1}\left(F\bar{P}H\transpose+V_{12}\right)\transpose}{\acrshort{are}}
259 | \end{flalign}
260 |
261 | \begin{defn}[Algebraic Riccati Equation (ARE)]
262 | The equation \ref{eq:KF-ARE} is a non-linear, matrix, static algebraic equation, known as \emph{\acrfull{are}}.
263 | \end{defn}
264 |
265 | If a steady state $\bar{P}$ solution of \gls{dre} (eq. \ref{eq:KF-DRE}) does exists, it must be a solution of ARE (eq. \ref{eq:KF-ARE}).
266 | There remains 3 questions:
267 | \begin{enumerate}
268 | \item \textbf{Existence}: does \gls{are} have a semi-definite positive solution $\bar{P}$?
269 | \item \textbf{Convergence}: if exists, does the \gls{dre} converges to $\bar{P}$?
270 | \item \textbf{Stability}: is the corresponding $\bar{K}$ such that the \gls{kf} is asymptotically stable?
271 | \end{enumerate}
272 |
273 |
274 | To answer those questions we need two fundamental theorems (\gls{kf} asymptotic theorems).
275 |
276 | \subsection{Asymptotic Kalman Filter Theorems}
277 | The two Asymptotic Kalman Filter Theorems that we are going to introduce provide \emph{sufficient} conditions only.
278 |
279 | \begin{thm}[First Asymptotic \gls{kf} Theorem]\label{th:1KF_as}
280 | Assumptions: $V_{12} = 0$ and the system is asymptotically stable (i.e. all eigenvalues of $F$ are strictly inside the unit circle).
281 | Then:
282 | \begin{enumerate}
283 | \item \gls{are} has one and only one semi-definite positive solution: $\bar{P} \ge 0$.
284 | \item \gls{dre} converges to $\bar{P}$, $\forall P_0 \ge 0$ ($P_0$: initial semi-definite positive condition).
285 | \item The corresponding $\bar{K}$ is s.t. the \gls{kf} is asymptotically stable (i.e. all the eigenvalues of $F-\bar{K}H$ have absolute value less than $1$).
286 | \end{enumerate}
287 | \end{thm}
288 |
289 | \begin{rem}[Observability and Controllability]
290 | Recall on Observability and Controllability needed for the introduction of the Second Asymptotic \gls{kf} Theorem (\ref{th:2KF_as}).
291 |
292 | \paragraph{Observability of the state through the output}
293 |
294 | The pair $(F, H)$ is observable if and only if
295 | \[
296 | O = \begin{bmatrix}
297 | H \\
298 | HF \\
299 | \vdots \\
300 | HF^{n-1}
301 | \end{bmatrix}
302 | \qquad
303 | \text{is full rank}
304 | \]
305 |
306 | \paragraph{Controllability from the noise}
307 |
308 | We are interested in controllability from $v_1(t)$ (and not from $u(t)$).
309 |
310 | \begin{align*}
311 | x(t+1) = Fx(t) + \cancel{Gu(t)} + v_1(t) \qquad v_1(t) \sim WN(0, V_1)
312 | \end{align*}
313 |
314 | % \begin{align*}
315 | % x(t+1) = Fx(t) + v_1(t)
316 | % \end{align*}
317 |
318 | It's always possible to factorize $V_1 = \Gamma\cdot\Gamma^T$ rewriting
319 | \[
320 | x(t+1) = Fx(t) + \Gamma\omega(t) \qquad \omega(t) \sim WN(0, I)
321 | \]
322 |
323 | We can say that the state $x$ is controllable/reachable from the input noise $v_1(t)$ if and only if:
324 | \[
325 | R = \begin{bmatrix}
326 | \Gamma & F\Gamma & \cdots & F^{n-1}\Gamma
327 | \end{bmatrix}
328 | \qquad
329 | \text{is full rank}
330 | \]
331 | \end{rem}
332 |
333 |
334 | \begin{thm}[Second Asymptotic \gls{kf} Theorem]\label{th:2KF_as}
335 | Assumptions: $V_{12} = 0$, $(F, H)$ is observable and $(F, \Gamma)$ is controllable.
336 | Then:
337 | \begin{enumerate}
338 | \item \gls{are} has one and only one definite positive solution $\bar{P} > 0$.
339 | \item \gls{dre} converges to $\bar{P}$, $\forall P_0 \ge 0$ ($P_0$: initial semi-definite positive condition).
340 | \item The corresponding $\bar{K}$ is such that the \gls{kf} is asymptotically stable (i.e. all the eigenvalues of $F-\bar{K}H$ have absolute value less than $1$).
341 | \end{enumerate}
342 | \end{thm}
343 |
344 | \begin{rem}
345 | The difference between theorems \ref{th:1KF_as} and \ref{th:2KF_as} is that the first one ensures that $\bar{P} \ge 0$ while the second one ensures that $\bar{P} > 0$.
346 | \end{rem}
347 |
348 | These two theorems are very useful in practice because we can fully avoid the (very difficult) direct convergence analysis of \gls{dre}.
349 |
350 |
351 |
--------------------------------------------------------------------------------