FadingMemoryFilter

Introduction and Overview

Implements a polynomial fading memory filter. You can achieve the same results, and more, using the KalmanFilter class. However, some books use this form of the fading memory filter, so it is here for completeness. I suppose some would also find this simpler to use than the standard Kalman filter.


Copyright 2014 Roger R Labbe Jr.

filterpy library. http://github.com/rlabbe/filterpy

Documentation at: https://filterpy.readthedocs.org

Supporting book at: https://github.com/rlabbe/Kalman-and-Bayesian-Filters-in-Python

This is licensed under an MIT license. See the readme.MD file for more information.

class filterpy.memory.FadingMemoryFilter(x0, dt, order, beta)[source]
__init__(x0, dt, order, beta)

Creates a fading memory filter of order 0, 1, or 2.

Parameters

x0 : 1D np.array or scalar

Initial value for the filter state. Each value can be a scalar or a np.array.

You can use a scalar for x0. If order > 0, then 0.0 is assumed for the higher order terms.

x[0] is the value being tracked x[1] is the first derivative (for order 1 and 2 filters) x[2] is the second derivative (for order 2 filters)

dt : scalar
timestep
order : int
order of the filter. Defines the order of the system 0 - assumes system of form x = a_0 + a_1*t 1 - assumes system of form x = a_0 +a_1*t + a_2*t^2 2 - assumes system of form x = a_0 +a_1*t + a_2*t^2 + a_3*t^3
beta : float
filter gain parameter.

Members

self.x : np.array

State of the filter. x[0] is the value being tracked x[1] is the derivative of x[0] (order 1 and 2 only) x[2] is the 2nd derivative of x[0] (order 2 only)

This is always an np.array, even for order 0 where you can initialize x0 with a scalar.

self.P : np.array

The diagonal of the covariance matrix. Assumes that variance is one; multiply by sigma^2 to get the actual variances.

This is a constant and will not vary as the filter runs.

self.e : np.array

The truncation error of the filter. Each term must be multiplied by the a_1, a_2, or a_3 of the polynomial for the system.

For example, if the filter is order 2, then multiply all terms of self.e by a_3 to get the actual error. Multipy by a_2 for order 1, and a_1 for order 0.

update(z)

update the filter with measurement z. z must be the same type (or treatable as the same type) as self.x[0].