小波去噪代码

先放代码,代码如下:

a = np.loadtxt('C:\\Users\\Administrator\\Desktop\\数据文件\\20201008009.txt', dtype=float)# 20201008009为一个一维列表
index = []
data = []
coffs = []
for i in range(len(a) - 1):
    X = float(i)
    Y = float(a[i])
    index.append(X)
    data.append(Y)
# create wavelet object and define parameters
w = pywt.Wavelet('db8')  # 选用Daubechies8小波
maxlev = pywt.dwt_max_level(len(data), w.dec_len)
print("maximum level is" + str(maxlev))
threshold = 0.1  # Threshold for filtering
# Decompose into wavelet components,to the level selected:
coffs = pywt.wavedec(data, 'db8', level=maxlev)  # 将信号进行小波分解
for i in range(1, len(coffs)):
    coffs[i] = pywt.threshold(coffs[i], threshold * max(coffs[i]))
datarec = pywt.waverec(coffs, 'db8')  # 将信号进行小波重构
mintime = 0
maxtime = mintime + len(data)
print(mintime, maxtime)

plt.rcParams['font.sans-serif']=['SimHei'] #使得标题输出为中文
plt.rcParams['axes.unicode_minus'] = False #使得标题输出为中文

plt.figure(1)
#plt.subplot(3, 1, 1)
plt.plot(index[mintime:maxtime], data[mintime:maxtime])
plt.title("原始信号")
plt.figure(2)
#plt.subplot(3, 1, 2)
plt.plot(index[mintime:maxtime], datarec[mintime:maxtime])
plt.title("小波降噪信号")
plt.figure(3)
#plt.subplot(3, 1, 3)
plt.plot(index[mintime:maxtime], data[mintime:maxtime] - datarec[mintime:maxtime])
plt.xlabel('time (s)')
plt.ylabel('error (uV)')
plt.tight_layout()
plt.show()

去噪之前的波形

 去噪之后的波形

最后一个我估计应该是去除的噪声波形 

 

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值