[SciPy-User] butterworth filter on .WAV file
Thu Jul 8 08:21:20 CDT 2010
Le jeudi 08 juillet 2010 à 13:00 +0100, Peter Howard a écrit :
> Hang on a minute - my brain is working backwards... am I wasting
> everyone's time here...
> If a .WAV file contains stereo sound data - then it's never going to
> work sucking it in and simply applying a filter to the numbers is it?
> So how come it sort of works?
> Or is the entire NumPy/SciPy suite so clever about working in
> N-dimensions that it treats the two sound channels as
> multi-dimensioned arrays right from the .WAV read() call? - and the
> filtering is separate for each dimension?
So you might consider NumPy/SciPy clever! When reading a wav file, the
output array is a 2D array with shape (M,N) where M is the number of
samples of each channel (time range*sampling frequency) and N is the
number of channels. Each channel is stored in a column of the output
And it is so clever that it handles to apply a filter (with
scipy.signal.lfilter) on each of the columns of the array.
In : import scipy.io.wavfile as wv
In : Fs,Sig = wv.read("STE-023.wav")
Warning: %s chunk not understood
Reading fmt chunk
Reading data chunk
In : Fs
In : Sig.shape, Sig.dtype
Out: ((4434112, 2), dtype('int16'))
In : import scipy.signal as ss
In : SigFilt = ss.lfilter(,[1, .1], Sig)
array([[ 0. , 0. ],
[ 4. , -9.4],
[ 7. , -20.7],
[ 0. , 0. ],
[ 0. , 0. ],
[ 0. , 0. ]])
In : SigFilt.shape, SigFilt.dtype
Out: ((4434112, 2), dtype('float64'))
More information about the SciPy-User