---
title: System identification
heading: Models from data: step tests and the two-point FOPDT fit, second-order fits from overshoot, frequency-response tests, least squares for discrete models, and why the input must excite the plant
eyebrow: S9 · Lesson 6 · System identification
xp: 50
---

::: hook
Lesson 2 built models from physics: masses, resistances, motor constants. Real plants rarely come with all their numbers. The heater's thermal resistance depends on airflow, the motor's friction on temperature, the process's dead time on pipe lengths nobody measured. So control engineers routinely measure the model instead: kick the plant with a step, a sine or a random signal, record what comes out, and fit a model with the few parameters a controller design needs.
:::

::: play
- The solid curve is the step response of a plant $1/(s + 1)^3$; the dashed one is a first-order-plus-dead-time (FOPDT) model fitted by the two-point method.
- The fit matches the true response where it crosses 28.3% and 63.2%, at 1.85 s and 3.26 s, giving τ = 2.11 s and θ = 1.15 s.
- Elsewhere it's off by up to 0.11 of the step, good enough to tune a PI controller and a reminder that every model is an approximation.
:::

```sim plot
view: graph
x: t = 0..10 s
y: y = 0..1.1
plot: 1 - exp(-t)*(1 + t + t^2/2) | label: plant 1/(s + 1)³
plot: step(t - 1.147)*(1 - exp(-(t - 1.147)/2.110)) | dashed | label: FOPDT fit
plot: 0.283 + 0*t | dashed | label: 28.3%
plot: 0.632 + 0*t | dashed | label: 63.2%
```

::: predict
## A step test's output reaches 28.3% of its final change at 1.7 s and 63.2% at 3.0 s after the step. What time constant does the two-point method give?

- [ ] 3.0 s
- [x] 1.95 s
- [ ] 1.3 s
- [ ] 0.65 s

::: reveal
A first-order response reaches 28.3% at θ + τ/3 and 63.2% at θ + τ, so the two times differ by 2τ/3: τ = 1.5 × (3.0 − 1.7) = 1.95 s, and the dead time is θ = 3.0 − 1.95 = 1.05 s. The two-point method uses the middle of the response, where noise matters least.
:::
:::

::: nameit
## Step tests

