Guest User

Untitled

a guest
Feb 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. # @Author: juliangaal
  3. # @Date: 2018-02-10 12:25:41
  4. # @Last Modified by: juliangaal
  5. # @Last Modified time: 2018-02-10 15:07:28
  6. import numpy as np
  7. import matplotlib.pyplot as plt
  8.  
  9. values = [1124, 800, 628, 379, 199, 104, 279, 227, 97, 226, 105, 95, 150, 180, 200, 226, 250, 279, 399, 415, 430, 455, 470, 498, 504]
  10. filtered = []
  11.  
  12. def filter():
  13. global values
  14.  
  15. a = 0.75
  16. u = 1
  17. b = 0.5
  18. c = 1
  19. r = 2
  20. xhat = values[0]
  21. pred = gain = 1
  22.  
  23. for z in values:
  24. # Update
  25. xhat = a * xhat + b * u
  26. pred = a * pred * a
  27.  
  28. # Predict
  29. gain = pred * c / (c * pred * c + r)
  30. xhat = xhat + gain * (z - c * xhat)
  31. pred = (1 - gain * c) * pred
  32.  
  33. # save
  34. filtered.append(xhat)
  35.  
  36. filter()
  37. x = np.linspace(0, len(values) + 1, len(values))
  38. plt.plot(x, filtered, label='filtered')
  39. plt.plot(x, values, label='original')
  40. plt.show()
Add Comment
Please, Sign In to add comment