python 带通滤波器 - 奇异矩阵误差
python bandpass filter - singular matrix error
我一直在尝试使用 scipy 设计带通滤波器,但我一直收到 LinAlg 奇异矩阵错误。我读到奇异矩阵是不可逆的,但我不确定该错误是如何出现的以及我可以做些什么来解决它
代码接收 EEG 信号(在下面的代码中,我刚刚将其替换为一个 int 数组用于测试)并滤除频率 < 8Hz 和 > 12Hz(alpha 波段)
谁能阐明奇异矩阵误差的来源?或者,如果您知道像这样过滤信号的更好方法,我也很想测试其他选项
from scipy import signal
from scipy.signal import filter_design as fd
import matplotlib.pylab as plt
#bandpass
Wp = [8, 12] # Cutoff frequency
Ws = [7.5, 12.5] # Stop frequency
Rp = 1 # passband maximum loss (gpass)
As = 100 # stoppand min attenuation (gstop)
b,a = fd.iirdesign(Wp,Ws,Rp,As,ftype='butter')
w,H = signal.freqz(b,a) # filter response
plt.plot(w,H)
t = np.linspace(1,256,256)
x = np.arange(256)
plt.plot(t,x)
y = signal.filtfilt(b,a,x)
plt.plot(t,y)
如iirdesign
documentation所示,Wp
和Ws
是"are normalized from 0 to 1, where 1 is the Nyquist frequency"。
如果您的采样率为 Fs
(例如 100Hz),您可以使用以下方法标准化截止频率和停止频率:
Wp = [x / (Fs/2.0) for x in Wp]
Ws = [x / (Fs/2.0) for x in Ws]
我一直在尝试使用 scipy 设计带通滤波器,但我一直收到 LinAlg 奇异矩阵错误。我读到奇异矩阵是不可逆的,但我不确定该错误是如何出现的以及我可以做些什么来解决它
代码接收 EEG 信号(在下面的代码中,我刚刚将其替换为一个 int 数组用于测试)并滤除频率 < 8Hz 和 > 12Hz(alpha 波段)
谁能阐明奇异矩阵误差的来源?或者,如果您知道像这样过滤信号的更好方法,我也很想测试其他选项
from scipy import signal
from scipy.signal import filter_design as fd
import matplotlib.pylab as plt
#bandpass
Wp = [8, 12] # Cutoff frequency
Ws = [7.5, 12.5] # Stop frequency
Rp = 1 # passband maximum loss (gpass)
As = 100 # stoppand min attenuation (gstop)
b,a = fd.iirdesign(Wp,Ws,Rp,As,ftype='butter')
w,H = signal.freqz(b,a) # filter response
plt.plot(w,H)
t = np.linspace(1,256,256)
x = np.arange(256)
plt.plot(t,x)
y = signal.filtfilt(b,a,x)
plt.plot(t,y)
如iirdesign
documentation所示,Wp
和Ws
是"are normalized from 0 to 1, where 1 is the Nyquist frequency"。
如果您的采样率为 Fs
(例如 100Hz),您可以使用以下方法标准化截止频率和停止频率:
Wp = [x / (Fs/2.0) for x in Wp]
Ws = [x / (Fs/2.0) for x in Ws]