[SciPy-User] lfilter produce very low output

f5owl at free.fr f5owl at free.fr
Fri Feb 28 05:44:40 EST 2014


Hello,
I have identified my problem : the phil1.wav is a stereo file.
I converted it to mono with audacity and now I have consistent results. 
Probably  r= np.hsplit(sig,2)[0] is not the good way to select only one channel.
Philipp

----- Mail original -----
De: "Warren Weckesser" <warren.weckesser at gmail.com>
À: "SciPy Users List" <scipy-user at scipy.org>
Envoyé: Jeudi 27 Février 2014 17:09:12
Objet: Re: [SciPy-User] lfilter produce very low output

On 2/27/14, f5owl at free.fr <f5owl at free.fr> wrote:
> Dear list readers,
> I am new to scipy and I am trying to filter some wav file containing
> experimental data.
> The files contain an (almost) sine wave at 5kHz with some 50 and 100Hz noise
> and other spurious.
> The fs=44100Hz and samples are 16 bits.
> I use firwin and lfilter to filter my data between 4000 and 6000 Hz.
> My problem is that the output of lfilter is very low and seem to be almost
> independent of the filter frequencies.
> I have made a test file with a pure 5kHz sine wave and result are
> consistant.
> I have to normalize data between -1 and 1 but I have the same problem.
> I can figure out what is wrong.
> I put my code and the end of the message. phil1.wav is real data,
> sin_0_5000_44100.wav is generated sine.
> Attachment is two plots of the first 400 samples made with the two files.
> With the simulated sine wave, result is consistent filter delay and low
> attenuation.
> With the real data, no filter delay and output very low.
> Can someone help ?


Can you put the file phil1.wav somewhere accessible?   It would help
us reproduce the output you are seeing.

Warren


> Thank you
>
> Here is my code :
>
> import matplotlib.pyplot as plt
> import numpy as np
> from scipy.signal import lfilter, firwin
> from scipy.io import wavfile
> #filename='phil1.wav'
> filename='sin_0_5000_44100.wav'
>
> fs, sig = wavfile.read(filename)
>
> # extract first channel
> r= np.hsplit(sig,2)[0]
>
> print('fs = %f'%fs)
> print('min %f max %f mean %f rms
> %f'%(r.min(),r.max(),r.mean(),np.sqrt(np.mean(r**2))))
> flow=4000
> fup=6000
> taps = firwin(256,[flow,fup],nyq=fs/2,pass_zero=False, scale=False)
>
> rf = lfilter(taps, 1.0, r)
>
> print('min %f max %f mean %f rms
> %f'%(rf.min(),rf.max(),rf.mean(),np.sqrt(np.mean(rf**2))))
> t=np.arange(len(r))*(1./fs)
> plt.subplot(211)
> plt.title(filename)
> plt.plot(t[:400],r[:400])
> plt.subplot(212)
> plt.title(filename+' filtered %.0f %.0f'%(flow,fup))
> plt.plot(t[:400],rf[:400])
>
> plt.show()
>
>
_______________________________________________
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