All Projects → zziz → Kalman Filter

zziz / Kalman Filter

Kalman Filter implementation in Python using Numpy only in 30 lines.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Kalman Filter

Kalman.jl
Flexible filtering and smoothing in Julia
Stars: ✭ 62 (-61.49%)
Mutual labels:  filter, kalman-filter
Matchering
🎚️ Open Source Audio Matching and Mastering
Stars: ✭ 398 (+147.2%)
Mutual labels:  numpy, filter
Kalmanfilter altimeter vario
Kalman filter to estimate altitude and climbrate(sinkrate) by fusing altitude and acceleration sensor data
Stars: ✭ 31 (-80.75%)
Mutual labels:  filter, kalman-filter
Numpycnn
Building Convolutional Neural Networks From Scratch using NumPy
Stars: ✭ 436 (+170.81%)
Mutual labels:  numpy, filter
Kalmanjs
Javascript based Kalman filter for 1D data
Stars: ✭ 298 (+85.09%)
Mutual labels:  kalman-filter, filter
Probabilistic robotics
solution of exercises of the book "probabilistic robotics"
Stars: ✭ 734 (+355.9%)
Mutual labels:  numpy, kalman-filter
Pyaudiodsptools
Numpy Audio DSP Tools
Stars: ✭ 154 (-4.35%)
Mutual labels:  numpy
Cam board
Turn web cam into a black / white board
Stars: ✭ 157 (-2.48%)
Mutual labels:  numpy
Lits Liver Tumor Segmentation Challenge
LiTS - Liver Tumor Segmentation Challenge
Stars: ✭ 153 (-4.97%)
Mutual labels:  numpy
Alphalens
Performance analysis of predictive (alpha) stock factors
Stars: ✭ 2,130 (+1222.98%)
Mutual labels:  numpy
Numsca
numsca is numpy for scala
Stars: ✭ 160 (-0.62%)
Mutual labels:  numpy
Multiselectspinner
Android - Select Multiple Items from Spinner with Filtration.
Stars: ✭ 158 (-1.86%)
Mutual labels:  filter
Rnn lstm from scratch
How to build RNNs and LSTMs from scratch with NumPy.
Stars: ✭ 156 (-3.11%)
Mutual labels:  numpy
Color recognition
🎨 Color recognition & classification & detection on webcam stream / on video / on single image using K-Nearest Neighbors (KNN) is trained with color histogram features by OpenCV.
Stars: ✭ 154 (-4.35%)
Mutual labels:  numpy
Gl React Instagramfilters
Instagram filters for gl-react and gl-react-native
Stars: ✭ 157 (-2.48%)
Mutual labels:  filter
Search
CakePHP: Easy model searching
Stars: ✭ 153 (-4.97%)
Mutual labels:  filter
Spring Boot Examples
个人学习 SpringBoot2.x 写的一些示例程序,目前正在持续更新中.....
Stars: ✭ 159 (-1.24%)
Mutual labels:  filter
Searchobject
Search object DSL
Stars: ✭ 152 (-5.59%)
Mutual labels:  filter
Gpuimage X
A Cross-platform (for both Android & iOS) Framework for GPU-based Filters, Video and Image Processing.
Stars: ✭ 154 (-4.35%)
Mutual labels:  filter
Filtrex
A library for performing and validating complex filters from a client (e.g. smart filters)
Stars: ✭ 157 (-2.48%)
Mutual labels:  filter

Implementation of Kalman filter in 30 lines using Numpy. All notations are same as in Kalman Filter Wikipedia Page.

It is a generic implementation of Kalman Filter, should work for any system, provided system dynamics matrices are set up properly. Included example is the prediction of position, velocity and acceleration based on position measurements. Synthetic data is generated for the purpose of illustration.

Running: python kalman-filter.py

import numpy as np

class KalmanFilter(object):
    def __init__(self, F = None, B = None, H = None, Q = None, R = None, P = None, x0 = None):

        if(F is None or H is None):
            raise ValueError("Set proper system dynamics.")

        self.n = F.shape[1]
        self.m = H.shape[1]

        self.F = F
        self.H = H
        self.B = 0 if B is None else B
        self.Q = np.eye(self.n) if Q is None else Q
        self.R = np.eye(self.n) if R is None else R
        self.P = np.eye(self.n) if P is None else P
        self.x = np.zeros((self.n, 1)) if x0 is None else x0

    def predict(self, u = 0):
        self.x = np.dot(self.F, self.x) + np.dot(self.B, u)
        self.P = np.dot(np.dot(self.F, self.P), self.F.T) + self.Q
        return self.x

    def update(self, z):
        y = z - np.dot(self.H, self.x)
        S = self.R + np.dot(self.H, np.dot(self.P, self.H.T))
        K = np.dot(np.dot(self.P, self.H.T), np.linalg.inv(S))
        self.x = self.x + np.dot(K, y)
        I = np.eye(self.n)
        self.P = np.dot(np.dot(I - np.dot(K, self.H), self.P), 
        	(I - np.dot(K, self.H)).T) + np.dot(np.dot(K, self.R), K.T)

def example():
	dt = 1.0/60
	F = np.array([[1, dt, 0], [0, 1, dt], [0, 0, 1]])
	H = np.array([1, 0, 0]).reshape(1, 3)
	Q = np.array([[0.05, 0.05, 0.0], [0.05, 0.05, 0.0], [0.0, 0.0, 0.0]])
	R = np.array([0.5]).reshape(1, 1)

	x = np.linspace(-10, 10, 100)
	measurements = - (x**2 + 2*x - 2)  + np.random.normal(0, 2, 100)

	kf = KalmanFilter(F = F, H = H, Q = Q, R = R)
	predictions = []

	for z in measurements:
		predictions.append(np.dot(H,  kf.predict())[0])
		kf.update(z)

	import matplotlib.pyplot as plt
	plt.plot(range(len(measurements)), measurements, label = 'Measurements')
	plt.plot(range(len(predictions)), np.array(predictions), label = 'Kalman Filter Prediction')
	plt.legend()
	plt.show()

if __name__ == '__main__':
    example()

Output

Result

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].