I want to filter out everything outside 20 Hz - 20000 Hz. I'm using a Butterworth filter:
from scipy.io import wavfile
from scipy import signal
import numpy
sr, x = wavfile.read('sweep.wav')
nyq = 0.5 * sr
b, a = signal.butter(5, [20.0 / nyq, 20000.0 / nyq], btype='band')
x = signal.lfilter(b, a, x)
x = numpy.float32(x)
x /= numpy.max(numpy.abs(x))
wavfile.write('b.wav', sr, x)
I've noticed that it works with a 44.1 khz file, but not with a 96 khz WAV file (demo file here) (it's not an audio I/O problem): the output is either blank (silence) or exploding (with some other input wav files).
1) Is there something that makes that the Butterworth filters don't work with a bandpass [b1, b2] where b2 < 0.5 ?
2) More generally, how would you do a filtering to keep only 20 - 20000Hz with Python / scipy? (no other external library)