[SciPy-Dev] scipy.signal.butter returns complex coefficients

Eric Moore ewm@redtetrahedron....
Wed Feb 20 17:58:55 CST 2013

Pierre Haessig wrote:
> Hello,
> Just a quick question about filter design using scipy.signal.butter :
> (using scipy '0.10.1')
>  >>> import scipy.signal as sig
>  >>> B,A = sig.butter(N=4, Wn=1, analog=1) # 4rth order low-pass filter
> with cutoff at 1 rad/s
>  >>> A,B
> (array([ 1.00000000 +0.00000000e+00j, 2.61312593 -1.11022302e-16j,
> 3.41421356 +0.00000000e+00j, 2.61312593 -1.11022302e-16j,
> 1.00000000 -1.66533454e-16j]),
> array([ 1.+0.j]))
> I was surprised by the result since I was expecting real numbers and not
> complex numbers. And indeed the imaginary part is zero with respect to
> floating point precision. For comparison, bessel function return real
> coefficients.
> So my question is : is the return of complex coefficients the expected
> behavior ? or should I place an issue on Trac ?
> best,
> Pierre
> (Maybe I didn't use the proper keywords because a quick Google search
> didn't give me preexisting discussion on this topic)

I'd say that no it isn't expected.  What is happening here is that the 
code in np.poly which constructs a polynomial from its zeros tries to 
detect that you have pairs of complex conjugate roots and then return a 
real array.  That code is failing in this particular case.  (The code in 
question is lines 137-145 of numpy/lib/polynomial.py: 

I'm not sure that the correct fix would be, perhaps signal.buttap should 
calculate the poles by calculating half of them, and then conjugating. 
Since I'd bet that the ultimate cause is that we aren't getting exact 
conjugates from the complex exponential.


More information about the SciPy-Dev mailing list