Created
December 4, 2017 21:14
-
-
Save cotramarko/2233415136edf2b6e268107e44b1fd56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class KalmanFilter(): | |
def __init__(self, A, H, Q, R, x_0, P_0): | |
# Model parameters | |
self.A = A | |
self.H = H | |
self.Q = Q | |
self.R = R | |
# Initial state | |
self._x = x_0 | |
self._P = P_0 | |
def predict(self): | |
self._x = self.A @ self._x | |
self._P = self.A @ self._P @ self.A.transpose() + self.Q | |
def update(self, z): | |
self.S = self.H @ self._P @ self.H.transpose() + self.R | |
self.V = z - self.H @ self._x | |
self.K = self._P @ self.H.transpose() @ np.linalg.inv(self.S) | |
self._x = self._x + self.K @ self.V | |
self._P = self._P - self.K @ self.S @ self.K.transpose() | |
def get_state(self): | |
return self._x, self._P |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment