Python中的心电60hz噪声滤波

Python中的心电60hz噪声滤波,python,scipy,signal-processing,Python,Scipy,Signal Processing,我从我工作的实验室开发的一个采集电路中获得了一些ECG数据,我正在尝试实现一个60 Hz陷波滤波器来最小化背景噪声 代码如下: from scipy import fft from scipy import ifft import matplotlib.pyplot as plt def notchfilter(ECGdata): """ Filters the data using notch filter Description: Digital filter w

我从我工作的实验室开发的一个采集电路中获得了一些ECG数据,我正在尝试实现一个60 Hz陷波滤波器来最小化背景噪声

代码如下:

from scipy import fft
from scipy import ifft
import matplotlib.pyplot as plt

def notchfilter(ECGdata):
""" Filters the data using notch filter

    Description:
        Digital filter which returns the filtered signal using 60Hz
        notch filter. Transforms the signal into frequency domain
        using the fft function of the Scipy Module. Then, suppresses
        the 60Hz signal by equating it to zero. Finally, transforms
        the signal back to time domain using the ifft function.
    Input:
        ECGdata -- list of integers (ECG data)
    Output:
        ifft(fftECG) -- inverse fast fourier transformed array of filtered ECG data
"""         
fftECG = fft(ECGdata)
for i in range(len(fftECG)):
    if 590<i<620 or 880<i<910: fftECG[i]=0
return ifft(fftECG)

data = open('ECG_LOG4.TXT','r')
y = data.readlines()
data.close()

t = range(len(y))

plt.plot(t,y)
plt.show()
从scipy导入fft
从scipy导入ifft
将matplotlib.pyplot作为plt导入
def notchfilter(ECGdata):
“”“使用陷波滤波器过滤数据
说明:
使用60Hz返回滤波信号的数字滤波器
陷波滤波器。将信号转换为频域
使用Scipy模块的fft功能。然后,抑制
将60Hz信号等效为零。最后,转换
使用ifft功能将信号返回到时域。
输入:
ECGdata——整数列表(ECG数据)
输出:
ifft(fftECG)——滤波ECG数据的逆快速傅里叶变换阵列
"""         
fftECG=fft(ECGdata)
对于范围内的i(len(fftECG)):

如果您的数据似乎是以字符串形式读取的。尝试使用
numpy.loadtxt()
。您的数据似乎是以字符串形式读取的。尝试使用
numpy.loadtxt()