w = pywt.Wavelet('db8') # 选用Daubechies8小波
maxlev = pywt.dwt_max_level(len(data), w.dec_len)
print("maximum level is " + str(maxlev))
threshold = 0.04 # Threshold for filtering
coeffs = pywt.wavedec(data, 'db8', level=maxlev) # 将信号进行小波分解
# data为要处理的数据,列表存储
for i in range(1, len(coeffs)):
print(i)
coeffs[i] = pywt.threshold(coeffs[i], threshold*max(coeffs[i])) # 将噪声滤波
datarec = pywt.waverec(coeffs, 'db8') # 将信号进行小波重构
mintime = 0
maxtime = mintime + len(data) + 1