parameters: (wp, ws, gpass, gstop, analog=False)
return_statement: return ord, wn
docstring: Chebyshev type II filter order selection.
  
      Return the order of the lowest order digital or analog Chebyshev Type II
      filter that loses no more than `gpass` dB in the passband and has at least
      `gstop` dB attenuation in the stopband.
  
      Parameters
      ----------
      wp, ws : float
          Passband and stopband edge frequencies.
          For digital filters, these are normalized from 0 to 1, where 1 is the
          Nyquist frequency, pi radians/sample.  (`wp` and `ws` are thus in
          half-cycles / sample.)  For example:
  
              - Lowpass:   wp = 0.2,          ws = 0.3
              - Highpass:  wp = 0.3,          ws = 0.2
              - Bandpass:  wp = [0.2, 0.5],   ws = [0.1, 0.6]
              - Bandstop:  wp = [0.1, 0.6],   ws = [0.2, 0.5]
  
          For analog filters, `wp` and `ws` are angular frequencies (e.g. rad/s).
  
      gpass : float
          The maximum loss in the passband (dB).
      gstop : float
          The minimum attenuation in the stopband (dB).
      analog : bool, optional
          When True, return an analog filter, otherwise a digital filter is
          returned.
  
      Returns
      -------
      ord : int
          The lowest order for a Chebyshev type II filter that meets specs.
      wn : ndarray or float
          The Chebyshev natural frequency (the "3dB frequency") for use with
          `cheby2` to give filter results.
  
      See Also
      --------
      cheby2 : Filter design using order and critical points
      buttord : Find order and critical points from passband and stopband spec
      cheb1ord, ellipord
      iirfilter : General filter design using order and critical frequencies
      iirdesign : General filter design using passband and stopband spec
  
      Examples
      --------
      Design a digital bandstop filter which rejects -60 dB from 0.2*(fs/2) to
      0.5*(fs/2), while staying within 3 dB below 0.1*(fs/2) or above
      0.6*(fs/2).  Plot its frequency response, showing the passband and
      stopband constraints in gray.
  
      >>> from scipy import signal
      >>> import matplotlib.pyplot as plt
  
      >>> N, Wn = signal.cheb2ord([0.1, 0.6], [0.2, 0.5], 3, 60)
      >>> b, a = signal.cheby2(N, 60, Wn, 'stop')
      >>> w, h = signal.freqz(b, a)
      >>> plt.semilogx(w / np.pi, 20 * np.log10(abs(h)))
      >>> plt.title('Chebyshev II bandstop filter fit to constraints')
      >>> plt.xlabel('Normalized frequency')
      >>> plt.ylabel('Amplitude [dB]')
      >>> plt.grid(which='both', axis='both')
      >>> plt.fill([.01, .1, .1, .01], [-3,  -3, -99, -99], '0.9', lw=0) # stop
      >>> plt.fill([.2,  .2, .5,  .5], [ 9, -60, -60,   9], '0.9', lw=0) # pass
      >>> plt.fill([.6,  .6,  2,   2], [-99, -3,  -3, -99], '0.9', lw=0) # stop
      >>> plt.axis([0.06, 1, -80, 3])
      >>> plt.show()
