Consider a bandpass filter with Low Cut 17Hz, High Cut 22 Hz, Fs = 45000 Hz and Order = 6. When I pass a mixture of multiple sinusoidal waves through this filter (with a sine wave of frequency 20 Hz), I noticed that Scipy's Butter Bandpass filter, upon filtering, returned values that were unexpectedly high. I did not get a sinusoidal output, but rather, ended up getting an almost straight line that was scaled up by a factor of 1e305. Since I haven't done a course on DSP, and hail from a CS Background, any help would be greatly appreciated.
Here is my code:
from scipy.signal import butter, filtfilt
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = filtfilt(b, a, data)
return y
sos = butter(order, [low, high], btype='band', output='sos')andsosfiltfiltinstead – endolith Jun 07 '19 at 01:34