[SciPy-user] Problems with filter design

Robert Kern robert.kern at gmail.com
Sat Jan 20 23:09:43 CST 2007

Kumar Appaiah wrote:
> Dear Scipy users,
> I am having problems with the filter design functions in SciPy. I
> am unable to find out what I am doing wrong.
> Here's the relevant code section:
> <code>
> omega_c = sqrt(0.8)
> omega_r = 1 / sqrt(0.8)
> omega_s = 7.5
> gpass = 0.1
> gstop = 43.46
> (n, Wn) = signal.ellipord(omega_c, omega_r, gpass, gstop, analog=1)
> [B, A] = signal.ellip(n, gpass, gstop, Wn, analog=1)
> </code>
> However, it throws an error at me, like this:
> <error>
> Traceback (most recent call last):
>   File "ellip.py", line 18, in ?
>     [B, A] = signal.ellip(n, gpass, gstop, Wn, analog=1)
>   File
> "/usr/lib/python2.4/site-packages/scipy/signal/filter_design.py", line
> 514, in ellip
>     return iirfilter(N, Wn, rs=rs, rp=rp, btype=btype, analog=analog,
> output=output, ftype='elliptic')
>   File
> "/usr/lib/python2.4/site-packages/scipy/signal/filter_design.py", line
> 448, in iirfilter
>     b, a = lp2lp(b,a,wo=wo)
>   File
> "/usr/lib/python2.4/site-packages/scipy/signal/filter_design.py", line
> 186, in lp2lp
>     wo = wo[0]
> IndexError: 0-d arrays can't be indexed
> </error>
> Referring to filter_design.py, I guessed an array may be expected in
> Wn. But neither does that make sense, nor does it give the expected
> output. What is the mistake?

It's a subtle bug. Wn is being coerced to an array in iirfilter(). When Wn is a
scalar, it becomes a rank-0 array. Unfortunately, there was a bit of inaccurate
type-checking in lp2lp and lp2hp that assumed that if the type of wo was an
array, then it would be a (2,)-array of 2 critical frequencies, not a ()-array
(and don't ask me whether or not having two critical frequencies makes sense.
It's been a long time since I took my signal processing class).

I've checked in a workaround.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

More information about the SciPy-user mailing list