【发布时间】:2014-10-01 05:34:30
【问题描述】:
我正在尝试使用 python 过滤嘈杂的心率信号。因为心率不应该高于每分钟 220 次,所以我想过滤掉所有高于 220 bpm 的噪音。我将 220/分钟转换为 3.66666666 赫兹,然后将该赫兹转换为 rad/s 以获得 23.0383461 rad/sec。
获取数据的芯片的采样频率是 30Hz,所以我将其转换为 rad/s 得到 188.495559 rad/s。
在网上查找了一些资料后,我发现了一些我想将其制成低通的带通滤波器的功能。 Here is the link the bandpass code,所以我把它改成了这样:
from scipy.signal import butter, lfilter
from scipy.signal import freqs
def butter_lowpass(cutOff, fs, order=5):
nyq = 0.5 * fs
normalCutoff = cutOff / nyq
b, a = butter(order, normalCutoff, btype='low', analog = True)
return b, a
def butter_lowpass_filter(data, cutOff, fs, order=4):
b, a = butter_lowpass(cutOff, fs, order=order)
y = lfilter(b, a, data)
return y
cutOff = 23.1 #cutoff frequency in rad/s
fs = 188.495559 #sampling frequency in rad/s
order = 20 #order of filter
#print sticker_data.ps1_dxdt2
y = butter_lowpass_filter(data, cutOff, fs, order)
plt.plot(y)
我对此感到非常困惑,因为我很确定黄油函数会以 rad/s 为单位接收截止和采样频率,但我似乎得到了一个奇怪的输出。它实际上是赫兹吗?
其次,这两行的目的是什么:
nyq = 0.5 * fs
normalCutoff = cutOff / nyq
我知道这与归一化有关,但我认为奈奎斯特是采样频率的 2 倍,而不是一半。为什么要使用 nyquist 作为归一化器?
谁能解释一下如何使用这些功能创建过滤器?
我使用以下方法绘制了过滤器:
w, h = signal.freqs(b, a)
plt.plot(w, 20 * np.log10(abs(h)))
plt.xscale('log')
plt.title('Butterworth filter frequency response')
plt.xlabel('Frequency [radians / second]')
plt.ylabel('Amplitude [dB]')
plt.margins(0, 0.1)
plt.grid(which='both', axis='both')
plt.axvline(100, color='green') # cutoff frequency
plt.show()
并且得到了这个显然不会在 23 rad/s 时截止:
【问题讨论】:
标签: python scipy filtering signal-processing