docstring_summary: Chebyshev type II filter order selection.
docstring_tokens: Chebyshev type II filter order selection .
function: def cheb2ord(wp, ws, gpass, gstop, analog=False):
      """Chebyshev type II filter order selection.
  
      Return the order of the lowest order digital or analog Chebyshev Type II
      filter that loses no more than `gpass` dB in the passband and has at least
      `gstop` dB attenuation in the stopband.
  
      Parameters
      ----------
      wp, ws : float
          Passband and stopband edge frequencies.
          For digital filters, these are normalized from 0 to 1, where 1 is the
          Nyquist frequency, pi radians/sample.  (`wp` and `ws` are thus in
          half-cycles / sample.)  For example:
  
              - Lowpass:   wp = 0.2,          ws = 0.3
              - Highpass:  wp = 0.3,          ws = 0.2
              - Bandpass:  wp = [0.2, 0.5],   ws = [0.1, 0.6]
              - Bandstop:  wp = [0.1, 0.6],   ws = [0.2, 0.5]
  
          For analog filters, `wp` and `ws` are angular frequencies (e.g. rad/s).
  
      gpass : float
          The maximum loss in the passband (dB).
      gstop : float
          The minimum attenuation in the stopband (dB).
      analog : bool, optional
          When True, return an analog filter, otherwise a digital filter is
          returned.
  
      Returns
      -------
      ord : int
          The lowest order for a Chebyshev type II filter that meets specs.
      wn : ndarray or float
          The Chebyshev natural frequency (the "3dB frequency") for use with
          `cheby2` to give filter results.
  
      See Also
      --------
      cheby2 : Filter design using order and critical points
      buttord : Find order and critical points from passband and stopband spec
      cheb1ord, ellipord
      iirfilter : General filter design using order and critical frequencies
      iirdesign : General filter design using passband and stopband spec
  
      Examples
      --------
      Design a digital bandstop filter which rejects -60 dB from 0.2*(fs/2) to
      0.5*(fs/2), while staying within 3 dB below 0.1*(fs/2) or above
      0.6*(fs/2).  Plot its frequency response, showing the passband and
      stopband constraints in gray.
  
      >>> from scipy import signal
      >>> import matplotlib.pyplot as plt
  
      >>> N, Wn = signal.cheb2ord([0.1, 0.6], [0.2, 0.5], 3, 60)
      >>> b, a = signal.cheby2(N, 60, Wn, 'stop')
      >>> w, h = signal.freqz(b, a)
      >>> plt.semilogx(w / np.pi, 20 * np.log10(abs(h)))
      >>> plt.title('Chebyshev II bandstop filter fit to constraints')
      >>> plt.xlabel('Normalized frequency')
      >>> plt.ylabel('Amplitude [dB]')
      >>> plt.grid(which='both', axis='both')
      >>> plt.fill([.01, .1, .1, .01], [-3,  -3, -99, -99], '0.9', lw=0) # stop
      >>> plt.fill([.2,  .2, .5,  .5], [ 9, -60, -60,   9], '0.9', lw=0) # pass
      >>> plt.fill([.6,  .6,  2,   2], [-99, -3,  -3, -99], '0.9', lw=0) # stop
      >>> plt.axis([0.06, 1, -80, 3])
      >>> plt.show()
  
      """
      wp = atleast_1d(wp)
      ws = atleast_1d(ws)
      filter_type = 2 * (len(wp) - 1)
      if wp[0] < ws[0]:
          filter_type += 1
      else:
          filter_type += 2
  
      # Pre-warp frequencies for digital filter design
      if not analog:
          passb = tan(pi * wp / 2.0)
          stopb = tan(pi * ws / 2.0)
      else:
          passb = wp * 1.0
          stopb = ws * 1.0
  
      if filter_type == 1:           # low
          nat = stopb / passb
      elif filter_type == 2:          # high
          nat = passb / stopb
      elif filter_type == 3:     # stop
          wp0 = optimize.fminbound(band_stop_obj, passb[0], stopb[0] - 1e-12,
                                   args=(0, passb, stopb, gpass, gstop, 'cheby'),
                                   disp=0)
          passb[0] = wp0
          wp1 = optimize.fminbound(band_stop_obj, stopb[1] + 1e-12, passb[1],
                                   args=(1, passb, stopb, gpass, gstop, 'cheby'),
                                   disp=0)
          passb[1] = wp1
          nat = ((stopb * (passb[0] - passb[1])) /
                 (stopb ** 2 - passb[0] * passb[1]))
      elif filter_type == 4:  # pass
          nat = ((stopb ** 2 - passb[0] * passb[1]) /
                 (stopb * (passb[0] - passb[1])))
  
      nat = min(abs(nat))
  
      GSTOP = 10 ** (0.1 * abs(gstop))
      GPASS = 10 ** (0.1 * abs(gpass))
      ord = int(ceil(arccosh(sqrt((GSTOP - 1.0) / (GPASS - 1.0))) /
                     arccosh(nat)))
  
      # Find frequency where analog response is -gpass dB.
      # Then convert back from low-pass prototype to the original filter.
  
      new_freq = cosh(1.0 / ord * arccosh(sqrt((GSTOP - 1.0) / (GPASS - 1.0))))
      new_freq = 1.0 / new_freq
  
      if filter_type == 1:
          nat = passb / new_freq
      elif filter_type == 2:
          nat = passb * new_freq
      elif filter_type == 3:
          nat = numpy.zeros(2, float)
          nat[0] = (new_freq / 2.0 * (passb[0] - passb[1]) +
                    sqrt(new_freq ** 2 * (passb[1] - passb[0]) ** 2 / 4.0 +
                         passb[1] * passb[0]))
          nat[1] = passb[1] * passb[0] / nat[0]
      elif filter_type == 4:
          nat = numpy.zeros(2, float)
          nat[0] = (1.0 / (2.0 * new_freq) * (passb[0] - passb[1]) +
                    sqrt((passb[1] - passb[0]) ** 2 / (4.0 * new_freq ** 2) +
                         passb[1] * passb[0]))
          nat[1] = passb[0] * passb[1] / nat[0]
  
      if not analog:
          wn = (2.0 / pi) * arctan(nat)
      else:
          wn = nat
  
      if len(wn) == 1:
          wn = wn[0]
      return ord, wn
