c4dynamics.filters.ekf.ekf.update#
- ekf.update(z: ndarray | None = None, H: ndarray | None = None, hx: ndarray | None = None, innov: ndarray | None = None, R: ndarray | None = None, gate: float | None = None)[source]#
Updates the state estimate based on the latest measurement, using an optional nonlinear measurement function.
- Parameters:
z (np.ndarray, optional) – Measurement vector, representing observed values from the system. Required unless innov is provided directly.
H (np.ndarray, optional) – Measurement Jacobian matrix. If provided, it overrides the previously set H matrix for this update step.
hx (np.ndarray, optional) – Nonlinear measurement function output, h(x). If provided, it is used in place of the linear
H @ Xto form the innovationz - hx. Ignored if innov is provided directly.innov (np.ndarray, optional) – The innovation itself, overriding
z - hx. Use this for a residual that isn’t a plain subtraction, e.g. an angle-wrapped measurement. z is not required when innov is given.R (np.ndarray, optional) – Measurement noise covariance matrix, representing the uncertainty in the measurements.
gate (float, optional) – Chi-squared NIS gating threshold; see
kalman.update. If the innovation fails the gate, the update is rejected and update returns None.
Examples
The examples in this section are intended to demonstrate the usage of the ekf class and specifically the update method. However, they are not limited to nonlinear dynamics. For detailed usage that highlights the properties of nonlinear dynamics, refer to the
filtersmodule introduction.Import required packages:
>>> from c4dynamics.filters import ekf
Plain update step:
>>> _ekf = ekf({'x': 0}, P0 = 0.5**2, F = 1, H = 1, Q = 0.05, R = 200) >>> print(_ekf) [ x ] >>> _ekf.X [0] >>> _ekf.P [[0.25]] >>> _ekf.update(z = 100) # returns Kalman gain [[0.001...]] >>> _ekf.X [0.124...] >>> _ekf.P [[0.249...]]
Update with modified measurement noise covariance matrix:
>>> _ekf = ekf({'x': 0}, P0 = 0.5**2, F = 1, G = 150, H = 1, R = 200, Q = 0.05) >>> _ekf.X [0] >>> _ekf.P [[0.25]] >>> K = _ekf.update(z = 150, R = 0) >>> K [[1]] >>> _ekf.X [150] >>> _ekf.P [[0]]