[英]what is the problem in this butterworth filter
我认为问题在于您的过滤器不知道数据集的时间步长,特别是在您对bilinear
的调用中,您明确给出了 1 的采样频率。
为了演示,让我们从一个非常强的信号开始:
import numpy as np
import matplotlib.pyplot as plt
N = 1_000
T = 4.
tau = 0.25 # period of signal, frequency of 4 Hz
f = 1 / tau # frequency
omega = 2 * np.pi * f # angular frequency
t, dt = np.linspace(0, T, N, endpoint = False, retstep = True)
fs = 1 / dt # sampling frequency in Hz
noise = np.random.random(N)
sig = np.sin(t * omega)
x = 0.2 * noise + sig
plt.plot(t, x)
plt.xlabel('time')
现在让我们从您开发的过滤器开始。 我的波的频率高于你的截止频率,所以它应该被捕获,但事实并非如此。
from scipy import signal
b, a = signal.butter(4, 0.5, 'high', analog = True, output = 'ba')
z, p = signal.bilinear(b, a, 1.)
x_filt = signal.lfilter(z, p, x)
plt.figure()
plt.plot(t, x)
plt.plot(t, x_filt)
plt.xlabel('time')
请注意,在您对bilinear
的调用中,您将采样频率设置为 1。让我们改为使用我们的采样频率(上面定义为fs
)。
z, p = signal.bilinear(b, a, fs)
x_filt = signal.lfilter(z, p, x)
plt.figure()
plt.plot(t, x)
plt.plot(t, x_filt)
plt.xlabel('time')
最后一点,您有时可能会观察到 Butterorth 滤波器的相移。 同样,我不是专家,只在我不担心相位的情况下才使用它们,但如果这是一个问题, 请参阅此处以获取有关使用不同类型过滤器的建议。 出于这个原因, 此处的评论还建议使用不同的过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.