Search

Search papers and lessons

System Identification

Level 3 · 11 min read

System identification builds a mathematical model of a system from recorded inputs and outputs, usually by fitting its unknown coefficients with least squares.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Discrete math
  • Calculus
  • Control systems
  • Inference
  • Sign in to see your progress

TL;DR

System identification is the work of building a mathematical model of a system from measurements. You apply an input, record the output, and fit the model's unknown numbers so that it reproduces what you recorded. The most common route is least squares, the same method used to fit a straight line through scattered points.

The model is only as good as the data. The input has to move enough to reveal how the system responds, and the fitted model has to predict data it has not seen.

Where you'll see it: in tuning a controller for a motor or a chemical plant when nobody has the physics equations, in flight-control software that estimates an aircraft's response from test flights, and in the learned dynamics models that robots use to plan their motion.

Intuition

Learning a machine from its behaviour

Suppose you are handed a closed box with a dial on the front and a needle on the back. You turn the dial and watch the needle. After enough turns you can predict where the needle will go for any setting of the dial, without opening the box. You have identified the system from its behaviour alone.

Engineers face this problem constantly. A motor has friction, inertia and electrical resistance, and the exact values are rarely on a datasheet. A furnace has heat leaks that depend on the building. Writing down the physics from first principles is slow and often inaccurate. Measuring the response and fitting a model is faster, and the fitted model is tied to the system as it actually behaves.

The method has three steps, and they repeat in a loop:

