Skip to content

samples/python/kalman.py is not constant rotation as documented #20091

@drf5n

Description

@drf5n

The comments and documentation in samples/python/kalman.py do not match the behavior of the program.

This line prints that the speed is constant, but it is clear from running the program that the speed is not constant.

Rotation speed is constant.

Because of:

kalman.processNoiseCov = 1e-5 * np.eye(2)

and
process_noise = sqrt(kalman.processNoiseCov[0,0]) * np.random.randn(2, 1)
state = np.dot(kalman.transitionMatrix, state) + process_noise

The state variable holds the angle and speed, which at each step is modified by the process transition matrix plus the process noise. Since the process noise is added onto the state variable for the speed of rotation, the speed is not constant -- it is a random walk.

The random walk in speed (and location) is more visually interesting than tracking a constant rotation, but it isn't required by a Kalman filter and doesn't match the documentation.

Kalman filters can be a confusing topic, and the inconsistent documentation doesn't help.

I suggest either making the process noise zero to match the documentation or replacing the "Rotation speed is constant. " with something like:

Rotation speed is a random walk from N(0,0.1 ), integrating N(0,1e-5) process noise.

If you run the program it is clear that the rotation is not constant.

Another couple issues:

  • Why plot the crosses underneath the lines? The thick lines overwrite the points and cover them up.
  • Why not use/plot the kalman.statePost? The utility of a Kalman filter is to improve the estimate of the current state based on the recent measurement and to improve the estimate of the next state. This demo doesn't use the corrected measurement.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions