# INVSID 1.0: An Inverse System Identification Toolbox for MATLAB
## 2 Creation of INVSID 1.0
### Inverse System Identification Toolbox Creation  
Building the inverse system identification toolbox consists of two parts. * Based on the MATLAB codes of inverse identification obtained in Section 2.2, a MATLAB function file, which is an m-file, can be created. The specific content of the m-file is given in Listing 1. MATLAB function of inverse system identification. ```
1 functionGinv=INVSID Toolbox(numerator,denominator,Ts,fb,d,N,pc,mc,nx)
2%numeratoranddenominator:ThennumeratoranddenominatorcoefficientsoftthetransferfunctionofthenominalmodelG_d. 3%Ts:ThesamplingperiodofthenominalmodelG_d. 4%fb:Thesmallestfrequencyamongthefrequencycomponentsforinversystemidentification. 5%d:Thecommondifference. 6%N:Thenumberofthefrequencycomponentsforinverseystemidentification. 7%pc:Thecovarianceoftheprocessing. 8%mc:Thecovarianceofthemasurementnoise. 9%nx:Vectorofmodelorderstoscan. 10%Ginv:Theidentifiedinversemodel. 12%%StepI
13 systf=tf(numerator,denominator,Ts);
14 syssss=ss(systf);
15 figure;
16 opts=bodeoptions;
17 opts.FreqUnits='Hz';
18 bode(sysss,opts);
19
20%%StepII
21 dim=N;
22 FN=zeros(dim,1);
23 form=1:dim
24 FN(m,:)=fb+(m-1)*d;
25 end
26 AN=zeros(2*dim,2);
27 form=1:dim
28 AN(((2*m-1):2*m),:)=[cos(2*pi*FN(m,:)*Ts)sin(2*pi*FN(m,:)*Ts)
29-sin(2*pi*FN(m,:)*Ts)cos(2*pi*FN(m,:)*Ts)];
30 end
31 CN=zeros(dim,2);
32 form=1:dim
33 CN(m,:)=[1 0];
34 end
35
36%%StepIII
37r1=size(sysss.a,1)+2;
38 AN=zeros(r1*dim,r1);
39 form=1:dim
40r2=1+(m-1)*r1;
41 AN(r2:r1*m,:)=[sysss.a sysss.b*CN(m,:)
42 zeros(2,size(sysss.a,1))AN(((2*m-1):2*m),:)];
43 end
44 CaN=zeros(dim,r1);
45 form=1:dim
46 CaN(m,:)=[sysss.c sysss.d*CN(m,:)];
47 end
48 CrN=zeros(dim,r1);
49 form=1:dim
50 CrN(m,:)=[zeros(1,size(sysss.a,1)) CN(m,:)];
51 end
52 LN=zeros(r1,dim);
53 form=1:dim
54Q=pc*eye(r1);
55R=mc;
56r2=1+(m-1)*r1;
57 LN(:,m)=dlqr(AaN(r2:r1*m,:)',CaN(m,:)',Q,R)';
58 end
59g=cell(dim,1);
60 GN=zeros(dim,1);
61 form=1:dim
62r2=1+(m-1)*r1;
63 sysr=ss(AaN(r2:r1*m,:)-LN(:,m)*CaN(m,:),LN(:,m),CrN(m,:),0,Ts);



According to the transfer function (33), the following observations can be made:

1. \(G_{\rm d}\) is stable. 2. \(G_{\rm d}\) is proper. 3. \(G_{\rm d}\) is minimal-realized. 4. \(G_{\rm d}\) has one nonminimum-phase zero. According to the above observations, it can be known that the direct inversion of the system \(G\) is a challenging problem. So we now turn to using the proposed toolbox INVSID 1.0 to identify the inverse model of the system \(G\). The proposed inverse identification approach can specify the frequency range of interest, i.e., by selecting the values of \(f_{\rm b}\), \(m\), and \(d\) in Equation (9), the frequency range to be identified can be determined. The parameters shown in Table 1 are used as the inputs of the inverse identification toolbox. With the above inputs, the final output of the inverse identification toolbox is the identified inverse model which is the best model corresponding to the recommended singular value. The model order of the identified inverse model \(\hat{G}_{\rm inv}\) is recommended to be 4. The frequency response properties of the model \(\hat{G}_{\rm inv}\) with fourth order are demonstrated in Figure 4.

In addition, the inversion \(\hat{G}_{\rm inv}\) is identified using the MATLAB function n4 sid with stability enforcement, so the identified model \(\hat{G}_{\rm inv}\) is stable and causal. \begin{table}
\begin{tabular}{l l} \hline \hline
**Parameter** & **Value in MATLAB** \\ \hline numerator & \([0,1,0]\) \\ denominator & \([1,-1.5,0.7]\) \\ \(T_{\rm s}\) & \(1\times 10^{-5}\) \\ \(f_{\rm b}\) & \(10\) \\ \(d\) & \(10\) \\ \(N\) & \(50\) \\ pc & \(1\times 10^{-3}\) \\ mc & \(1\times 10^{-3}\) \\ nx & \(2\):\(10\) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Parameters for inverse identification. Figure 3: Bode plot of \(G_{\rm d}\). By connecting the model \(G_{\text{d}}\) and the model \(\hat{G}_{\text{inv}}\) in series using Equation (19), the model \(G_{\text{s}}\) can be obtained.