This example demonstrates the implementation of a Kalman filter
in Python.
The model generates a uniform random number, which is computed
in the Python file KalmanFilter.py
by the function
random(seed)
.
This random number is added to a sine wave and then sent to
the function filter(u)
in the above Python file.
The function filter(u)
implements a Kalman filter that estimates and returns
the state.
The function saves its temporary variables to a file called
tmp-kalman.json
.
When simulating this model, the figure below will be generated which shows the sine wave, the sine wave plus noise, which is input to the Kalman filter, and the estimated state which is the output of the Kalman filter.
The code is based on http://www.scipy.org/Cookbook/KalmanFiltering.
pickle
to json
as the former can trigger a
segfault with JModelica simulation run in a subprocess.