filtering (signal processing)

John Hunter jdhunter at ace.bsd.uchicago.edu
Mon Dec 30 11:18:51 EST 2002


>>>>> "Nadav" == Nadav Horesh <nadavh at visionsense.com> writes:

    Nadav> As Robert Kern wrote signal tools are part of scipy
    Nadav> (www.scipy.org), 

Hi -- thanks for the info.  I now have the scipy signal tools working.
As a test case (code below), I am doing a lowpass butterworth filter
of a sine wave with noise, and notice that there is a substantial
phase shift when I do the filtering with lfilter.  This is not
surprising, but matlab provides filtfilt which reduces filter
transients and the phase lag.  Is there an equivalent to filtfilt in
the signal tools, or other clever tricks to get rid of the phase lag?

    Nadav> If your convolutions use large kernels, converting to the
    Nadav> time-domain will save you 99% of computation time.

Could you clarify what you mean here -- convolution is a time domain
operation but is often implemented via fft's.  So I am not sure if you
are advising me to use convolution or signaltools here for the
performance boost.

Thanks,
John Hunter

Here is the test code:

from __future__ import division
from scipy import signal, arange, sin, pi
from RandomArray import normal
from scipy.signal import buttord, butter, lfilter

dt = 0.001
t = arange(0.0, 10.0, dt)
nse = normal(0.0, 0.1, t.shape)
s = sin(2*pi*t) + nse

lpcf = 3
lpsf = 5
Nyq = 1/(2*dt)
Rp = 2
Rs = 20
Wp = lpcf/Nyq
Ws = lpsf/Nyq
[n,Wn] = buttord(Wp,Ws,Rp,Rs)
[b,a] = butter(n,Wn)
xlp = lfilter(b,a,s)





More information about the Python-list mailing list