我以前(现已删除)的答案有点令人困惑。在这里,我将尝试为您提供一个动手示例,该示例显示仅使用“db6”近似系数重建以 360Hz 采样的 ECG 数据(大致)等效于使用 0.35Hz 的截止频率对这些数据进行低通滤波。
在下面的代码示例中,我从 scipy ( from scipy.misc import electrocardiogram
) 导入了 ECG 时间序列;它们的采样频率为 360Hz,就像你的一样。我将使用以下方法过滤这些数据数据:
- 一种 DWT 方法,即仅使用近似系数 (filtered_data_dwt) 重构数据
- 巴特沃斯滤波器 (filtered_data_butterworth)
这是代码示例:
import pywt
import numpy as np
from scipy.misc import electrocardiogram
import scipy.signal as signal
import matplotlib.pyplot as plt
wavelet_type='db6'
data = electrocardiogram()
DWTcoeffs = pywt.wavedec(data,wavelet_type,mode='symmetric', level=9, axis=-1)
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,wavelet_type,mode='symmetric',axis=-1)
fc = 0.35 # Cut-off frequency of the butterworth filter
w = fc / (360 / 2) # Normalize the frequency
b, a = signal.butter(5, w, 'low')
filtered_data_butterworth = signal.filtfilt(b, a, data)
让我们使用两种方法绘制原始数据和过滤数据的功率谱密度:
plt.figure(1)
plt.psd(data, NFFT=512, Fs=360, label='original data', color='blue')
plt.psd(filtered_data_dwt, NFFT=512, Fs=360, color='red', label='filtered data (DWT)')
plt.psd(filtered_data_butterworth, NFFT=512, Fs=360, color='black', label='filtered data (Butterworth)')
plt.legend()
产生:

在原始数据中,您可以清楚地看到 60Hz 及其第一个倍数(120Hz)。让我们近距离观察低频:

现在让我们看一下时域中的数据:
plt.figure(2)
plt.subplot(311)
plt.plot(data,label='original data', color='blue')
plt.title('original')
plt.subplot(312)
plt.plot(filtered_data_dwt, color='red', label='filtered data (DWT)')
plt.title('filtered (DWT)')
plt.subplot(313)
plt.plot(filtered_data_butterworth, color='black', label='filtered data (Butterworth)')
plt.title('filtered (Butterworth)')

因此,为了使用 0.35Hz 的截止频率对原始数据进行低通滤波,您可以使用 DWT 分解的近似系数(即使用“db6”小波)简单地重建它们。
希望这可以帮助!