[SciPy-user] ***[Possible UCE]*** Band pass filter design

Travis Oliphant oliphant at ee.byu.edu
Mon Apr 3 19:11:52 CDT 2006


vincenzo cacciatore wrote:

> Hi all,
> i would like to design a high pass filter with scipy.signal module.
>
> This is the code i'm using to:
>
> import scipy.signal as signal
> import scipy
>
> #first of all i design the lowpass fir filter. This is a 10 taps filter
> with cutoff frequency =1 (as help tell me to do)
>
> lpwindow=signal.firwin(10,1)
>
> #with the following instruction i'm creating a band pass filter from
> the low pass one
> bpwindow=signal.lp2bp(lpwindow,1,0.5,0.2)
>
> My problem is that the band-pass filter obtained with lp2bp function is
> 16 taps one!
> How is it possible??
>

The low-pass to band-pass function uses a specific transformation that 
changes the number of taps from N to 2*N-1

So, for me the number of taps goes from 10 to 19. 

You have two options:

1) Change the number of taps in your underlying low-pass filter

2) (Preferred).   Design the filter in the frequency domain explicitly 
(i.e. make a vector of ones and zeros that define your filter).  Use the 
inverse FFT to get the ideal set of coefficients and then window them 
using the hamming window. 

Something like this:

We will use normalized frequencies where 1 corresponds to Nyquist (i.e. 
pi radians / sample) --- your use of 1 for a cutoff showed that you need 
to re-think what normalized coordinates are..

Assume the pass-band is f1 and f2 so that

Let the number of taps in the filter be N and Let

desired = {1  if |f| in [f1,f2] 
                 { 0  otherwise

from numpy import *
from scipy import signal

Ndesign = 256  # assume it is even
f = dft.fftfreq(Ndesign,d=0.5)
af = abs(f)
desired = where((af > f1) & (af < f2), 1,0)
hideal = ifft(desired).real
win = signal.get_window('hamming',N)

# Now we need to get the actual tap coefficients by windowing this result.
htrunc = dft.fftshift(r_[hideal[:N/2],hideal[-(N-1)/2:]])
hfinal = win * htrunc

# The final coefficents contain the taps of your filter (with the 
largest tap at the center).
#  We should probably add something like this to the library.

Best,

-Travis





More information about the SciPy-user mailing list