modelKalmanFilter
Extends from Modelica.Icons.Example (Icon for runnable examples).
Information
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.
Implementation
The code is based on http://www.scipy.org/Cookbook/KalmanFiltering.
Parameters
| Type | Name | Default | Description |
|---|---|---|---|
| Modelica.Units.SI.Time | samplePeriod | 0.001 | Sample period of component |
Components
| Type | Name | Default | Description |
|---|---|---|---|
| Python_3_8.Real_Real | ran | Generate a random number in Python | |
| Modelica.Blocks.Sources.ContinuousClock | clock | ||
| Python_3_8.Real_Real | kalFil | Kalman filter in Python | |
| Modelica.Blocks.Sources.Sine | sine | Sine wave | |
| Modelica.Blocks.Math.Add | add | Addition of signals before sending it to the Kalman filter |
Revisions
-
August 27, 2021, by Michael Wetter:
Updated to Python 3.8. -
April 10, 2020, by Jianjun Hu and Michael Wetter:
Updated to Python 3.6. -
October 24, 2019, by Antoine Gautier:
Changed the temporary file format frompickletojsonas the former can trigger a segfault with JModelica simulation run in a subprocess.
This is for Buildings, #1587. -
February 5, 2013, by Michael Wetter:
First implementation.