Moving Horizon Estimation on a Digital Twin

The Temperature Control Lab board with two heaters, two sensors and a USB cable

Open the TCLab Control Studio app

Advanced Control Exercise 7 of 30 in Estimation · All exercises · Time: 15 minutes

The TCLab digital twin runs the same energy balance as the board. Here heater 1 is weaker than the MPC's model thinks: 150 of a nominal 200. A bias estimator hides that error as an offset. A moving horizon estimator refits the heater gain from the last 20 s of data while the MPC runs on it. Students with a board can repeat the run on hardware, where the mismatch is real.

Learning Outcomes

  • Formulate moving horizon estimation of states and bounded parameters over a sliding window.
  • Compare an output-bias estimator with an MHE that re-estimates the plant under the same MPC.
  • Explain what the arrival cost carries from data that has left the window, and why excitation matters.

Book Chapter

Process Dynamics, Modeling, and Identification (Volume 1), Chapter 4, A Two-Heater Digital Twin That Runs Beside the Device It Models. Read the chapter, open the PDF, or watch the lecture slides.

Theory in Brief

The twin's heater temperatures `T_{H1}, T_{H2}` and sensor temperatures `T_1, T_2` follow an energy balance. For heater 1, with power `Q_1` in percent, `\beta_1 = 200/5720` °C/s per percent at the nominal capacity, a heater gain `g_1` (1 when the heater is as built), a loss rate `\lambda = 1/\tau_a`, coupling time `\tau_c` and sensor lag `\tau_s`:

$$\frac{dT_{H1}}{dt} = g_1 \beta_1 Q_1 + \lambda \left(T_a - T_{H1}\right) - \frac{T_{H1} - T_{H2}}{\tau_c}, \qquad \frac{dT_1}{dt} = \frac{T_{H1} - T_1}{\tau_s}$$

The MHE joins the four temperatures `x` and the slow parameters `p = (g_1, g_2, \lambda, T_a)` into one state `z = (x, p)`, lets `p` drift as a random walk, and every second fits the last `N` = 20 s of measurements:

$$\min_{z_{t-N},\,w} \; \left\| z_{t-N} - \bar z_{t-N} \right\|^2_{P^{-1}} + \sum_{k=t-N}^{t} \left\| y_k - C z_k \right\|^2_{R^{-1}} + \sum_{k} \left\| w_k \right\|^2_{Q_w^{-1}}$$

$$\mathrm{subject\;to} \quad z_{k+1} = F(z_k, u_k) + w_k, \qquad p_{lo} \le p_k \le p_{hi}$$

Here `R` and `Q_w` are noise covariances, not control weights. The first term is the arrival cost. It carries what was learned before the window, with `P` from a Riccati update. The bias estimator instead adds a filtered offset `\hat d = y - C\hat x` to a model that keeps `g_1 = 1`. That removes steady error but leaves every predicted move the wrong size.

Model: Physics-based, combined with data. The four-state TCLab energy balance, with four parameters refitted online from measurements.
Decision: Both heater powers every second, from an MPC that plans 90 s ahead on the estimated model.
Learning: Online parameter estimation is learning from a stream of data, bounded by physics and by the parameter limits.

Exercise

Read 2 min · Predict 1 min · Run 7 min · Explain 3 min · Check your AI 2 min.

Predict. Heater 1 delivers 75 % of the power the MPC's model assumes. After a 5 °C setpoint step, will the MPC with the bias estimator still reach the setpoint? Which estimator do you expect to settle faster, and what value of `g_1` should the MHE find?

