# INVSID 1.0: An Inverse System Identification Toolbox for MATLAB
## 2 Creation of INVSID 1.0
### MATLAB Codes  
The corresponding MATLAB (R2020b) commands to realize the above mentioned inverse identification approach are illustrated step by step. Firstly the transfer function of a nominal model \(G_{\mathrm{d}}\) is given, then a state-space realization of the transfer function is made, afterwards the Bode plot is plotted. The process can be realized by following MATLAB codes. * ystf=tf(numerator,denominator,Ts);
* ysss=ss(systf);
* figure;
* According to the bandwidth of the nominal model \(G_{\text{d}}\), specify the frequencies \(f_{m}\), \(m=1,2,\ldots,N\), by using the rule stated in Remarks 1 and 2, and then stack all the frequencies into the vector \(F_{N}\), i.e., \[F_{N}= \begin{pmatrix}f_{1}\\ f_{2}\\ \vdots\\ f_{N}\end{pmatrix} .\] (21) Based on Equations (7) and (8), create the matrices \(A_{m}\) and \(C_{m}\) for \(m=1,2,\ldots,N\) in the models of the \(N\) discrete-time sine signals in the set \(S\), and then stack them into the matrices \(A_{N}\) and \(C_{N}\), respectively, i.e., \[A_{N}= \begin{pmatrix}A_{1}\\ A_{2}\\ \vdots\\ A_{N}\end{pmatrix} ,\] (22) and \[C_{N}= \begin{pmatrix}C_{1}\\ C_{2}\\ \vdots\\ C_{N}\end{pmatrix} .\] (23) We can obtain the following MATLAB codes for the above. * for m=1:dim
* AN(((2*m-1):2*m),:)=[cos(2*pi*FN(m,:)*Ts) sin(2*pi*FN(m,:)*Ts) -sin(2*pi*FN(m,:)*Ts) cos(2*pi*FN(m,:)*Ts)];
* for m=1:dim
* CN(m,:)=[1 0];
* end Step 3: With the created matrices \(A_{m}\) and \(C_{m}\) for \(m=1,2,\ldots,N\), create the matrices \(A_{\text{a},m}\), \(C_{\text{a},m}\), and \(C_{\text{r},m}\) for \(m=1,2,\ldots,N\) by using Equation (13), Equation (14), and
Equation (17), respectively. Then stack the matrices \(\mathbf{A}_{\mathrm{a},m}\) and \(\mathbf{C}_{\mathrm{a},m}\), \(m=1,2,\ldots,N\), into the matrices \(\mathbf{A}_{N}^{\mathrm{a}}\), \(\mathbf{C}_{N}^{\mathrm{a}}\), and \(\mathbf{C}_{N}^{\mathrm{r}}\), respectively, i.e.,  
\[\mathbf{A}_{N}^{\mathrm{a}}= \begin{pmatrix}\mathbf{A}_{\mathrm{a},1}\\ \mathbf{A}_{\mathrm{a},2}\\ \vdots\\ \mathbf{A}_{\mathrm{a},N}\end{pmatrix} , \tag{24}\]  
\[\mathbf{C}_{N}^{\mathrm{a}}= \begin{pmatrix}\mathbf{C}_{\mathrm{a},1}\\ \mathbf{C}_{\mathrm{a},2}\\ \vdots\\ \mathbf{C}_{\mathrm{a},N}\end{pmatrix} , \tag{25}\]  
and  
\[\mathbf{C}_{N}^{\mathrm{r}}= \begin{pmatrix}\mathbf{C}_{\mathrm{r},1}\\ \mathbf{C}_{\mathrm{r},2}\\ \vdots\\ \mathbf{C}_{\mathrm{r},N}\end{pmatrix} . \tag{26}\]  
Based on the expression of the model (18), calculate the transfer function of the reconstructors \(G_{\mathrm{inv},m}\) by using  
\[G_{\mathrm{inv},m}(z)=\mathbf{C}_{\mathrm{r},m}[z\mathbf{I}-(\mathbf{A}_{\mathrm{a},m}- \mathbf{L}_{\mathrm{a},m}\mathbf{C}_{\mathrm{a},m})]^{-1}\mathbf{L}_{\mathrm{a},m}, \tag{27}\]  
where the observer gain \(\mathbf{L}_{\mathrm{a},m}\) can be chosen in a linear least-squares sense for stochastic systems, i.e., the observer gain \(\mathbf{L}_{\mathrm{a},m}\) can be obtained as the gain of the steady-state Kalman filter for the model (11) with process noise and measurement noise or can be obtained in a minimum mean-integral squared error sense [24]. Denote the process noise and measurement noise as \(\mathbf{w}(k)\in\mathbb{R}^{n_{\mathrm{a}}}\) with \(n_{\mathrm{a}}=n_{\mathrm{d}}+2\) and \(v(k)\in\mathbb{R}\), respectively, and assume that both \(\{\mathbf{w}(k),k=1,2,\ldots\}\) and \(\{v(k),k=1,2,\ldots\}\) are white Gaussian sequences, \(\mathbf{w}(k)\sim N(0,\mathbf{Q})\) with \(\mathbf{Q}>\mathbf{0}\), \(v(k)\sim N(0,R)\) with \(R>0\), and assume that the distribution of \(\mathbf{x}_{\mathrm{a},m}(0)\) is Gaussian, and assume that \(\{\mathbf{w}(k),k=1,2,\ldots\}\) and \(\{v(k),k=1,2,\ldots\}\) are uncorrelated with \(\mathbf{x}_{\mathrm{a},m}(0)\) and with each other.