System Identification Loss Function Selection
Selecting the correct loss function in MATLAB System Identification Toolbox aligns the estimated model with your operational goal, such as feedback control, short-term forecasting, or noise rejection.
1. Primary Loss Functions and Selection Criteria
| Loss Function | Best For | MATLAB Option / Setting |
|---|---|---|
| Prediction Error (1-Step Ahead) | Kalman filtering, real-time tracking, adaptive control | opt.Focus = 'prediction' |
| Simulation Error (Infinite Horizon) | Model predictive control (MPC), digital twins, open-loop simulation | opt.Focus = 'simulation' |
| Robust Loss (Huber / Bisquare) | Datasets with measurement outliers or sensor spikes | opt.RobustCost = 'Huber' |
| Frequency-Weighted Loss | Targeting specific bandwidths or resonance frequencies | opt.Focus = [f_low, f_high] |
| Regularized Loss (L2 / Ridge) | High-order models with ill-conditioned matrices | opt.Regularization.Lambda = 0.01 |
2. Simulation vs. Prediction Focus
Prediction error minimizes error one step ahead using past measured outputs. Simulation error evaluates full multi-step trajectory rollout without feeding back true measured states.
% Load identification dataset
load iddata1 z1;
% 1. Simulation Focus: Ideal for open-loop simulation & MPC
opt_sim = ssestOptions;
opt_sim.Focus = 'simulation';
model_sim = ssest(z1, 2, opt_sim);
% 2. Prediction Focus: Ideal for state estimation & filtering
opt_pred = ssestOptions;
opt_pred.Focus = 'prediction';
model_pred = ssest(z1, 2, opt_pred);
% Compare both models against validation data
figure('Color', 'w');
compare(z1, model_sim, model_pred);
legend('Measured', 'Simulation Focus', 'Prediction Focus');
3. Robust Loss for Outlier Suppression
Standard quadratic error squares outliers, which distorts estimated poles and zeros. Huber and Bisquare loss functions linearize error penalties above a specified threshold.
% Configure robust optimization options
opt_robust = tfestOptions;
opt_robust.RobustCost = 'Huber'; % Options: 'Huber', 'Bisquare', 'Cauchy'
opt_robust.Display = 'on';
% Estimate transfer function from noisy data with spikes
np = 2; % Number of poles
nz = 1; % Number of zeros
sys_tf = tfest(z1, np, nz, opt_robust);
4. Frequency-Weighted Loss for Control Design
When you need high model fidelity only around your controller crossover frequency (e.g., 0.1 to 10 rad/s), filter the loss function focus:
opt_freq = oeOptions;
opt_freq.Focus = [0.1, 10]; % Passband range in rad/s
% Estimate Output-Error (OE) model focusing on specified frequency band
model_oe = oe(z1, [2 2 1], opt_freq);
% Check frequency response fit
figure('Color', 'w');
bode(model_oe);
grid on;
5. Regularization to Prevent Over-Parameterization
Add a penalty term (lambda) on parameter magnitudes when identifying high-order transfer functions or state-space models to prevent overfitting.
opt_reg = armaxOptions;
opt_reg.Regularization.Lambda = 1e-3; % Ridge penalty weight
opt_reg.Regularization.R = eye(5); % Metric weighting matrix
model_armax = armax(z1, [2 2 2 1], opt_reg);
Decision Rule:
- If you use the model in Simulink for full open-loop runs or MPC: Choose
Focus = 'simulation'. - If you use the model in a Kalman Filter or for 1-step forecasting: Choose
Focus = 'prediction'. - If your sensors have occasional glitches or dropouts: Enable
RobustCost = 'Huber'.
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Explore similar technical troubleshooting questions and verified MATLAB solutions: