Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- import pywt
- df = pd.read_csv('z_rate.csv')
- x = df.index
- y = df['z_avgRate']
- # perform wavelet decomposition
- coeffs = pywt.wavedec(y, 'sym5', mode='symmetric')
- # zero out last 5 detail coefficents
- for i in range(5):
- coeffs[i+5] = np.zeros(coeffs[i+5].shape)
- # reconstruct wavelet
- y_rec = pywt.waverec(coeffs, 'sym5', mode='symmetric')[1:]
- # plot result
- plt.figure(figsize=(18,6))
- plt.plot(x, y)
- plt.plot(x, y_rec)
- plt.legend(['original', 'wavelet-based smoothing'])
- plt.xlabel('time index')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment