[SciPy-User] butterworth filter on .WAV file
Fabrice Silva
silva@lma.cnrs-mrs...
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
array.
And it is so clever that it handles to apply a filter (with
scipy.signal.lfilter) on each of the columns of the array.
Example
In [2]: import scipy.io.wavfile as wv
In [3]: Fs,Sig = wv.read("STE-023.wav")
Warning: %s chunk not understood
Reading fmt chunk
Reading data chunk
In [4]: Fs
Out[4]: 44100
In [5]: Sig.shape, Sig.dtype
Out[5]: ((4434112, 2), dtype('int16'))
In [6]: import scipy.signal as ss
In [8]: SigFilt = ss.lfilter([1],[1, .1], Sig)
Out[8]:
array([[ 0. , 0. ],
[ 4. , -9.4],
[ 7. , -20.7],
...,
[ 0. , 0. ],
[ 0. , 0. ],
[ 0. , 0. ]])
In [9]: SigFilt.shape, SigFilt.dtype
Out[9]: ((4434112, 2), dtype('float64'))
More information about the SciPy-User
mailing list