CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download
Project: test
Views: 91872
1
# -*- coding: utf-8 -*-
2
"""
3
Created on Sat May 24 14:42:55 2014
4
5
@author: rlabbe
6
"""
7
8
from KalmanFilter import KalmanFilter
9
import numpy as np
10
import matplotlib.pyplot as plt
11
import numpy.random as random
12
13
f = KalmanFilter (dim=4)
14
15
dt = 1
16
f.F = np.mat ([[1, dt, 0, 0],
17
[0, 1, 0, 0],
18
[0, 0, 1, dt],
19
[0, 0, 0, 1]])
20
21
f.H = np.mat ([[1, 0, 0, 0],
22
[0, 0, 1, 0]])
23
24
25
26
f.Q *= 4.
27
f.R = np.mat([[50,0],
28
[0, 50]])
29
30
f.x = np.mat([0,0,0,0]).T
31
f.P *= 100.
32
33
34
xs = []
35
ys = []
36
count = 200
37
for i in range(count):
38
z = np.mat([[i+random.randn()*1],[i+random.randn()*1]])
39
f.predict ()
40
f.update (z)
41
xs.append (f.x[0,0])
42
ys.append (f.x[2,0])
43
44
45
plt.plot (xs, ys)
46
plt.show()
47
48
49