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 Thu May 15 16:07:26 201434@author: RL5"""6from __future__ import division7import matplotlib.pyplot as plt8import numpy.random as random9101112131415def g_h_filter (data, x, dx, g, h, dt=1.):16results = []17for z in data:18x_est = x + (dx*dt)19residual = z - x_est2021dx = dx + h * (residual / float(dt))22x = x_est + g * residual23print('gx',dx,)2425results.append(x)262728return results293031'''32computation of x33x_est = weight + gain34residual = z - weight - gain35x = weight + gain + g (z - weight - gain)3637w + gain + gz -wg -ggain38w -wg + gain - ggain + gz3940w(1-g) + gain(1-g) +gz4142(w+g)(1-g) +gz4344'''45'''46gain computation4748gain = gain + h/t* (z - weight - gain)49= gain + hz/t -hweight/t - hgain/t5051= gain(1-h/t) + h/t(z-weight)5253'''54'''55gain+ h*(z-w -gain*t)/t5657gain + hz/t -hw/t -hgain5859gain*(1-h) + h/t(z-w)606162'''63def weight2():64w = 065gain = 20066t = 10.67weight_scale = 1./668gain_scale = 1./106970weights=[2060]71for i in range (len(weights)):72z = weights[i]73w_pre = w + gain*t7475new_w = w_pre * (1-weight_scale) + z * (weight_scale)7677print('new_w',new_w)7879gain = gain *(1-gain_scale) + (z - w) * gain_scale/t8081print (z)82print(w)8384#gain = new_gain * (gain_scale) + gain * (1-gain_scale)85w = new_w86print ('w',w,)87print ('gain=',gain)888990def weight3():91w = 160.92gain = 1.93t = 1.94weight_scale = 6/10.95gain_scale = 2./39697weights=[158]98for i in range (len(weights)):99z = weights[i]100w_pre = w + gain*t101102new_w = w_pre * (1-weight_scale) + z * (weight_scale)103104print('new_w',new_w)105106gain = gain *(1-gain_scale) + (z - w) * gain_scale/t107108print (z)109print(w)110111#gain = new_gain * (gain_scale) + gain * (1-gain_scale)112w = new_w113print ('w',w,)114print ('gain=',gain)115weight3()116'''117#zs = [i + random.randn()*50 for i in range(200)]118zs = [158.0, 164.2, 160.3, 159.9, 162.1, 164.6, 169.6, 167.4, 166.4, 171.0]119120#zs = [2060]121data= g_h_filter(zs, 160, 1, .6, 0, 1.)122123'''124125data = g_h_filter([2060], x=0, dx=200, g=1./6, h = 1./10, dt=10)126print data127128129'''130print data131print data2132plt.plot(data)133plt.plot(zs, 'g')134plt.show()135'''136137138