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

SciPy Trac scipy-tickets@scipy....
Sat Oct 16 10:27:01 CDT 2010


#371: signal.residue fails when len(b) < len(a)
----------------------------+-----------------------------------------------
 Reporter:  ryankrauss      |       Owner:  stefan     
     Type:  defect          |      Status:  needs_info 
 Priority:  normal          |   Milestone:  Unscheduled
Component:  scipy.signal    |     Version:  0.5.2      
 Keywords:  signal residue  |  
----------------------------+-----------------------------------------------
Description changed by warren.weckesser:

Old description:

> 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
>  last)
>
> C:\Python24\<ipython console>
>
> C:\Python24\Lib\site-packages\scipy\signal\signaltools.py in residue(b,
> a, tol,
> rtype)
>   1054
>   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)
> Out[77]:
> (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=[]
>    else:
>        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.

New description:

 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
  last)

 C:\Python24\<ipython console>

 C:\Python24\Lib\site-packages\scipy\signal\signaltools.py in residue(b, a,
 tol,
 rtype)
   1054
   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)
 Out[77]:
 (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=[]
    else:
        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/ticket/371#comment:10>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list