Always free. For everyone.
Course outline
Module 16 of 20 · Applied control

Identify and validate a plant

Estimate models from experiments and test them on unseen input sequences. This module has 3 lessons and takes about 2h 25m. Each lesson has a practice exercise that runs real Python in your browser and a short quiz.

Start module 16 in the Learning Lab
LESSON 1 OF 3

Fit a discrete model with least squares

35 minControl engineering
WHAT YOU WILL DO

Estimate an ARX model from input and output records.

A first order ARX model writes y[k+1]=a*y[k]+b*u[k]+error[k]. Stack rows [y[k],u[k]] into a design matrix X and targets y[k+1] into a vector. Solve X*theta approximately equals target for theta=[a,b].

Use np.linalg.lstsq rather than explicitly inverting X.T*X. The input must excite the dynamics enough to distinguish a and b. A constant record at equilibrium often leaves many models consistent with the same data.

This basic least-squares fit assumes suitable residual behaviour. Noise on y[k] can bias the estimate because a regressor becomes correlated with error. The synthetic first exercise is noise-free so you can verify indexing and parameter recovery first.

See it in action

example.pyPython 3
import numpy as np
u=np.array([1.,0.,-1.,1.,0.5,-0.5,1.,0.])
y=[0.]
for command in u: y.append(0.8*y[-1]+0.2*command)
y=np.array(y)
X=np.column_stack([y[:-1],u])
theta=np.linalg.lstsq(X,y[1:],rcond=None)[0]
print('Estimated [a,b]:',theta)
Keep this in mind

Correct indexing and informative experiments come before a fitted coefficient.

LESSON 2 OF 3

Excitation, residuals, and validation

35 minControl engineering
WHAT YOU WILL DO

Separate model fitting from evidence that a model predicts new data.

A useful experiment varies the input across relevant time scales while respecting actuator and plant limits. A reproducible pseudo-random input can reveal dynamics better than a single constant value. Inspect the design matrix rank and singular values.

One-step prediction uses the measured y[k] at every step. Free-run simulation recursively uses its own predicted state after the initial sample. A model can look accurate one step ahead but drift during free-run simulation.

Keep a separate input sequence for validation. Report RMSE with units, residual mean, and residual correlation with previous input. Structured residuals suggest missing dynamics, delay, or bias. Good synthetic performance does not establish field accuracy.

See it in action

example.pyPython 3
import numpy as np
measured=np.array([0.,0.2,0.36,0.488])
predicted=np.array([0.,0.18,0.34,0.47])
residual=measured-predicted
print('RMSE:',np.sqrt(np.mean(residual**2)))
print('Residual mean:',residual.mean())
Keep this in mind

A model should explain data it did not fit.

LESSON 3 OF 3

Practical: identify, validate, then control

75 minControl engineering
WHAT YOU WILL DO

Recover a plant from one experiment and validate on another.

Generate a training input with a fixed random seed, simulate a=0.85,b=0.3, and estimate the parameters. Validate on a separate step-and-pulse sequence. Keep the true coefficients only for evaluating your estimator.

For a stable first order ZOH model with 0<a<1, tau=-Ts/ln(a) and DC gain K=b/(1-a). A delay or extra pole can make these conversions misleading, so inspect residuals before treating the model as physical.

The checked task estimates physical parameters from exact fitted coefficients. Extend the experiment by adding measurement noise, repeating with different training inputs, and comparing free-run errors before selecting a controller.

GUIDED PRACTICAL · 75 MIN

Your experiment plan

Use the browser editor or the downloadable notebook. All plant data are simulated. Keep a notebook with parameters, predictions, results, and units.

  1. Generate a seeded training record and fit a,b.
  2. Validate free-run output on an unseen pulse sequence.
  3. Repeat with noise and report parameter spread across five seeds.
  4. Design a modest PI controller from the fitted model and test it on the original plant.

What to hand in

  • Training and validation plots kept separate.
  • Parameter estimates and validation RMSE.
  • A controller test on a plant not replaced by its fitted model.
Reflect on your results

Which assumption matters most? Describe one result that surprised you and one experiment that would test your explanation.

The automatic exercise checks the core code behaviour. Review observations and written deliverables yourself or with a mentor.

See it in action

example.pyPython 3
import numpy as np
rng=np.random.default_rng(42)
u=rng.choice([-1.,1.],size=200)
y=np.zeros(len(u)+1)
for k in range(len(u)): y[k+1]=0.85*y[k]+0.3*u[k]
theta=np.linalg.lstsq(np.column_stack([y[:-1],u]),y[1:],rcond=None)[0]
print('Fitted:',theta)
print('Gain:',theta[1]/(1-theta[0]),'Time constant:',-0.1/np.log(theta[0]))
Keep this in mind

Identify, validate, and redesign in separate steps.

ABOUT THE LEARNING LAB

Free, open and run by a nonprofit.

This page is part of Control Engineering, a free course of 20 modules and 60 lessons in the engineering.fit( ) Learning Lab. The Learning Lab is built and run by engineering.fit( ), a nonprofit founded by Abdullateef Opeyemi Bakare that helps African engineering students gain research experience. You do not need an account or pay a fee to learn.

Course outline · Project lab · Visit engineering-fit.org