function_tokens: def cheb2ord ( wp , ws , gpass , gstop , analog = False ) : wp = atleast_1d ( wp ) ws = atleast_1d ( ws ) filter_type = 2 * ( len ( wp ) - 1 ) if wp [ 0 ] < ws [ 0 ] : filter_type += 1 else : filter_type += 2 # Pre-warp frequencies for digital filter design if not analog : passb = tan ( pi * wp / 2.0 ) stopb = tan ( pi * ws / 2.0 ) else : passb = wp * 1.0 stopb = ws * 1.0 if filter_type == 1 : # low nat = stopb / passb elif filter_type == 2 : # high nat = passb / stopb elif filter_type == 3 : # stop wp0 = optimize . fminbound ( band_stop_obj , passb [ 0 ] , stopb [ 0 ] - 1e-12 , args = ( 0 , passb , stopb , gpass , gstop , 'cheby' ) , disp = 0 ) passb [ 0 ] = wp0 wp1 = optimize . fminbound ( band_stop_obj , stopb [ 1 ] + 1e-12 , passb [ 1 ] , args = ( 1 , passb , stopb , gpass , gstop , 'cheby' ) , disp = 0 ) passb [ 1 ] = wp1 nat = ( ( stopb * ( passb [ 0 ] - passb [ 1 ] ) ) / ( stopb ** 2 - passb [ 0 ] * passb [ 1 ] ) ) elif filter_type == 4 : # pass nat = ( ( stopb ** 2 - passb [ 0 ] * passb [ 1 ] ) / ( stopb * ( passb [ 0 ] - passb [ 1 ] ) ) ) nat = min ( abs ( nat ) ) GSTOP = 10 ** ( 0.1 * abs ( gstop ) ) GPASS = 10 ** ( 0.1 * abs ( gpass ) ) ord = int ( ceil ( arccosh ( sqrt ( ( GSTOP - 1.0 ) / ( GPASS - 1.0 ) ) ) / arccosh ( nat ) ) ) # Find frequency where analog response is -gpass dB. # Then convert back from low-pass prototype to the original filter. new_freq = cosh ( 1.0 / ord * arccosh ( sqrt ( ( GSTOP - 1.0 ) / ( GPASS - 1.0 ) ) ) ) new_freq = 1.0 / new_freq if filter_type == 1 : nat = passb / new_freq elif filter_type == 2 : nat = passb * new_freq elif filter_type == 3 : nat = numpy . zeros ( 2 , float ) nat [ 0 ] = ( new_freq / 2.0 * ( passb [ 0 ] - passb [ 1 ] ) + sqrt ( new_freq ** 2 * ( passb [ 1 ] - passb [ 0 ] ) ** 2 / 4.0 + passb [ 1 ] * passb [ 0 ] ) ) nat [ 1 ] = passb [ 1 ] * passb [ 0 ] / nat [ 0 ] elif filter_type == 4 : nat = numpy . zeros ( 2 , float ) nat [ 0 ] = ( 1.0 / ( 2.0 * new_freq ) * ( passb [ 0 ] - passb [ 1 ] ) + sqrt ( ( passb [ 1 ] - passb [ 0 ] ) ** 2 / ( 4.0 * new_freq ** 2 ) + passb [ 1 ] * passb [ 0 ] ) ) nat [ 1 ] = passb [ 0 ] * passb [ 1 ] / nat [ 0 ] if not analog : wn = ( 2.0 / pi ) * arctan ( nat ) else : wn = nat if len ( wn ) == 1 : wn = wn [ 0 ] return ord , wn