This repository contains Kalman Filter implementations in MATLAB that can be used for embedded code-generation.
Currently, only the Square-Root Kalman Filter with the Scaled-Unscented Transform and non-additive measurement noise is provided, as is defined by Rudolph Van der Merwe.1 It replicates in large parts the Square-Root UKF by MathWorks but has slightly different property names, function syntax and calculation schemes. The results when using either implementation are very similar in tested scenarios.
The SR-UKF implementation has successfully been used to test and design an UKF-algorithm in MATLAB. The filter was then ported to Simulink using a MATLAB-function block to generate code for an embedded system (dSPACE Microautobox III).
Only a base MATLAB installation is required, no toolboxes!
Compatability has only been tested for MATLAB 2021a.
You can either use the library for recursive offline estimation or code generation for embedded systems. For a guide on generating code (or using the MATLAB classes in Simulink), see this official guide by MathWorks.
You can either use the library for recursive offline estimation or code generation for embedded systems.
You can instantiate the SR-UKF very simply. In this example, a fictional state transition (f) and measurement function (h) are used. Covariance matrices are omitted and are set to default values.
f = @(x,v,u) x*(1+v) + u;
h = @(x,n) x;
x0 = 1;
ukf = spkf.SquareRootUnscentedKalmanFilter(f,h,x0,[],[],[]);
To perform a predict step, do:
u = 10; % arbitrary control input
ukf.predict(u)
The prediction is corrected in a similar fashion:
y = 11; % arbitrary measurement
ukf.correct(y)
The results can be viewed by accessing the class properties:
ukf.State
ukf.StateCovariance
Or by using the optional outputs of the predict and correct functions:
[x, P] = ukf.predict(u);
[x, P] = ukf.correct(y);
Footnotes
-
Merwe R, Wan E (2003) Sigma-Point Kalman Filters for Probabilistic Inference in Dynamic State-Space Models. Proceedings of the Workshop on Advances in Machine Learning ↩