Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
Project: test
Views: 91872# -*- coding: utf-8 -*-1"""2Created on Fri Feb 13 17:47:56 201534@author: rlabbe5"""6import numpy as np7from filterpy.kalman import UnscentedKalmanFilter as UKF8from math import atan2, radians,degrees9from filterpy.common import stats10import matplotlib.pyplot as plt1112p = (-10, -10)1314def hx(x):15dx = x[0] - hx.p[0]16dy = x[1] - hx.p[1]17return np.array([atan2(dy,dx), (dx**2 + dy**2)**.5])1819def fx(x,dt):20return x21222324kf = UKF(2, 2, dt=0.1, hx=hx, fx=fx, kappa=2.)2526kf.x = np.array([100, 100.])27kf.P *= 4028hx.p = kf.x - np.array([50,50])2930d = ((kf.x[0] - hx.p[0])**2 + (kf.x[1] - hx.p[1])**2)**.53132stats.plot_covariance_ellipse(33kf.x, cov=kf.P, axis_equal=True,34facecolor='y', edgecolor=None, alpha=0.6)35plt.scatter([100], [100], c='y', label='Initial')3637kf.R[0,0] = radians (1)**238kf.R[1,1] = 2.**2394041kf.predict()42kf.update(np.array([radians(45), d]))4344print(kf.x)45print(kf.P)4647stats.plot_covariance_ellipse(48kf.x, cov=kf.P, axis_equal=True,49facecolor='g', edgecolor=None, alpha=0.6)50plt.scatter([100], [100], c='g', label='45 degrees')515253p = (13, -11)54hx.p = kf.x - np.array([-50,50])55d = ((kf.x[0] - hx.p[0])**2 + (kf.x[1] - hx.p[1])**2)**.55657kf.predict()58kf.update(np.array([radians(135), d]))5960stats.plot_covariance_ellipse(61kf.x, cov=kf.P, axis_equal=True,62facecolor='b', edgecolor=None, alpha=0.6)63plt.scatter([100], [100], c='b', label='135 degrees')6465plt.legend(scatterpoints=1, markerscale=3)6667