【问题标题】:ECG signal filtering心电信号滤波
【发布时间】:2018-11-28 23:51:15
【问题描述】:

我正在尝试过滤从 Bioplux 传感器获取的 ECG 信号。我包括用于消除 200 Hz 以上频率噪声的低通滤波器、用于消除基线漂移的高通滤波器和用于消除 60 Hz 电力线频率的陷波滤波器。我无法理解为什么在高通滤波后我会得到一个波浪形的输出。有人可以提出一些想法来获得正确过滤的心电图信号吗? rawsignal数据文本文件和过滤后得到的输出见以下链接:

https://drive.google.com/open?id=1hvvQpMMa_hn9VNlUh4HAqb_H1lCu70or

我写的代码如下:

from scipy import signal
from scipy.signal import butter, iirnotch, lfilter
import numpy as np
import matplotlib.pyplot as plt

def butter_highpass(cutoff, fs, order=5):
    nyq = 0.5*fs
    normal_cutoff = cutoff/nyq
    b, a = butter(order, normal_cutoff, btype='high', analog=False, output='ba')
    return b, a

def butter_lowpass(cutoff, fs, order=5):
    nyq = 0.5*fs
    normal_cutoff = cutoff/nyq
    b, a = butter(order, normal_cutoff, btype='low', analog=False, output='ba')
    return b, a

def notch_filter(cutoff, q):
    nyq = 0.5*fs
    freq = cutoff/nyq
    b, a = iirnotch(freq, q)
    return b, a

def highpass(data, fs, order=5):
    b,a = butter_highpass(cutoff_high, fs, order=order)
    x = lfilter(b,a,data)
    return x

def lowpass(data, fs, order =5):
    b,a = butter_lowpass(cutoff_low, fs, order=order)
    y = lfilter(b,a,data)
    return y

def notch(data, powerline, q):
    b,a = notch_filter(powerline,q)
    z = lfilter(b,a,data)
    return z

def final_filter(data, fs, order=5):
    b, a = butter_highpass(cutoff_high, fs, order=order)
    x = lfilter(b, a, data)
    d, c = butter_lowpass(cutoff_low, fs, order = order)
    y = lfilter(d, c, x)
    f, e = notch_filter(powerline, 30)
    z = lfilter(f, e, y)    
    return x
    return y
    return z

rawdata = np.loadtxt('D:\CANADA TRIP\BiosignalsSample.txt', skiprows=0)
signal = rawdata
fs = 1000

cutoff_high = 0.5
cutoff_low = 200
powerline = 60
order = 6

#print(signal)
plt.figure(1)
ax1 = plt.subplot(321)
plt.plot(signal)
ax1.set_title("Raw signal")

conditioned_signal = final_filter(signal, fs, order)
ax2 = plt.subplot(322)
plt.plot(conditioned_signal)
ax2.set_title("Conditioned signal")

hsignal = highpass(signal, fs, order)
ax3 = plt.subplot(323)
plt.plot(hsignal)
ax3.set_title("Only highpass filter")

lsignal = lowpass(signal, fs, order)
ax4 = plt.subplot(324)
plt.plot(lsignal)
ax4.set_title("Only lowpass filter")

nonotch_1 = highpass(signal, fs, order)
nonotch = lowpass(nonotch_1, fs, order)
ax5 = plt.subplot(325)
plt.plot(nonotch)
ax5.set_title("High and low pass")

onlynotch = notch(signal, powerline, 30)
ax6 = plt.subplot(326)
plt.plot(onlynotch)
ax6.set_title("Notch filter only")

plt.show()

【问题讨论】:

    标签: python python-2.7 signal-processing sensors


    【解决方案1】:

    尝试使用 0.1 到 45 Hz 的带通滤波器,而不是级联低通和高通滤波器。

    def bandpass(lowcut, highcut, order=5):
        nyq = 0.5 * fs
        low = lowcut / nyq
        high = highcut / nyq
        b, a = butter(order, [low, high], btype='band')
        return b, a
    
    
    

    【讨论】:

      猜你喜欢
      • 2015-11-17
      • 2015-07-03
      • 1970-01-01
      • 2015-02-26
      • 2011-06-02
      • 2020-09-16
      • 1970-01-01
      • 2023-03-08
      • 2012-12-03
      相关资源
      最近更新 更多