你可以使用Scipy如何对时间序列数据集应用低通滤波器和高通滤波器?

huangapple go评论84阅读模式
英文:

How can I apply a low pass and high pass filter to a time series dataset using scipy?

问题

我有一个采样率为1/10且样本大小为8390的时间序列数据集。我只想对前1000个和最后1000个样本应用低通和高通滤波器,以便计算傅里叶变换时不受低频干扰的影响。

我尝试使用scipy的巴特沃斯滤波器函数生成一个系数数组'lowpass',然后将该数组与我的数据集y值'yf_ISLL_11_21_irfft'卷积。

from scipy import signal

lowpass = scipy.signal.butter(2, 0.1, btype='low', analog=False, output='ba', fs=0.1)

yf_ISLL_11_21_irfft = np.convolve(lowpass, yf_ISLL_11_21_irfft)
plt.plot(time_data_ISLL_11_21, yf_ISLL_11_21_irfft)

但是出现错误消息:'数字滤波器临界频率必须满足0 < Wn < 1',尽管我的Wn == 0.1。

英文:

I have a time series dataset with sample rate 1/10 and sample size 8390. I just want to apply low and high pass filters for the first 1000 and last 1000 samples so I can compute a fourier transform without low end artefacts affecting the result.

I tried using scipy's butterworth filter function to generate an array of coefficients 'lowpass' then convolving that array with my dataset y values 'yf_ISLL_11_21_irfft'.

from scipy import signal

lowpass = scipy.signal.butter(2, 0.1, btype=&#39;low&#39;, analog=False, output=&#39;ba&#39;, fs=0.1)

yf_ISLL_11_21_irfft = np.convolve(lowpass, yf_ISLL_11_21_irfft)
plt.plot(time_data_ISLL_11_21, yf_ISLL_11_21_irfft)



But the error message: 'Digital filter critical frequencies must be 0 < Wn < 1' is returned, despite my Wn == 0.1.

答案1

得分: 1

我在运行您的前两行时遇到了一个略有不同的错误信息:

ValueError: 数字滤波器的临界频率必须在 0 < Wn < fs/2 (fs=0.1 -> fs/2=0.05)

但我认为根本原因是相同的。当您为 fs 提供一个值时,Wn 参数需要在 0 和奈奎斯特频率之间。听起来(也许我理解有误),您想将 0.1*fs 作为您的 Wn 值。

英文:

I get a slightly different error message when I run your first two lines:

ValueError: Digital filter critical frequencies must be 0 &lt; Wn &lt; fs/2 (fs=0.1 -&gt; fs/2=0.05)

But I think the underlying reason is the same. When you provide a value for fs, the Wn parameters needs to be between 0 and the Nyquist frequency. It sounds like (and maybe I am misinterpreting), you want to use a value of 0.1*fs as your Wn value.

huangapple
  • 本文由 发表于 2023年2月18日 23:58:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/75494558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定