[SciPy-user] High-pass filtering

Travis Oliphant oliphant at ee.byu.edu
Wed May 12 15:56:10 CDT 2004

Jesper Larsen wrote:

>Dear scipy mailing list,
>I would like to perform a high-pass filtering of a simple timeseries of 
>floats. I'm not really sure how to do that using numarray and scipy. Can 
>anyone post a simple example of how to do that? I have no special preferences 
>for window type.

SciPy uses Numeric and doesn't require numarray (it can use numarray 
objects as inputs which will be treated as Python sequences and can be 

What kind of high-pass filter are you looking for.  Simple FIR filters 
are quite simple to design and give linear phase.  Other IIR filters are 
available.  I'll show you how to design a high-pass FIR filter using the 
remez algorithm (you could also look at signal.firwin for windowed 
filter design (but remez is usually a better solution).

Let T be the sample distance and must be defined

F = 1.0/T  
bands = array([0,0.5,0.6,1])*F/2  # this places band-edges
gain = [0,1]  # high-pass filter
N = 25  # length of FIR filter
b = signal.remez(N, bands, gain,Hz=F)

w,h = signal.freqz(b,1)  # this will show you the filter

To filter a time series you can use

out = signal.lfilter(b,[1],in_)

Or simply
out = signal.convolve(in_,b)[:-(N-1)]

You can get different transients using

out = signal.convolve(in_,b,'same') (cuts off on both ends)

Good luck,

-Travis O.

More information about the SciPy-user mailing list