[SciPy-User] butterworth filter on .WAV file

Sebastian Haase seb.haase at gmail.com
Thu Jul 8 07:53:35 EDT 2010


You could "post" (upload)  large files maybe to http://drop.io  for
everyone interested to listen in (100MB file limit)
-Sebastian


On Thu, Jul 8, 2010 at 1:41 PM, Peter Howard <peterhoward42 at gmail.com> wrote:
> This tip from Chris, has nearly solved the problem.
> Thanks to everybody that has contributed.
> I now get sound out that sounds similar to but different from the input - so
> the fundamentals are sorted thank you.
> However I can only get it to work by experimentation with the frequencies
> and gains - it doesn't work with my understanding of what they theoretically
> should be. Either the filter design module objects to the coefficients or I
> get silence.
> Also, (and almost certainly significantly) the filtered output is only on
> the right stereo channel.
> I wonder if each integer sound sample in a WAV file is split bitwise into
> left and right sectors and the type conversion is corrupting half of each
> sample?
>
> Here's the state of play:
>
> <snip>
> from scipy.io.wavfile import read, write
> from scipy.signal.filter_design import butter, buttord
> from scipy.signal import lfilter, lfiltic
> import numpy as np
> from math import log
>
> rate, sound_samples = read('monty.wav')
> sound_samples = np.float64(sound_samples / 32768.0)
> pass_freq = 0.2
> stop_freq = 0.3
> pass_gain = 0.5 # permissible loss (ripple) in passband (dB)
> stop_gain = 10.0 # attenuation required in stopband (dB)
> ord, wn = buttord(pass_freq, stop_freq, pass_gain, stop_gain)
> b, a = butter(ord, wn, btype = 'low')
> filtered = lfilter(b, a, sound_samples)
> filtered = np.int16(filtered * 32768 * 10)
> write('monty-filtered.wav', rate, filtered)
>
>
>
>
>
> Pete
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>



More information about the SciPy-User mailing list