Simple Offline Least Squares System Identification Example


Jump to: navigation, search
Simple Offline Least Squares System Identification Example
Green carrot left.gif
Green carrot.jpg
In order to prevent spam, users must register before they can edit or create articles.

1 Introduction to the Simple Offline Least Squares System Identification Example

Sometimes the best way to learn something is through a simple example. This simple example uses a continuous second order system as the system to be identified. The input/output relationship is saved in the Data Capture scope. There is a discrete model based on the least squares approximation. The final discrete transfer function block uses the transfer funciton returned by MATLAB's C2D function.

The results of the C2D function provide a discrete transfer function (via the Tustin Method) which is stable and provides similar results to that of the continuous time system. The least squares method provides a discrete transfer function good for interpolation of response points between measured points. However, the least squares method does not provide a discrete transfer function which is stable.

1.1 Refresher from Offline Least Squares

See Also

Below is a refresher from the Offline Least Squares article. The equation shows the minimum amount of data required for a least squares solution but it also shows how to use the input and output to form the mathematics for a least squares solution. The minimum amount of required data results in

LaTeX: \begin{bmatrix}u\left(k\right) & u\left(k-1\right) & -\hat{y}\left(k-1\right) & -\hat{y}\left(k-2\right) \\ u\left(k+1\right) & u\left(k\right) & -\hat{y}\left(k\right) & -\hat{y}\left(k-1\right) \\ u\left(k+2\right) & u\left(k+1\right) & -\hat{y}\left(k+1\right) & -\hat{y}\left(k\right) \\ u\left(k+3\right) & u\left(k+2\right) & -\hat{y}\left(k+2\right) & -\hat{y}\left(k+1\right)\end{bmatrix}\begin{bmatrix}b_{0} \\ b_{1} \\ a_{1} \\ a_{2}\end{bmatrix}+\begin{bmatrix}\nu\left(k\right) \\ \nu\left(k+1\right) \\ \nu\left(k+2\right) \\ \nu\left(k+3\right)\end{bmatrix}=\begin{bmatrix}\hat{y}\left(k\right) \\ \hat{y}\left(k+1\right) \\ \hat{y}\left(k+2\right) \\ \hat{y}\left(k+3\right)\end{bmatrix} Eqn. 2

2 Simple Simulink Model

Figure 1: Simple System ID Model

Figure 1 shows a simple system identification model. The model show a second order transfer function for the model to ID. The input is random and noise is added to system output. The noisy output is captured by the Data Capture scope. The discrete version of the ID'd system is the Discrete Least Squares Model. And it's output along with the noisy output are captured in the Model Comparison scope.

Transfer Function Parameters

 >> f = 100;
 >> w = f * (2*pi);
 >> z = 1/sqrt(2);

Using MATLAB's C2D Command the discrete model of the second order system is

 >> a = tf([w^2], [1, 2*z*w, w^2]);
 >> b = c2d(a, 1/10000);
         0.001916 z + 0.00186
         z^2 - 1.911 z + 0.915

2.1 Forming the parameter estimates

The data from Data Capture scope is saved to the ParamID variable. From this variable we can form the parameter estimates. The input and output vectors are formed with the following code:

 >> t = ParamID.time;
 >> y = ParamID.signals(2).values;
 >> r = ParamID.signals(1).values;

The least squares solution is formed using the following equation:

LaTeX: y=A\theta


LaTeX: A is the input/output data,
LaTeX: y is the output and
LaTeX: \theta are the least squares parameters.

The input/output data relationship where A

LaTeX: A=\begin{bmatrix}R & -Y\end{bmatrix}

where Y is formed with the following code

 Y = [];
 for i = 1:order
   Y = [Y, y((1+i):(end-(order-i)))];

and R is formed with the following code

 R = [];
 for i = 1:order
   R = [R, r(i:end-(order-i+1))];

The loop using order allows for an A matrix which is flexible. The size of the Y and R matrices are based on the order of the model you wish to form - in our case an order of 2. This type of formation assumes that there is plenty of excess data available. In this example I saved data at 10 kHz for 10 seconds and only require 4 data points.

The equation for finding the least squares parameter set is

LaTeX: \theta=A^{-1}y

We find the system parameters with the following MATLAB code

 >> theta = pinv(A) * y;

3 Results

Figure 2: Results for least squares parameter identification
Figure 3: Zoom-in on Results

The results of the least squares parameter estimation is a discrete model good for interpolation. However, when the offline least squares solution is used online it does not perform well as can be seen in Figure 4.

Figure 4: Online Comparison Results

4 Resources