Unscented Kalman Filter — Control Systems/State Estimation
Control_Systems/State_Estimation/Unscented_Kalman_Filter · 2 input / 1 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
Unscented Kalman Filter
Control Systems / State Estimation
Estimates the states of a nonlinear discrete-time plant from a noisy measurement. The plant is
x[k+1] = f(x[k], u[k]) + w[k], y[k] = h(x[k], u[k]) + v[k], with cov(w) = Q and cov(v) = R,
and f and h are expressions you type over the state and input variables you name. Instead of linearizing them, the filter pushes 2n + 1 sigma points – the estimate and a symmetric spread around it, sized by the covariance – through f and h, and takes the mean and covariance of what comes out. No derivative is ever formed, so f and h may be anything the expression language can write.
It is MATLAB's own unscented Kalman filter
(unscentedKalmanFilter, which Simulink's block runs) in its
square-root form: the covariance is carried as a factor S with
P = S·S', updated by QR factorizations and rank-one Cholesky updates.
The factory setting is a forced Van der Pol oscillator, stepped by forward Euler at 0.05 s, whose position x1 is measured: feed the oscillator's input on u and its noisy position on y, and xhat recovers the velocity nobody measured.
Ports
- u – the known plant input, a column [p,1] in the order of Input Variables. With no input variables it must be a scalar, and it is ignored.
- y – the measurement, a column [m,1] (m = the entries of Measurement h).
- xhat – the state estimate, a column [n,1] in the order of State Variables.
Parameters
- State Variables – the n state names, separated by spaces: 1 to 6 of them.
- Input Variables – the p input names, 0 to 6 of them; leave it empty for a plant with no input.
- State Transition f – the next state f(x, u): a column of n expressions over the state and input variables.
- Measurement h – the measurement h(x, u): a column of 1 to 6 expressions.
- Alpha – the spread of the sigma points around the estimate, greater than 0 and at most 1; MATLAB's default 1e-3.
- Beta – prior knowledge of the distribution, 0 or greater; 2 is optimal for a Gaussian, MATLAB's default.
- Kappa – a secondary spread parameter, from 0 to 3; MATLAB's default 0.
- Process Noise Q – [n,n], symmetric positive semidefinite; a scalar is taken as that value times the identity.
- Measurement Noise R – [m,m], symmetric positive definite (the gain divides by it); a scalar expands the same way.
- Initial State – x[0], n entries.
- Initial State Covariance – P[0], [n,n] symmetric positive definite, or a positive scalar: the first correction updates its triangular Cholesky factor.
- Estimator Type – Current publishes x̂[k|k], corrected with the measurement of the same sample (Simulink's default); Delayed publishes x̂[k|k−1], the prediction made before it.
- Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
Code export
All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text. Each prints the same description of the filter that the simulation itself runs – f and h written in the target's own syntax at every sigma point, the QR factorizations, the Cholesky updates and their fallback unrolled – so every target does the same arithmetic in the same order. The noise factors, the weights and the initial state are baked in at export time.
⚠ The three HDL targets run the filter in simulation-only real arithmetic, quantizing only at the port boundaries: a covariance factor and a triangular solve span many decades, which a Q16.16 datapath does not carry.
Simulink bridge
None (Support::None). Simulink's block (Control System
Toolbox and System Identification Toolbox, cstblocks/State
Estimation/Unscented Kalman Filter) names its state transition and
measurement as MATLAB functions on the path, not as expressions, so there
is nothing a model could carry across; the bridge reports this block rather than
dropping it silently. Code export verification still covers it across all ten
languages.
Notes
- Discrete only, and stateful: the estimate and the covariance factor persist from sample to sample.
- ⚠ At MATLAB's default Alpha of 1e-3 the filter agrees with MATLAB to about 1e-10, not bit for bit: the sigma-point weights are about a million and cancel, and MATLAB run against itself with the initial state moved by one ulp differs by the same amount. From Alpha 0.05 upward the two agree to about 1e-15.
- When a rank-one Cholesky downdate would leave the factor indefinite – often, at small Alpha – the filter does what MATLAB does: it re-factors the covariance from an eigen-decomposition, taking the square root of each eigenvalue's magnitude.
- Carries no state space: the filter is nonlinear, and f and h describe the PLANT, not this block.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/State_Estimation/Unscented_Kalman_Filter |
| family | Control_Systems/State_Estimation |
| solver environment class | ICoreBlock_0_Control_Systems_1_State_Estimation_2_Unscented_Kalman_Filter |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/State_Estimation/Unscented_Kalman_Filter/ICoreBlock_0_Control_Systems_1_State_Estimation_2_Unscented_Kalman_Filter.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/State_Estimation/Unscented_Kalman_Filter/ICoreBlock_0_Control_Systems_1_State_Estimation_2_Unscented_Kalman_Filter.h |
| default size on canvas | 150 × 90 px |
| ports at insert | 2 in, 1 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | u |
| 2 | in | ICoreDouble | y |
| 3 | out | ICoreDouble | xhat |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
| Config variable | Default | Simulink parameter |
|---|---|---|
State Variables | x1 x2 | — |
Input Variables | u | — |
State Transition f | [x1 + 0.05*x2; x2 + 0.05*((1 - x1^2)*x2 - x1 + u)] | — |
Measurement h | x1 | — |
Alpha | 1e-3 | — |
Beta | 2 | — |
Kappa | 0 | — |
Process Noise Q | [0.001 0; 0 0.01] | — |
Measurement Noise R | 0.2 | — |
Initial State | [2; 0] | — |
Initial State Covariance | 1 | — |
Estimator Type | Current%~%Delayed~~Current | — |
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::None |
| Simulink path | — |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
Caveat (shown to the user): Simulink's Unscented Kalman Filter block names its state transition and measurement as MATLAB functions on the path, and ICore's are typed expressions, so nothing a model could carry maps onto it. The block is reported rather than dropped when a model crosses
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The checker has a blind spot here — it could not resolve something (a grouped port bullet, a computed config name), which is reported and never counted as a pass. A reader has to settle it:
B0no sample under docs/generated/samples/ — nothing to cross-check (P8.1)
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
Unscented Kalman Filter -- MATLAB's square-root UKF over typed f(x, u) and h(x, u) sigma x and x +- sqrt(alpha^2 (n + kappa)) * the columns of S correct h through the sigma points -> ymean, Sy, Pxy; x = x + K (y - ymean); S downdated output x[k|k] (current estimator) or x[k|k-1] (delayed) predict f through the sigma points -> x, S; S = qrFactor(I, S, Qs)
The filter is ICoreUnscentedKalmanSupport's, written once for the live run and once as statements for the ten exports. This file holds the configuration, the ports, the state (x and S, zero until the first sample takes them from the configuration) and the per-target wrappers -- the same ones Extended Kalman Filter uses.
⚠ MEASURED AGAINST R2026a's unscentedKalmanFilter (the object the Simulink block runs) on 400 random problems of 1 to 4 states, 1 to 3 measurements and 0 to 2 inputs, 25 samples each, alpha, beta and kappa drawn across MATLAB's ranges:
alpha from 0.05 to 1 224 / 228 within 1e-12, median 1.6e-15 alpha = 1e-3 (default) median 2.2e-10
and MATLAB against ITSELF, with the initial state moved by one ulp, gives medians of 1.3e-15 and 2.1e-10 on the same problems: at the default alpha the unscented weights are ~1e6 and cancel, so no two correct implementations agree further. cholupdate is a builtin whose rotations are matched to 1 ulp, not bit for bit. The eight problems MATLAB itself drives to Inf or NaN are excluded. The emitted Python matches the live run bit for bit, 400 / 400.
Sample results#
No sample run is committed for this block. Samples come from the headless harness (DOCS_PLAN.md P8.1) into docs/generated/samples/; until one exists this block's behaviour is witnessed by the parity and export-verification suites, not by a plot here.