Band Pass Filter Valueerror: Digital Filter Critical Frequencies Must Be 0 < Wn < 1
Solution 1:
It may be because of the input of parameter fs
. It has to be larger than any of 2 * Wn
.
As in scipy/signal/filter_design.py source code:
if fs isnotNone:
if analog:
raise ValueError("fs cannot be specified for an analog filter")
Wn = 2*Wn/fs
And later:
if not analog:
if numpy.any(Wn <= 0) or numpy.any(Wn >= 1):
raise ValueError("Digital filter critical frequencies must be 0 < Wn < 1")
Solution 2:
scipy.signal.butter(N, Wn, btype='low', analog=False, output='ba')
Wn : array_like
A scalar or length-2 sequence giving the critical frequencies. For a Butterworth filter, this is the point at which the gain drops to 1/sqrt(2) that of the passband (the “-3 dB point”). For digital filters, Wn is normalized from 0 to 1, where 1 is the Nyquist frequency, pi radians/sample. (Wn is thus in half-cycles / sample.) For analog filters, Wn is an angular frequency (e.g. rad/s).
Your exception is here where low/high is not [0,1]
b, a = butter(filter_order, [low, high], btype='band', analog=False)
for filter_type == 1
, Wn
is float other than nparray.
https://github.com/scipy/scipy/blob/v0.19.1/scipy/signal/filter_design.py#L2226-L2297
>>>N, Wn = signal.buttord([20, 50], [14, 60], 3, 40, True)>>>b, a = signal.butter(N, Wn, 'band', True)
Post a Comment for "Band Pass Filter Valueerror: Digital Filter Critical Frequencies Must Be 0 < Wn < 1"