Guest User

Untitled

a guest
Jun 19th, 2023
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. import pandas as pd
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5. import pywt
  6.  
  7. df = pd.read_csv('z_rate.csv')
  8.  
  9. x = df.index
  10. y = df['z_avgRate']
  11.  
  12. # perform wavelet decomposition
  13. coeffs = pywt.wavedec(y, 'sym5', mode='symmetric')
  14.  
  15. # zero out last 5 detail coefficents
  16. for i in range(5):
  17. coeffs[i+5] = np.zeros(coeffs[i+5].shape)
  18.  
  19. # reconstruct wavelet
  20. y_rec = pywt.waverec(coeffs, 'sym5', mode='symmetric')[1:]
  21.  
  22. # plot result
  23. plt.figure(figsize=(18,6))
  24. plt.plot(x, y)
  25. plt.plot(x, y_rec)
  26. plt.legend(['original', 'wavelet-based smoothing'])
  27. plt.xlabel('time index')
  28. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment