parameters: (b, a, tol=1e-3, rtype='avg')
return_statement: return r / gain, p, k
docstring: Compute partial-fraction expansion of b(z) / a(z).
  
      If `M` is the degree of numerator `b` and `N` the degree of denominator
      `a`::
  
                  b(z)     b[0] + b[1] z**(-1) + ... + b[M] z**(-M)
          H(z) = ------ = ------------------------------------------
                  a(z)     a[0] + a[1] z**(-1) + ... + a[N] z**(-N)
  
      then the partial-fraction expansion H(z) is defined as::
  
                   r[0]                   r[-1]
           = --------------- + ... + ---------------- + k[0] + k[1]z**(-1) ...
             (1-p[0]z**(-1))         (1-p[-1]z**(-1))
  
      If there are any repeated roots (closer than `tol`), then the partial
      fraction expansion has terms like::
  
               r[i]              r[i+1]                    r[i+n-1]
          -------------- + ------------------ + ... + ------------------
          (1-p[i]z**(-1))  (1-p[i]z**(-1))**2         (1-p[i]z**(-1))**n
  
      This function is used for polynomials in negative powers of z,
      such as digital filters in DSP.  For positive powers, use `residue`.
  
      Parameters
      ----------
      b : array_like
          Numerator polynomial coefficients.
      a : array_like
          Denominator polynomial coefficients.
  
      Returns
      -------
      r : ndarray
          Residues.
      p : ndarray
          Poles.
      k : ndarray
          Coefficients of the direct polynomial term.
  
      See Also
      --------
      invresz, residue, unique_roots
docstring_summary: Compute partial-fraction expansion of b(z) / a(z).
docstring_tokens: Compute partial - fraction expansion of b ( z ) / a ( z ) .
function: def residuez(b, a, tol=1e-3, rtype='avg'):
      """
      Compute partial-fraction expansion of b(z) / a(z).
  
      If `M` is the degree of numerator `b` and `N` the degree of denominator
      `a`::
  
                  b(z)     b[0] + b[1] z**(-1) + ... + b[M] z**(-M)
          H(z) = ------ = ------------------------------------------
                  a(z)     a[0] + a[1] z**(-1) + ... + a[N] z**(-N)
  
      then the partial-fraction expansion H(z) is defined as::
  
                   r[0]                   r[-1]
           = --------------- + ... + ---------------- + k[0] + k[1]z**(-1) ...
             (1-p[0]z**(-1))         (1-p[-1]z**(-1))
  
      If there are any repeated roots (closer than `tol`), then the partial
      fraction expansion has terms like::
  
               r[i]              r[i+1]                    r[i+n-1]
          -------------- + ------------------ + ... + ------------------
          (1-p[i]z**(-1))  (1-p[i]z**(-1))**2         (1-p[i]z**(-1))**n
  
      This function is used for polynomials in negative powers of z,
      such as digital filters in DSP.  For positive powers, use `residue`.
  
      Parameters
      ----------
      b : array_like
          Numerator polynomial coefficients.
      a : array_like
          Denominator polynomial coefficients.
  
      Returns
      -------
      r : ndarray
          Residues.
      p : ndarray
          Poles.
      k : ndarray
          Coefficients of the direct polynomial term.
  
      See Also
      --------
      invresz, residue, unique_roots
  
      """
      b, a = map(asarray, (b, a))
      gain = a[0]
      brev, arev = b[::-1], a[::-1]
      krev, brev = polydiv(brev, arev)
      if krev == []:
          k = []
      else:
          k = krev[::-1]
      b = brev[::-1]
      p = roots(a)
      r = p * 0.0
      pout, mult = unique_roots(p, tol=tol, rtype=rtype)
      p = []
      for n in range(len(pout)):
          p.extend([pout[n]] * mult[n])
      p = asarray(p)
      # Compute the residue from the general formula (for discrete-time)
      #  the polynomial is in z**(-1) and the multiplication is by terms
      #  like this (1-p[i] z**(-1))**mult[i].  After differentiation,
      #  we must divide by (-p[i])**(m-k) as well as (m-k)!
      indx = 0
      for n in range(len(pout)):
          bn = brev.copy()
          pn = []
          for l in range(len(pout)):
              if l != n:
                  pn.extend([pout[l]] * mult[l])
          an = atleast_1d(poly(pn))[::-1]
          # bn(z) / an(z) is (1-po[n] z**(-1))**Nn * b(z) / a(z) where Nn is
          # multiplicity of pole at po[n] and b(z) and a(z) are polynomials.
          sig = mult[n]
          for m in range(sig, 0, -1):
              if sig > m:
                  # compute next derivative of bn(s) / an(s)
                  term1 = polymul(polyder(bn, 1), an)
                  term2 = polymul(bn, polyder(an, 1))
                  bn = polysub(term1, term2)
                  an = polymul(an, an)
              r[indx + m - 1] = (polyval(bn, 1.0 / pout[n]) /
                                 polyval(an, 1.0 / pout[n]) /
                                 factorial(sig - m) / (-pout[n]) ** (sig - m))
          indx += sig
      return r / gain, p, k
function_tokens: def residuez ( b , a , tol = 1e-3 , rtype = 'avg' ) : b , a = map ( asarray , ( b , a ) ) gain = a [ 0 ] brev , arev = b [ : : - 1 ] , a [ : : - 1 ] krev , brev = polydiv ( brev , arev ) if krev == [ ] : k = [ ] else : k = krev [ : : - 1 ] b = brev [ : : - 1 ] p = roots ( a ) r = p * 0.0 pout , mult = unique_roots ( p , tol = tol , rtype = rtype ) p = [ ] for n in range ( len ( pout ) ) : p . extend ( [ pout [ n ] ] * mult [ n ] ) p = asarray ( p ) # Compute the residue from the general formula (for discrete-time) #  the polynomial is in z**(-1) and the multiplication is by terms #  like this (1-p[i] z**(-1))**mult[i].  After differentiation, #  we must divide by (-p[i])**(m-k) as well as (m-k)! indx = 0 for n in range ( len ( pout ) ) : bn = brev . copy ( ) pn = [ ] for l in range ( len ( pout ) ) : if l != n : pn . extend ( [ pout [ l ] ] * mult [ l ] ) an = atleast_1d ( poly ( pn ) ) [ : : - 1 ] # bn(z) / an(z) is (1-po[n] z**(-1))**Nn * b(z) / a(z) where Nn is # multiplicity of pole at po[n] and b(z) and a(z) are polynomials. sig = mult [ n ] for m in range ( sig , 0 , - 1 ) : if sig > m : # compute next derivative of bn(s) / an(s) term1 = polymul ( polyder ( bn , 1 ) , an ) term2 = polymul ( bn , polyder ( an , 1 ) ) bn = polysub ( term1 , term2 ) an = polymul ( an , an ) r [ indx + m - 1 ] = ( polyval ( bn , 1.0 / pout [ n ] ) / polyval ( an , 1.0 / pout [ n ] ) / factorial ( sig - m ) / ( - pout [ n ] ) ** ( sig - m ) ) indx += sig return r / gain , p , k