Run the TCLab Control Studio app. The TCLab studio runs up to 10× and keeps a session clock; the steps give clock times.

  1. Open Settings (Simulation and safety settings). Set Heater 1 capacity to 150 and Sensor noise to 0, press Apply settings, then Reset. Set the sim speed to 10× and press MPC.
  2. Keep the estimator on Bias · default. When the clock reads 4:00, raise the T1 setpoint from 45 to 50 °C. At 9:00, note when T1 last came within 0.5 °C of 50 °C, then press Export CSV (Reset clears the record).
  3. Set the T1 setpoint back to 45 °C, press Reset, press MPC again (Reset returns to Manual), and choose MHE. Repeat the step at 4:00 and export again at 9:00. Read g1 in the MHE readout under the MPC card.
  4. From each CSV, the integral error is the sum of |setpoint_t1_c − sim_t1_c| times the time step, from the step to 5 min after it.

Explain.

  1. Why does the bias estimator still reach the setpoint, and what does it get wrong on the way?
  2. The 20 s window at 9:00 holds no step. Why does the MHE still report a good g1, and what would sensor noise do to it?

Generative AI Learning

"I have an MPC on a two-heater lab with a bias update. Heater 1 lost a quarter of its power. Should I switch to a moving horizon estimator that estimates the heater gain? What could go wrong with estimating it online?"

Check the answer against your run: A good answer says the bias removes offset but not the wrong move size, and warns that a gain and a loss trade off when the data do not excite both. Your two integral errors test the first claim. The help beside Estimator tests the second. The assistant is your tutor and reviewer; you answer for every claim you turn in.

What to Turn In

A screenshot of the MHE readout at 9:00, a two-row table (bias, MHE) with the settling time and the integral error from each CSV, your written prediction, and three sentences that answer the two questions.

Both estimators bring T1 to 50 °C. After the step the integral error is 3.9 °C·min with the bias estimator and 3.1 °C·min with the MHE. T1 stays within 0.5 °C of the setpoint 1.5 min after the step with the bias estimator and 1.1 min after it with the MHE. The MHE's readout shows g1 = 0.77, against the true 150/200 = 0.75.

The bias estimator reaches the setpoint because the offset `\hat d` absorbs any constant mismatch. Its plans are the wrong size, though. The model thinks each percent of Q1 is worth a third more than it is, so the first moves are too small. In the 30 s after the step heater 1 averages 86 % with the bias estimator and 91 % with the MHE.

At 9:00 the window holds only steady data. The estimate of g1 was made earlier, while the heat-up and the step excited the heater, and with no noise the arrival cost carries it forward. Because the parameters are random walks, that information slowly fades. With the default 0.2 °C noise the gain and the loss trade off along the direction that steady data cannot see, and g1 wanders, often to its 1.275 bound. An estimate is only as good as the excitation behind it.

Measured with the app build of December 3, 2026 by a scripted replay of the steps above. Numbers that no tile shows come from the replay's record; your readings from the trends will be close. A later app release may move the last digit.

TCLab E and Moving Horizon Estimation build an MHE in GEKKO with `IMODE=5`. Fit `g_1` and `\lambda` on a window of your exported CSV with and without the step inside the window, and compare the parameter confidence intervals. That is the observability argument in numbers.

Related

References

  1. Hedengren, J. D. (ed.), Process Dynamics, Modeling, and Identification, Volume 1 of Interactive Control Engineering, Chapter 4, "A Two-Heater Digital Twin That Runs Beside the Device It Models", pp. 84–111, Advanced Process Solutions, 2026. PDF (CC BY 4.0).
  2. Rao, C. V., Rawlings, J. B., Mayne, D. Q., Constrained state estimation for nonlinear discrete-time systems: stability and moving horizon approximations, IEEE Transactions on Automatic Control 48(2), 246–258, 2003.
  3. Spivey, B. J., Hedengren, J. D., Edgar, T. F., Constrained nonlinear estimation for industrial process fouling, Industrial & Engineering Chemistry Research 49(17), 7824–7831, 2010.

Course Information

TCLab

Project

Applications

Advanced Control Exercises

Exams

Modeling

Machine Learning

Estimation

Control

Reinforcement Learning

Related Courses

Admin