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

sta*_*fer 5 python wavelet-transform pywavelets

我想用小波变换对信号进行去噪,但不知何故去噪后的数据并没有显着变化

代码:

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()
Run Code Online (Sandbox Code Playgroud)

结果: 在此输入图像描述

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

数据集链接: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.
Run Code Online (Sandbox Code Playgroud)

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

在此输入链接描述

She*_*don 4

我认为你的问题来自于你正在使用wavedec22D 离散小波变换来处理一维数组。

为什么不使用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()
Run Code Online (Sandbox Code Playgroud)

这将返回:

在此输入图像描述

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

#DWTcoeffs[-8] = np.zeros_like(DWTcoeffs[-8])
#DWTcoeffs[-9] = np.zeros_like(DWTcoeffs[-9])
Run Code Online (Sandbox Code Playgroud)

然后你得到:

在此输入图像描述