[英]Butterworth Lowpass Filter
I am not getting the desired output, it is cutting off the lower freq. 我没有得到想要的输出,它切断了较低的频率。 no matter if I set it to 'low' or 'high'.
无论我将其设置为“低”还是“高”。
import numpy as np
from scipy import signal
import matplotlib.pyplot as plt
def butter_filter(data, butterCutoffFreq, order=1):
b, a = signal.butter(order, butterCutoffFreq, 'low', analog=True)
y = signal.lfilter(b, a, data)
return y
"""
White noise
"""
N = 1024
dt = np.float64(1)
y = np.random.normal(loc=0.0, scale=1.0, size=N)
t = np.arange(start=0, stop=N, step=dt)
butterCutoffFreq = 0.5 * 1/dt
amps = np.fft.rfft(y)
freqs = np.fft.rfftfreq(y.size, dt)
#plt.plot(freqs, np.abs(amps), color='b')
ampsFiltered = butter_filter(y, butterCutoffFreq)
ampsFiltered = np.fft.rfft(ampsFiltered)
plt.plot(freqs, np.abs(ampsFiltered), color='g')
plt.show()
Your problem is whith the param analog=True
remove it and it will work. 您的问题是param
analog=True
删除了它,它将起作用。
lfilter()
can only use a digital filter. lfilter()
只能使用数字滤波器。 It doesn't make sense to filter a digital signal (your white noise assumed regularly sampled) with an analog filter. 用模拟滤波器滤波数字信号(假设您的白噪声假定为定期采样)是没有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.