[Scipy-tickets] [SciPy] #371: signal.residue fails when len(b) < len(a)

SciPy scipy-tickets@scipy....
Tue Feb 13 14:03:27 CST 2007

#371: signal.residue fails when len(b) < len(a)
 Reporter:  ryankrauss    |       Owner:  somebody      
     Type:  defect        |      Status:  new           
 Priority:  normal        |   Milestone:                
Component:  scipy.signal  |     Version:  0.5.2         
 Severity:  normal        |    Keywords:  signal residue
 The problem seems to come from polydiv requiring
 that the numerator polynomial be of degree at most 1 less than the
 denominator.  If I have a denominator of s^2+3*s+2, the numerator must
 have an s coefficient (even if that coefficient is 0) for
 signal.residue to work:

 In [75]: a
 Out[75]: array([1, 3, 2])

 In [76]: signal.residue([1],a)
 exceptions.ValueError                                Traceback (most
 recent cal

 C:\Python24\<ipython console>

 C:\Python24\Lib\site-packages\scipy\signal\signaltools.py in residue(b, a,
   1055     b,a = map(asarray,(b,a))
 -> 1056     k,b = polydiv(b,a)
   1057     p = roots(a)
   1058     r = p*0.0

 C:\Python24\Lib\site-packages\numpy\lib\polynomial.py in polydiv(u, v)
    399     n = len(v) - 1
    400     scale = 1. / v[0]
 --> 401     q = NX.zeros((m-n+1,), float)
    402     r = u.copy()
    403     for k in range(0, m-n+1):

 ValueError: negative dimensions are not allowed

 In [77]: signal.residue([0,1],a)
 (array([ 1.+0.j, -1.+0.j]),
  array([-1.+0.j, -2.+0.j]),
  array([], dtype=float64))

 I think the simple solution is to replace line 1056 with these four lines:
    if len(b)<len(a):
        k,b = polydiv(b,a)

 where the last line above is the old line 1056.  Basically, specify
 that there is no k term if the len of b is less than the len of a.

Ticket URL: <http://projects.scipy.org/scipy/scipy/ticket/371>
SciPy <http://www.scipy.org/>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list