flowchart LR
  A[Apply a varying input] --> B[Record the output]
  B --> C[Fit the model's coefficients]
  C --> D[Check it on fresh data]
  D -->|good enough| E[Use the model]
  D -->|poor| A

The systems considered here are the kind described by a linear dynamical system: the next output is a fixed weighted combination of earlier values and inputs. The simplest useful model describes the next output as a weighted sum of recent outputs and recent inputs. The weights are the unknown numbers. Once they are found, the model can predict and, for control design, can be inverted to ask what input will produce a wanted output.

The math

A first-order input-output model

Let yty_t be the output at time step tt, utu_t the input, and ete_t an unexplained error or noise term. Consider the model

yt=a yt−1+b ut−1+et.y_t = a\, y_{t-1} + b\, u_{t-1} + e_t.

Here aa and bb are the unknown numbers we want to find. The output depends on its own previous value, scaled by aa, and on the previous input, scaled by bb. A model that has this form, with an output that depends on its own past and on an outside input, is called an ARX model. Its name says what it is: autoregressive, with an exogenous input. The "autoregressive" part is the same idea as in an autoregressive model of a sequence, and adding an outside input to a model of this kind is what separates ARX from the plain ARMA model. The "exogenous" part is the input we control.

The equation is linear in aa and bb, and that is what makes identification easy. If we set ete_t aside for a moment, we want yty_t to be close to a yt−1+b ut−1a\,y_{t-1} + b\,u_{t-1} for every recorded step.

Writing it as a regression

Collect the known past values into a vector for each time step, φt=(yt−1,ut−1)\boldsymbol{\varphi}_t = (y_{t-1}, u_{t-1}), and the unknown numbers into θ=(a,b)\boldsymbol{\theta} = (a, b). The model becomes

yt≈φt⊤θ.y_t \approx \boldsymbol{\varphi}_t^\top \boldsymbol{\theta}.

This is exactly the setup of linear regression, with the regressors φt\boldsymbol{\varphi}_t built from past data rather than supplied separately. We choose θ\boldsymbol{\theta} to minimise the sum of squared errors over all NN recorded steps:

S(θ)=∑t=1N(yt−φt⊤θ)2.S(\boldsymbol{\theta}) = \sum_{t=1}^{N} \left(y_t - \boldsymbol{\varphi}_t^\top \boldsymbol{\theta}\right)^2.

Stack the regressors into a matrix Φ\Phi with one row φt⊤\boldsymbol{\varphi}_t^\top per time step, and stack the outputs into a vector y\mathbf{y}. The minimiser satisfies the normal equations

(Φ⊤Φ)θ^=Φ⊤y,\left(\Phi^\top \Phi\right) \hat{\boldsymbol{\theta}} = \Phi^\top \mathbf{y},

and when Φ⊤Φ\Phi^\top \Phi is invertible, θ^=(Φ⊤Φ)−1Φ⊤y\hat{\boldsymbol{\theta}} = (\Phi^\top \Phi)^{-1} \Phi^\top \mathbf{y}. The hat on θ^\hat{\boldsymbol{\theta}} marks it as an estimate computed from data.

Why squared errors? If the error ete_t follows a Gaussian distribution with the same variance at every step, then the maximum likelihood estimate of θ\boldsymbol{\theta} is the one that minimises SS. Taking the logarithm of the Gaussian likelihood turns the product over steps into a sum, and the only part that depends on θ\boldsymbol{\theta} is the sum of squared errors. Least squares is therefore the right answer under a standard noise assumption, not just a convenient one.

Persistent excitation

The input has to vary, and this is the most common way identification fails. Look at the second column of Φ\Phi: it contains the past inputs ut−1u_{t-1}. If the input is zero at every step, that column is all zeros. Then ∑tut−12=0\sum_t u_{t-1}^2 = 0, the matrix Φ⊤Φ\Phi^\top \Phi has a zero row and a zero column, and it cannot be inverted. The data contain no information about bb at all.

A signal that keeps changing, such as one that switches between two levels at random times, keeps the matrix invertible and reveals how the system responds at many operating points. Engineers call this requirement persistent excitation.

Worked examples

Example
A tiny exact dataset

Take the true system a=0.5a = 0.5, b=2b = 2, with y0=0y_0 = 0 and inputs u0=1u_0 = 1, u1=0u_1 = 0, u2=1u_2 = 1, u3=0u_3 = 0. There is no noise, so the data are exact.

  1. Compute the outputs: y1=0.5⋅0+2⋅1=2y_1 = 0.5 \cdot 0 + 2 \cdot 1 = 2.
  2. y2=0.5⋅2+2⋅0=1y_2 = 0.5 \cdot 2 + 2 \cdot 0 = 1.
  3. y3=0.5⋅1+2⋅1=2.5y_3 = 0.5 \cdot 1 + 2 \cdot 1 = 2.5.
  4. y4=0.5⋅2.5+2⋅0=1.25y_4 = 0.5 \cdot 2.5 + 2 \cdot 0 = 1.25.
  5. Build the rows φt=(yt−1,ut−1)\boldsymbol{\varphi}_t = (y_{t-1}, u_{t-1}) for t=1,…,4t = 1, \dots, 4: (0,1)(0, 1), (2,0)(2, 0), (1,1)(1, 1) and (2.5,0)(2.5, 0), with targets 2,1,2.5,1.252, 1, 2.5, 1.25.
  6. Compute the entries of Φ⊤Φ\Phi^\top\Phi. The sum of yt−12y_{t-1}^2 is 0+4+1+6.25=11.250 + 4 + 1 + 6.25 = 11.25. The sum of yt−1ut−1y_{t-1}u_{t-1} is 0+0+1+0=10 + 0 + 1 + 0 = 1. The sum of ut−12u_{t-1}^2 is 22. So Φ⊤Φ=(11.25112)\Phi^\top\Phi = \begin{pmatrix} 11.25 & 1 \\ 1 & 2 \end{pmatrix}.
  7. Compute Φ⊤y\Phi^\top\mathbf{y}. The sum of yt−1yty_{t-1}y_t is 0+2+2.5+3.125=7.6250 + 2 + 2.5 + 3.125 = 7.625. The sum of ut−1ytu_{t-1}y_t is 2+0+2.5+0=4.52 + 0 + 2.5 + 0 = 4.5.
  8. Solve. The determinant is 11.25⋅2−1=21.511.25 \cdot 2 - 1 = 21.5, so a^=(2⋅7.625−1⋅4.5)/21.5=10.75/21.5=0.5\hat a = (2 \cdot 7.625 - 1 \cdot 4.5)/21.5 = 10.75/21.5 = 0.5 and b^=(−7.625+11.25⋅4.5)/21.5=43/21.5=2\hat b = (-7.625 + 11.25 \cdot 4.5)/21.5 = 43/21.5 = 2.

Interpretation: with exact data, least squares recovers the true numbers exactly. Real data will not be this clean, but the procedure is identical.

Example
The same system with measurement noise

Now suppose the measured outputs are off by small errors. The recorded values are y^1=2.1\hat y_1 = 2.1, y^2=0.9\hat y_2 = 0.9, y^3=2.7\hat y_3 = 2.7 and y^4=1.15\hat y_4 = 1.15, with y^0=0\hat y_0 = 0 known exactly. The inputs are unchanged.

  1. The regressors are now (0,1)(0, 1), (2.1,0)(2.1, 0), (0.9,1)(0.9, 1) and (2.7,0)(2.7, 0), with targets 2.12.1, 0.90.9, 2.72.7 and 1.151.15.
  2. The sum of y^t−12\hat y_{t-1}^2 is 0+4.41+0.81+7.29=12.510 + 4.41 + 0.81 + 7.29 = 12.51. The sum of y^t−1ut−1\hat y_{t-1}u_{t-1} is 0+0+0.9+0=0.90 + 0 + 0.9 + 0 = 0.9. The sum of ut−12u_{t-1}^2 is 22.
  3. The sum of y^t−1y^t\hat y_{t-1}\hat y_t is 0+1.89+2.43+3.105=7.4250 + 1.89 + 2.43 + 3.105 = 7.425. The sum of ut−1y^tu_{t-1}\hat y_t is 2.1+0+2.7+0=4.82.1 + 0 + 2.7 + 0 = 4.8.
  4. The determinant is 12.51⋅2−0.81=24.2112.51 \cdot 2 - 0.81 = 24.21. So a^=(2⋅7.425−0.9⋅4.8)/24.21=10.53/24.21≈0.435\hat a = (2 \cdot 7.425 - 0.9 \cdot 4.8)/24.21 = 10.53/24.21 \approx 0.435 and b^=(−0.9⋅7.425+12.51⋅4.8)/24.21=53.37/24.21≈2.20\hat b = (-0.9 \cdot 7.425 + 12.51 \cdot 4.8)/24.21 = 53.37/24.21 \approx 2.20.
  5. Compare with the truth, a=0.5a = 0.5 and b=2b = 2.

Interpretation: the estimate of bb is close, but aa has dropped to about 0.4350.435. The noise sits in the regressor y^t−1\hat y_{t-1} as well as in the target, which pulls the estimate of aa toward zero. One small dataset cannot prove a bias, but shrinkage toward zero is the known tendency, a weakness of plain least squares when the regressors are themselves noisy, and it is the reason more careful methods exist.

Example
A realistic tank or motor model, with analytic numbers

Consider a heated tank sampled every Ts=0.1T_s = 0.1 s. Suppose the true model has a=0.95a = 0.95 and b=0.04b = 0.04. These values are chosen for the calculation, not measured from a real tank.

  1. The steady-state gain is b/(1−a)=0.04/0.05=0.8b/(1-a) = 0.04/0.05 = 0.8. A sustained input of 1 settles the output at 0.8.
  2. The time constant, the time for the response to cover about 63 percent of its change, is τ=−Ts/ln⁡a=0.1/0.0513≈1.95\tau = -T_s/\ln a = 0.1/0.0513 \approx 1.95 s.
  3. To identify it in practice, drive the heater with a signal that switches randomly between two levels, so the input keeps moving. Record the input and output for several minutes.
  4. Fit the ARX model on the first 70 percent of the record. Then predict the last 30 percent one step at a time, using the measured past, and compute the mean squared error. Small error on the unseen part is the evidence that the model is usable.
  5. If the fitted aa and bb reproduce the steady gain and time constant above, the model matches the system's behaviour at this operating point.

Interpretation: the identified numbers become design inputs. A time constant near 2 seconds tells the controller how quickly it can act, and a gain of 0.8 tells it how strongly the heater changes the temperature.

Tradeoffs and failure modes

SituationWhat goes wrongBetter choice
The input is constant, or nearly soSome coefficients cannot be separated from the dataUse a persistently exciting input that keeps changing
Measurement noise enters the regressorsEstimates are biased, typically toward zeroUse a method that models the noise, or [[instrumental-variables
Too many coefficients for the dataThe model fits the recording perfectly and predicts poorly, the classic OverfittingUse fewer coefficients and check on held-out data
The system is strongly nonlinearA linear model fits only near the operating pointIdentify several local models, or use a [[nonlinear-dynamical-system

The main tradeoff is between model simplicity and accuracy. A low-order model is easy to fit and easy to control with, but it may miss fast dynamics. A high-order model can match the data more closely while predicting worse. Validation on fresh data is the only reliable way to choose between them.

History

Least squares was introduced by Gauss and Legendre in the early 1800s, and Gauss used it to predict the orbit of the asteroid Ceres from a few observations. The idea of fitting a dynamic model to recorded inputs and outputs grew in control engineering through the 1950s and 1960s. In the early 1970s, Karl Åström and Peter Eykhoff surveyed the field in a widely read review. Lennart Ljung's later work on prediction error methods put the theory on a firm statistical footing, and it is now a standard part of control practice. Estimation with a Kalman filter, which tracks an unknown state as data arrive, grew out of the same period.

Recap

A system can be identified from recorded behaviour by choosing a model with unknown coefficients, writing its prediction as a regression on past inputs and outputs, and fitting the coefficients by least squares. The fit is the maximum likelihood estimate under Gaussian noise. The input must keep changing for the coefficients to be identifiable, and the model must be checked on data it did not see. Where the regression assumes too little about the noise, the estimates drift. The same idea extends to state-space models, which are the subject of the Kalman filter, and to model predictive control, which uses an identified model to plan inputs ahead of time.

Check yourself

QuestionRecall: in the model yt=a yt−1+b ut−1+ety_t = a\,y_{t-1} + b\,u_{t-1} + e_t, what is the role of ut−1u_{t-1}, and why is it called exogenous?Show answer

ut−1u_{t-1} is the input from the previous step. It is called exogenous because it comes from outside the system, set by the experimenter or the controller, rather than being generated by the system's own past outputs.

QuestionComputation: with a=0.5a = 0.5, b=2b = 2, y0=0y_0 = 0 and u0=1u_0 = 1, what is y1y_1? Then, if u1=0u_1 = 0, what is y2y_2?Show answer

y1=0.5⋅0+2⋅1=2y_1 = 0.5 \cdot 0 + 2 \cdot 1 = 2. Then y2=0.5⋅2+2⋅u1=1+0=1y_2 = 0.5 \cdot 2 + 2 \cdot u_1 = 1 + 0 = 1.

QuestionWhy: if the input is zero at every step, why can the coefficient bb not be estimated from the data?Show answer

Every regressor in the second column of Φ\Phi is ut−1=0u_{t-1} = 0. The matrix Φ⊤Φ\Phi^\top\Phi then has a zero row and column, so it cannot be inverted. The data contain no evidence of how the input affects the output, so every value of bb fits equally well.

QuestionApplied: you identify a process and get a model that fits the training recording almost perfectly, but predicts badly on a new recording. What did you probably do wrong, and what would you change?Show answer

The model probably has too many coefficients and has fitted the noise in the training data, which is overfitting. Use a lower-order model, and choose the order by checking prediction error on data that were not used to fit it.

Sources