如何使用小波变换对数据进行去噪

4
我想用小波变换去噪信号,但一些数据在降噪后并没有显著的改变。
代码:
df = pd.read_csv('0311LalaStand5Min1.csv', low_memory=False)
columns = ['Fx','Fy','Fz','Mx','My','Mz']
selected_df = df[columns]
FPDatas = selected_df[:15000]

FPData = np.array(FPDatas).astype('float64')

wavelet = 'db4'

# Perform the wavelet decomposition
coeffs = pywt.wavedec2(FPData, wavelet)

# Threshold the coefficients (using hard thresholding)
threshold = 0.1# adjust this threshold to control the amount of noise removal
coeffs_thresh = [pywt.threshold(c, threshold, 'soft') for c in coeffs]

# Reconstruct the signal using the inverse wavelet transform
FPData_Decompos = pywt.waverec2(coeffs_thresh, wavelet)

plt.figure(figsize=(15,6))
    # plt.figure()
plt.plot(FPData[:,1],color='red')
plt.plot(FPData_Decompos[:,1], markerfacecolor='none',color='green')
plt.legend(['Real Data', 'Denoising Data'], loc='best')
plt.show()

结果: 在此输入图像描述

我已经调整了阈值,但仍然相同。去噪数据没有平滑。

数据集链接:https://drive.google.com/file/d/1hV0kWe_C0XUZWY-M6hh8UC8RtO9Q521b/view?usp=sharing

期望的结果与下面的黑点相同: 在此输入图像描述

第二种情况:

SmartInsole = np.array([[  0.,   0.,  79.,  90.,  64.,   3.,   0.,   0.,   0.,   0.,  19.,
        113., 109.,   1.,  25.,   0.,   0.,   0.,   0.,   0.,   0.,  90.,
         99.,  73.,  35.,   0.,   0.,   0.,   0.,  46., 106., 113., 105.,
         52.,   0.,   0.,   0.,   0.,   0.,   0.,  61.,  71.,  53.,  30.,
          0.,  23.,   2.,  11.,  42., 114., 112., 100.,   0.,   0.,   0.,
          0.,   0.,   0.,   4.,   1.,   0.,   0.,   0.,  42.,  47.,  80.,
         86., 125., 121., 111.,  16.,   0.,   0.,   0.,  47.,  72., 112.,
        123., 129.,  82.,   0.,   0.,   0.,  87.,  80.,   0.,   0.,   5.,
          0.],
       [  0.,   0.,  79.,  90.,  64.,   3.,   0.,   0.,   0.,   0.,  19.,
        113., 109.,   1.,  25.,   0.,   0.,   0.,   0.,   0.,   0.,  90.,
         99.,  73.,  35.,   0.,   0.,   0.,   0.,  46., 106., 113., 105.,
         52.,   0.,   0.,   0.,   0.,   0.,   0.,  57.,  68.,  47.,  20.,
          0.,  17.,   1.,  14.,  48., 120., 118., 105.,   0.,   0.,   0.,
          0.,   0.,   0.,   4.,   1.,   0.,   0.,   0.,  42.,  47.,  80.,
         86., 125., 121., 111.,  16.,   0.,   0.,   0.,  47.,  72., 112.,
        123., 129.,  82.,   0.,   0.,   0.,  87.,  80.,   0.,   0.,   5.,
          0.]])

How to implemet above technique to remove noise if the SmartInsole data like above.

智能鞋垫情节: 在此输入图像描述

在此输入链接描述

1个回答

4

我认为你的问题在于你正在使用wavedec2,这是一个二维离散小波变换,用于处理一维数组。

为什么不使用wavedec呢?

这里有一个使用scipy的ECG数据的例子:

from scipy.misc import electrocardiogram
import matplotlib.pyplot as plt
import pywt
import numpy as np
ecg = electrocardiogram()


FPData = ecg.reshape(10800,-1)
DWTcoeffs = pywt.wavedec(FPData[:,1], 'db4')
DWTcoeffs[-1] = np.zeros_like(DWTcoeffs[-1])
DWTcoeffs[-2] = np.zeros_like(DWTcoeffs[-2])
DWTcoeffs[-3] = np.zeros_like(DWTcoeffs[-3])
DWTcoeffs[-4] = np.zeros_like(DWTcoeffs[-4])
DWTcoeffs[-5] = np.zeros_like(DWTcoeffs[-5])
DWTcoeffs[-6] = np.zeros_like(DWTcoeffs[-6])
DWTcoeffs[-7] = np.zeros_like(DWTcoeffs[-7])
DWTcoeffs[-8] = np.zeros_like(DWTcoeffs[-8])
DWTcoeffs[-9] = np.zeros_like(DWTcoeffs[-9])

filtered_data_dwt=pywt.waverec(DWTcoeffs,'db4',mode='symmetric',axis=-1)
plt.figure(figsize=(15,6))
plt.plot(FPData[:,1],color='red')
plt.plot(filtered_data_dwt, markerfacecolor='none',color='black')
plt.legend(['Real Data', 'Denoised Data'], loc='best')
plt.show()

这将返回:

enter image description here

编辑:在您下面的评论中,您提到输出(黑色曲线)看起来太平滑了。您可以通过将某些系数清零来获得更详细的输出。例如,如果您注释掉以下行:

#DWTcoeffs[-8] = np.zeros_like(DWTcoeffs[-8])
#DWTcoeffs[-9] = np.zeros_like(DWTcoeffs[-9])

然后你得到:

enter image description here


它太平滑了,如何让去噪数据遵循真实数据的模式? - stack offer
1
我编辑了我的帖子来回答你的问题。 - Sheldon
如何将上述技术应用于去除类似上述数据的噪声。我有一个SmartInsole数据。我已经编辑了我的问题。 - stack offer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接