Step the input by Δu with the plant at rest and record the output. The **gain** is the final change over the step, $K = \Delta y/\Delta u$. For a first-order-plus-dead-time model $Ke^{-\theta s}/(\tau s + 1)$, with $t_{28}$ and $t_{63}$ the times to 28.3% and 63.2% of the final change,
$$\tau = 1.5\,(t_{63} - t_{28}), \qquad \theta = t_{63} - \tau$$
A response that overshoots is fitted with a second-order model instead: the overshoot gives ζ (lesson 7's formula), and the period of the ringing $T_d$ gives $\omega_d = 2\pi/T_d$ and $\omega_n = \omega_d/\sqrt{1 - \zeta^2}$.

## Model reduction by the half rule

Skogestad's half rule turns a known higher-order model $Ke^{-\theta_0s}/\prod(\tau_is + 1)$ into FOPDT: keep the largest time constant, add half the second largest to it and the other half to the dead time, and add all the smaller ones to the dead time.

## Frequency-response tests

Drive the plant with a sine at ω, wait for the transient to die, and measure the output's amplitude ratio and phase. A first-order plant $K/(\tau s + 1)$ lags by $\tan^{-1}\omega\tau$ and has gain $K/\sqrt{1 + \omega^2\tau^2}$, so one measured phase gives τ and the gain then gives K. A sweep over frequency gives the whole Bode plot, including resonances a step test would blur.

## Least squares for discrete models

Sampled every T, a first-order plant obeys $y_{k+1} = ay_k + bu_k$. Stacking the samples into a regression and solving the normal equations
$$\begin{pmatrix} \sum y_k^2 & \sum y_ku_k \\ \sum y_ku_k & \sum u_k^2 \end{pmatrix}\begin{pmatrix} a \\ b \end{pmatrix} = \begin{pmatrix} \sum y_{k+1}y_k \\ \sum y_{k+1}u_k \end{pmatrix}$$
gives the parameters, and from them $\tau = -T/\ln a$ and $K = b/(1 - a)$.

## Excitation

Data identify only what the input excites. A constant input says nothing about dynamics; a slow input says nothing about fast poles. With noise of standard deviation σ, a gain estimated from N samples of an input with mean square P has standard deviation $\sigma/\sqrt{NP}$, so bigger, richer inputs and longer records both help.
:::

::: example
## Fit an FOPDT model to the plant $1/(s + 1)^3$ by the two-point method, and compare with the half rule.

::: solution
1. **Read the two crossings.** The step response
   $$y(t) = 1 - e^{-t}(1 + t + t^2/2)$$
   crosses 28.3% at 1.85 s and 63.2% at 3.26 s.
2. **Time constant.**
   $$\begin{aligned} \tau &= 1.5 \times (3.26 - 1.85) \\ &= 1.5 \times 1.41 \\ &= 2.11\ \text{s} \end{aligned}$$
3. **Dead time.**
   $$\begin{aligned} \theta &= 3.26 - 2.11 \\ &= 1.15\ \text{s} \end{aligned}$$
4. **Half rule.** It gives
   $$\begin{aligned} \tau &= 1 + 0.5 \\ &= 1.5\ \text{s} \\ \theta &= 0.5 + 1 \\ &= 1.5\ \text{s} \end{aligned}$$
   a slower model with more dead time, which tunes a more cautious controller.
5. **Gain.** Both have the same gain, 1.

**Answer:** the two-point fit gives τ = 2.11 s and θ = 1.15 s, and the half rule gives τ = θ = 1.5 s; both have a gain of 1.
:::
:::

::: example
## Sampled every 0.1 s, a plant's data fit $y_{k+1} = 0.9y_k + 0.2u_k$. What continuous model does that describe?

::: solution
1. **Time constant.** The pole a = 0.9 corresponds to $e^{-T/\tau}$, so
   $$\begin{aligned} \tau &= \frac{-0.1\ \text{s}}{\ln 0.9} \\ &= 0.949\ \text{s} \end{aligned}$$
2. **DC gain.** At steady state the difference equation reads $y = 0.9y + 0.2u$, so
   $$\begin{aligned} K &= \frac{0.2}{0.1} \\ &= 2 \end{aligned}$$
3. **The model.** Assuming a hold on the input, which is how the data were taken:
   $$P(s) = \frac{2}{0.949s + 1}$$

**Answer:** the data describe $2/(0.949s + 1)$, a gain of 2 with a 0.949 s time constant.
:::
:::

::: example
## A sine test at 2 Hz on a first-order plant measures a gain of 0.5 and a phase of −60°. What are K and τ?

::: solution
1. **Time constant from the phase.**
   $$\begin{aligned} \omega\tau &= \tan 60° \\ &= 1.732 \\ \tau &= \frac{1.732}{2\pi \times 2} \\ &= 0.138\ \text{s} \end{aligned}$$
2. **Gain from the magnitude.**
   $$\begin{aligned} K &= 0.5\sqrt{1 + 1.732^2} \\ &= 0.5 \times 2 \\ &= 1.0 \end{aligned}$$
3. **Check the model.** A second frequency would check the first-order assumption: if the phase there disagreed with $\tan^{-1}\omega\tau$, the plant has more dynamics than one pole.

**Answer:** K = 1.0 and τ = 0.138 s.
:::
:::

::: check
kind: parts
given: a = 4 | 6 | 8; d = 1.5 | 3 | 6; D = 2 | 10; U = 1 | 5

## A step of {U} in the input changes the output by {D} in the end; it reaches 28.3% of that change {a} s after the step and 63.2% {d} s after the 28.3% point.

::: part
answer: 1.5*d
unit: s
tolerance: 0.5%

### What time constant does the two-point method give?

::: misses
- [d] The two points are 2τ/3 apart.
- [any] $\tau = 1.5(t_{63} - t_{28})$.
:::
:::

::: part
answer: a + d - 1.5*d
unit: s
tolerance: 1%

### What dead time?

::: misses
- [any] $\theta = t_{63} - \tau$.
:::
:::

::: part
answer: D/U
tolerance: 0.5%

### What gain?

::: misses
- [any] $\Delta y/\Delta u$.
:::
:::
:::

::: check
kind: parts
given: a = 0.5 | 0.8 | 0.95 | 0.99; b = 0.05 | 0.3; T = 1 | 10 | 100

## A least-squares fit of sampled data gives $y_{k+1} = \given{a}y_k + \given{b}u_k$ with a sample period of {T} ms.

::: part
answer: -T/ln(a)
unit: ms
tolerance: 0.5%

### What time constant does that describe?

::: misses
- [T*(1 - a)] Close only when a is near 1; exactly, $\tau = -T/\ln a$.
- [any] $a = e^{-T/\tau}$.
:::
:::

::: part
answer: b/(1 - a)
tolerance: 0.5%

### What DC gain?

::: misses
- [b] Find the steady state: $y = ay + bu$.
- [any] $b/(1 - a)$.
:::
:::
:::

::: check
kind: parts
given: f = 0.5 | 2 | 10; p = 30 | 45 | 70; g = 0.2 | 1 | 4

## A sine test on a first-order plant at {f} Hz measures a phase of −{p}° and a gain of {g}.

::: part
answer: tan(p*pi/180)/(2*pi*f)
unit: s
tolerance: 0.5%

### What is τ?

::: misses
- [tan(p*pi/180)/f] Use ω = 2πf.
- [any] $\omega\tau = \tan\phi$.
:::
:::

::: part
answer: g*sqrt(1 + tan(p*pi/180)^2)
tolerance: 0.5%

### What is K?

::: misses
- [any] $K = |G|\sqrt{1 + \omega^2\tau^2}$.
:::
:::
:::

::: check
kind: parts
given: M = 10 | 20 | 35; T = 0.1 | 0.5 | 2

## A step test overshoots by {M}% and rings with a period of {T} s.

::: part
answer: -ln(M/100)/sqrt(pi^2 + ln(M/100)^2)
tolerance: 0.5%

### What damping ratio does a second-order fit give?

::: misses
- [any] $\zeta = -\ln M_p/\sqrt{\pi^2 + \ln^2M_p}$.
:::
:::

::: part
answer: 2*pi/T/sqrt(1 - ln(M/100)^2/(pi^2 + ln(M/100)^2))
unit: rad/s
tolerance: 0.5%

### What natural frequency?

::: misses
- [2*pi/T] That's $\omega_d$; divide by $\sqrt{1 - \zeta^2}$.
- [any] $\omega_n = \frac{2\pi/T_d}{\sqrt{1 - \zeta^2}}$.
:::
:::
:::

::: check
kind: parts
given: h = 0 | 1 | 3; a = 5 | 10 | 20; b = 1 | 2 | 4; c = 0.2 | 0.5

## A plant $e^{-\given{h}s}/((\given{a}s + 1)(\given{b}s + 1)(\given{c}s + 1))$ is reduced to FOPDT by the half rule.

::: part
answer: a + b/2
unit: s
tolerance: 0.5%

### What time constant results?

::: misses
- [a] Add half the second-largest time constant.
- [any] $\tau_1 + \tau_2/2$.
:::
:::

::: part
answer: h + b/2 + c
unit: s
tolerance: 0.5%

### What dead time?

::: misses
- [h + b/2] The smallest time constant counts as dead time too.
- [any] $\theta_0 + \tau_2/2 + \tau_3$.
:::
:::
:::

::: check
kind: parts
given: s = 0.01 | 0.05 | 0.2; N = 100 | 1000 | 10000; P = 0.25 | 1 | 4; e = 0.001 | 0.003

## A gain is estimated by least squares from {N} samples of an input with mean square {P}, with output noise σ = {s}.

::: part
answer: s/sqrt(N*P)
tolerance: 0.5%

### What is the estimate's standard deviation?

::: misses
- [s/N] Noise averages down as the square root of the samples.
- [any] $\sigma/\sqrt{NP}$.
:::
:::

::: part
answer: s^2/(e^2*P)
unit: samples
tolerance: 0.5%

### How many samples would bring it to {e}?

::: misses
- [any] Solve $\sigma/\sqrt{NP} = $ {e}.
:::
:::
:::

::: check
kind: choice

## A plant's data were logged for an hour while its controller held the setpoint perfectly steady and nothing disturbed it. Why can't a model be fitted from them?

- [ ] The sample rate was too low
- [x] Nothing excited the plant: input and output sat at constant values, which fit any model with the right gain ratio, so the dynamics are invisible in the data
- [ ] The controller hides the plant's gain
- [ ] An hour is too short

::: misses
- [1] No sample rate reveals dynamics that never moved.
- [3] The DC gain could be found from two different steady states, but not the dynamics.
- [4] A longer record of the same constant values adds nothing.
:::
:::

::: check
kind: derivation
vars: a = 0.01..0.999, b = 0.001..10, T = 0.0001..1

## A sampled first-order model $y_{k+1} = ay_k + bu_k$ with sample period T.

::: step
answer: -T/ln(a)

### What is the time constant?
:::

::: step
answer: b/(1 - a)

### What is the DC gain?
:::

::: step
answer: ln(a)/T

### Where is the continuous pole?
:::

::: right
Right. Sampling maps the pole s to $a = e^{sT}$, and the logarithm maps it back.
:::
:::

::: check
kind: python

## Write `fit_arx(u, y)`: the least-squares a and b in $y_{k+1} = ay_k + bu_k$ from lists u and y (use pairs k = 0 to N − 2), and `two_point(t, y)`: τ and θ by the two-point method from a sampled step response starting at rest (interpolate the crossing times linearly; take the final value as the last sample).

```python starter
def fit_arx(u, y):
    return 0.0, 0.0

def two_point(t, y):
    return 1.0, 0.0
```

```python solution
def fit_arx(u, y):
    syy = sum(y[k] * y[k] for k in range(len(y) - 1))
    syu = sum(y[k] * u[k] for k in range(len(y) - 1))
    suu = sum(u[k] * u[k] for k in range(len(y) - 1))
    r1 = sum(y[k + 1] * y[k] for k in range(len(y) - 1))
    r2 = sum(y[k + 1] * u[k] for k in range(len(y) - 1))
    det = syy * suu - syu * syu
    return (r1 * suu - r2 * syu) / det, (syy * r2 - syu * r1) / det

def two_point(t, y):
    yf = y[-1]
    def cross(level):
        for k in range(1, len(y)):
            if y[k] >= level * yf:
                return t[k - 1] + (level * yf - y[k - 1]) / (y[k] - y[k - 1]) * (t[k] - t[k - 1])
    t28, t63 = cross(0.283), cross(0.632)
    tau = 1.5 * (t63 - t28)
    return tau, t63 - tau
```

```python tests
import math, random
r = random.Random(3)
u = [r.choice((-1, 1)) for _ in range(500)]
y = [0.0]
for k in range(499):
    y.append(0.9 * y[-1] + 0.2 * u[k])
a, b = fit_arx(u, y)
assert abs(a - 0.9) < 1e-9 and abs(b - 0.2) < 1e-9, "Noise-free data give the exact parameters."
yn = [v + r.gauss(0, 0.01) for v in y]
a, b = fit_arx(u, yn)
assert abs(a - 0.9) < 0.02 and abs(b - 0.2) < 0.02, "Light noise: close."
t = [k * 0.01 for k in range(2001)]
yt = [1 - math.exp(-s) * (1 + s + s * s / 2) for s in t]
tau, th = two_point(t, yt)
assert abs(tau - 2.110) < 0.01 and abs(th - 1.147) < 0.01, "1/(s + 1)³: τ = 2.11 s, θ = 1.15 s."
```

::: right
Right. The normal equations are a 2 × 2 solve; with noise in y the estimate of a is slightly biased, which more elaborate methods correct.
:::
:::

::: explain
## Why does identifying a plant require an input that excites it, and what makes a good test signal?

::: model
A model describes how the output responds to changes in the input, so the data must contain such changes at the frequencies the model needs to capture. If the input stays constant, every model with the right gain ratio fits the data equally well and the dynamics are invisible. A good test signal is large enough to rise well above the noise but small enough to keep the plant in its linear range, and rich enough in frequency to excite the poles that matter: a step excites low frequencies and the main time constant, while sweeps or random binary sequences reach faster dynamics. Longer records average the noise down, as the square root of the number of samples.
:::
:::

::: practice
::: check
given: a = 1 | 4; d = 2 | 5
answer: 1.5*d
unit: s
tolerance: 0.5%

## Two-point τ when the 63.2% point comes {d} s after the 28.3% point?

::: misses
- [any] $\tau = 1.5(t_{63} - t_{28})$.
:::
:::

::: check
given: a = 0.7 | 0.95; T = 5 | 20
answer: -T/ln(a)
unit: ms
tolerance: 0.5%

## τ from a discrete pole {a} at T = {T} ms?

::: misses
- [any] $\tau = -T/\ln a$.
:::
:::

::: check
given: p = 30 | 60; f = 1 | 5
answer: tan(p*pi/180)/(2*pi*f)
unit: s
tolerance: 0.5%

## τ from −{p}° at {f} Hz?

::: misses
- [any] $\tau = \tan\phi/\omega$.
:::
:::
:::
