心电信号过滤

时间:2018-06-19 23:20:43

标签: python python-2.7 signal-processing sensor

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

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()

1 个答案:

答案 0 :(得分:0)

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

def solve(c)

  letter_values =('a'..'z').map.with_index(1) {|letter,value| [letter,value] }
  remove_vowels =c.gsub(/[aeiou]/, ' ').split()


end
solve("zodiacs")
letter_values