Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 import numpy as np
00032 import circular_buffer as cb
00033
00034
00035 class Kalman1D():
00036
00037
00038
00039 def __init__(self, P, Q, R):
00040 self.P_orig = float(P)
00041 self.Q_orig = float(Q)
00042 self.R_orig = float(R)
00043 self.reset()
00044
00045
00046 def reset(self):
00047 self.P = self.P_orig
00048 self.Q = self.Q_orig
00049 self.R = self.R_orig
00050 self.xhat = None
00051
00052 def predict(self, z):
00053 if self.xhat == None:
00054 self.xhat = z
00055
00056 xhatminus = self.xhat
00057 Pminus = self.P + self.Q
00058
00059 K = Pminus / (Pminus + self.R)
00060 self.xhat = xhatminus + K * (z-xhatminus)
00061 self.P = (1-K) * Pminus
00062 return self.xhat
00063
00064
00065 class Mean():
00066
00067 def __init__(self, size, shape):
00068 self.buf = cb.CircularBuffer(size, shape)
00069
00070 def reset(self):
00071 self.buf.clear()
00072
00073 def predict(self, z):
00074 self.buf.append(z)
00075 return np.mean(self.buf.to_list(), 0)
00076
00077 class Median():
00078
00079 def __init__(self, size, shape):
00080 self.buf = cb.CircularBuffer(size, shape)
00081
00082 def reset(self):
00083 self.buf.clear()
00084
00085 def predict(self, z):
00086 self.buf.append(z)
00087 return np.median(self.buf.to_list(), 0)
00088
00089
00090
00091
00092 def filter_array(x, filt):
00093 x_filt = []
00094 for z in x:
00095 x_filt.append(filt.predict(z))
00096
00097 return np.array(x_filt)
00098
00099
00100
00101
00102
hrl_lib
Author(s): Cressel Anderson, Travis Deyle, Advait Jain, Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:34:06