我在 SciPy 中使用过滤器并注意到一些我不太熟悉的东西:
我正在使用代码:
import numpy as np
from scipy.signal import butter, lfilter, freqz
import matplotlib.pyplot as plt
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)
return b, a
def butter_lowpass_filter(data, cutoff, fs, order=5):
b, a = butter_lowpass(cutoff, fs, order=order)
y = lfilter(b, a, data)
return y
# Filter requirements.
order = 6
fs = 30.0 # sample rate, Hz
cutoff = 3.667 # desired cutoff frequency of the filter, Hz
# Get the filter coefficients so we can check its frequency response.
b, a = butter_lowpass(cutoff, fs, order)
# Plot the frequency response.
w, h = freqz(b, a, worN=8000)
取自:https ://stackoverflow.com/a/25192640/4959635
并对给定的 freqz 结果进行一些绘图:
plt.plot(w,h)
plt.show()
plt.plot(w,abs(h))
plt.show()
那么为什么我必须采取abs来获得“我想要的情节”呢?第一个具有负振幅的是什么?