b, a = map(atleast_1d, (b, a))<EOL>if len(a.shape) != <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if len(b.shape) > <NUM_LIT:2>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>if len(b.shape) == <NUM_LIT:1>:<EOL><INDENT>b = asarray([b], b.dtype.char)<EOL><DEDENT>while a[<NUM_LIT:0>] == <NUM_LIT:0.0> and len(a) > <NUM_LIT:1>:<EOL><INDENT>a = a[<NUM_LIT:1>:]<EOL><DEDENT>outb = b * (<NUM_LIT:1.0>) / a[<NUM_LIT:0>]<EOL>outa = a * (<NUM_LIT:1.0>) / a[<NUM_LIT:0>]<EOL>if allclose(<NUM_LIT:0>, outb[:, <NUM_LIT:0>], atol=<NUM_LIT>):<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>", BadCoefficients)<EOL>while allclose(<NUM_LIT:0>, outb[:, <NUM_LIT:0>], atol=<NUM_LIT>) and (outb.shape[-<NUM_LIT:1>] > <NUM_LIT:1>):<EOL><INDENT>outb = outb[:, <NUM_LIT:1>:]<EOL><DEDENT><DEDENT>if outb.shape[<NUM_LIT:0>] == <NUM_LIT:1>:<EOL><INDENT>outb = outb[<NUM_LIT:0>]<EOL><DEDENT>return outb, outa<EOL>

Normalize polynomial representation of a transfer function.

    If values of `b` are too close to 0, they are removed. In that case, a
    BadCoefficients warning is emitted.


a, b = map(atleast_1d, (a, b))<EOL>try:<EOL><INDENT>wo = float(wo)<EOL><DEDENT>except TypeError:<EOL><INDENT>wo = float(wo[<NUM_LIT:0>])<EOL><DEDENT>d = len(a)<EOL>n = len(b)<EOL>M = max((d, n))<EOL>pwo = pow(wo, numpy.arange(M - <NUM_LIT:1>, -<NUM_LIT:1>, -<NUM_LIT:1>))<EOL>start1 = max((n - d, <NUM_LIT:0>))<EOL>start2 = max((d - n, <NUM_LIT:0>))<EOL>b = b * pwo[start1] / pwo[start2:]<EOL>a = a * pwo[start1] / pwo[start1:]<EOL>return normalize(b, a)<EOL>

Transform a lowpass filter prototype to a different frequency.

Return an analog low-pass filter with cutoff frequency `wo`
from an analog low-pass filter prototype with unity cutoff frequency, in
transfer function ('ba') representation.


a, b = map(atleast_1d, (a, b))<EOL>try:<EOL><INDENT>wo = float(wo)<EOL><DEDENT>except TypeError:<EOL><INDENT>wo = float(wo[<NUM_LIT:0>])<EOL><DEDENT>d = len(a)<EOL>n = len(b)<EOL>if wo != <NUM_LIT:1>:<EOL><INDENT>pwo = pow(wo, numpy.arange(max((d, n))))<EOL><DEDENT>else:<EOL><INDENT>pwo = numpy.ones(max((d, n)), b.dtype.char)<EOL><DEDENT>if d >= n:<EOL><INDENT>outa = a[::-<NUM_LIT:1>] * pwo<EOL>outb = resize(b, (d,))<EOL>outb[n:] = <NUM_LIT:0.0><EOL>outb[:n] = b[::-<NUM_LIT:1>] * pwo[:n]<EOL><DEDENT>else:<EOL><INDENT>outb = b[::-<NUM_LIT:1>] * pwo<EOL>outa = resize(a, (n,))<EOL>outa[d:] = <NUM_LIT:0.0><EOL>outa[:d] = a[::-<NUM_LIT:1>] * pwo[:d]<EOL><DEDENT>return normalize(outb, outa)<EOL>

Transform a lowpass filter prototype to a highpass filter.

Return an analog high-pass filter with cutoff frequency `wo`
from an analog low-pass filter prototype with unity cutoff frequency, in
transfer function ('ba') representation.


def lp2bp(b, a, wo=<NUM_LIT:1.0>, bw=<NUM_LIT:1.0>):

a, b = map(atleast_1d, (a, b))<EOL>D = len(a) - <NUM_LIT:1><EOL>N = len(b) - <NUM_LIT:1><EOL>artype = mintypecode((a, b))<EOL>ma = max([N, D])<EOL>Np = N + ma<EOL>Dp = D + ma<EOL>bprime = numpy.zeros(Np + <NUM_LIT:1>, artype)<EOL>aprime = numpy.zeros(Dp + <NUM_LIT:1>, artype)<EOL>wosq = wo * wo<EOL>for j in range(Np + <NUM_LIT:1>):<EOL><INDENT>val = <NUM_LIT:0.0><EOL>for i in range(<NUM_LIT:0>, N + <NUM_LIT:1>):<EOL><INDENT>for k in range(<NUM_LIT:0>, i + <NUM_LIT:1>):<EOL><INDENT>if ma - i + <NUM_LIT:2> * k == j:<EOL><INDENT>val += comb(i, k) * b[N - i] * (wosq) ** (i - k) / bw ** i<EOL><DEDENT><DEDENT><DEDENT>bprime[Np - j] = val<EOL><DEDENT>for j in range(Dp + <NUM_LIT:1>):<EOL><INDENT>val = <NUM_LIT:0.0><EOL>for i in range(<NUM_LIT:0>, D + <NUM_LIT:1>):<EOL><INDENT>for k in range(<NUM_LIT:0>, i + <NUM_LIT:1>):<EOL><INDENT>if ma - i + <NUM_LIT:2> * k == j:<EOL><INDENT>val += comb(i, k) * a[D - i] * (wosq) ** (i - k) / bw ** i<EOL><DEDENT><DEDENT><DEDENT>aprime[Dp - j] = val<EOL><DEDENT>return normalize(bprime, aprime)<EOL>

Transform a lowpass filter prototype to a bandpass filter.

Return an analog band-pass filter with center frequency `wo` and
bandwidth `bw` from an analog low-pass filter prototype with unity
cutoff frequency, in transfer function ('ba') representation.


def lp2bs(b, a, wo=<NUM_LIT:1.0>, bw=<NUM_LIT:1.0>):

a, b = map(atleast_1d, (a, b))<EOL>D = len(a) - <NUM_LIT:1><EOL>N = len(b) - <NUM_LIT:1><EOL>artype = mintypecode((a, b))<EOL>M = max([N, D])<EOL>Np = M + M<EOL>Dp = M + M<EOL>bprime = numpy.zeros(Np + <NUM_LIT:1>, artype)<EOL>aprime = numpy.zeros(Dp + <NUM_LIT:1>, artype)<EOL>wosq = wo * wo<EOL>for j in range(Np + <NUM_LIT:1>):<EOL><INDENT>val = <NUM_LIT:0.0><EOL>for i in range(<NUM_LIT:0>, N + <NUM_LIT:1>):<EOL><INDENT>for k in range(<NUM_LIT:0>, M - i + <NUM_LIT:1>):<EOL><INDENT>if i + <NUM_LIT:2> * k == j:<EOL><INDENT>val += (comb(M - i, k) * b[N - i] *<EOL>(wosq) ** (M - i - k) * bw ** i)<EOL><DEDENT><DEDENT><DEDENT>bprime[Np - j] = val<EOL><DEDENT>for j in range(Dp + <NUM_LIT:1>):<EOL><INDENT>val = <NUM_LIT:0.0><EOL>for i in range(<NUM_LIT:0>, D + <NUM_LIT:1>):<EOL><INDENT>for k in range(<NUM_LIT:0>, M - i + <NUM_LIT:1>):<EOL><INDENT>if i + <NUM_LIT:2> * k == j:<EOL><INDENT>val += (comb(M - i, k) * a[D - i] *<EOL>(wosq) ** (M - i - k) * bw ** i)<EOL><DEDENT><DEDENT><DEDENT>aprime[Dp - j] = val<EOL><DEDENT>return normalize(bprime, aprime)<EOL>

Transform a lowpass filter prototype to a bandstop filter.

Return an analog band-stop filter with center frequency `wo` and
bandwidth `bw` from an analog low-pass filter prototype with unity
cutoff frequency, in transfer function ('ba') representation.


fs = float(fs)<EOL>a, b = map(atleast_1d, (a, b))<EOL>D = len(a) - <NUM_LIT:1><EOL>N = len(b) - <NUM_LIT:1><EOL>artype = float<EOL>M = max([N, D])<EOL>Np = M<EOL>Dp = M<EOL>bprime = numpy.zeros(Np + <NUM_LIT:1>, artype)<EOL>aprime = numpy.zeros(Dp + <NUM_LIT:1>, artype)<EOL>for j in range(Np + <NUM_LIT:1>):<EOL><INDENT>val = <NUM_LIT:0.0><EOL>for i in range(N + <NUM_LIT:1>):<EOL><INDENT>for k in range(i + <NUM_LIT:1>):<EOL><INDENT>for l in range(M - i + <NUM_LIT:1>):<EOL><INDENT>if k + l == j:<EOL><INDENT>val += (comb(i, k) * comb(M - i, l) * b[N - i] *<EOL>pow(<NUM_LIT:2> * fs, i) * (-<NUM_LIT:1>) ** k)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>bprime[j] = real(val)<EOL><DEDENT>for j in range(Dp + <NUM_LIT:1>):<EOL><INDENT>val = <NUM_LIT:0.0><EOL>for i in range(D + <NUM_LIT:1>):<EOL><INDENT>for k in range(i + <NUM_LIT:1>):<EOL><INDENT>for l in range(M - i + <NUM_LIT:1>):<EOL><INDENT>if k + l == j:<EOL><INDENT>val += (comb(i, k) * comb(M - i, l) * a[D - i] *<EOL>pow(<NUM_LIT:2> * fs, i) * (-<NUM_LIT:1>) ** k)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>aprime[j] = real(val)<EOL><DEDENT>return normalize(bprime, aprime)<EOL>

Return a digital filter from an analog one using a bilinear transform.

    The bilinear transform substitutes ``(z-1) / (z+1)`` for ``s``.


def iirdesign(wp, ws, gpass, gstop, analog=False, ftype='<STR_LIT>', output='<STR_LIT>'):

try:<EOL><INDENT>ordfunc = filter_dict[ftype][<NUM_LIT:1>]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % ftype)<EOL><DEDENT>except IndexError:<EOL><INDENT>raise ValueError(("<STR_LIT>"<EOL>"<STR_LIT>") % ftype)<EOL><DEDENT>wp = atleast_1d(wp)<EOL>ws = atleast_1d(ws)<EOL>band_type = <NUM_LIT:2> * (len(wp) - <NUM_LIT:1>)<EOL>band_type += <NUM_LIT:1><EOL>if wp[<NUM_LIT:0>] >= ws[<NUM_LIT:0>]:<EOL><INDENT>band_type += <NUM_LIT:1><EOL><DEDENT>btype = {<NUM_LIT:1>: '<STR_LIT>', <NUM_LIT:2>: '<STR_LIT>',<EOL><NUM_LIT:3>: '<STR_LIT>', <NUM_LIT:4>: '<STR_LIT>'}[band_type]<EOL>N, Wn = ordfunc(wp, ws, gpass, gstop, analog=analog)<EOL>return iirfilter(N, Wn, rp=gpass, rs=gstop, analog=analog, btype=btype,<EOL>ftype=ftype, output=output)<EOL>

Complete IIR digital and analog filter design.

    Given passband and stopband frequencies and gains, construct an analog or
    digital IIR filter of minimum order for a given basic type.  Return the
    output in numerator, denominator ('ba') or pole-zero ('zpk') form.

    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.
    ftype : str, optional
        The type of IIR filter to design:

            - Butterworth   : 'butter'
            - Chebyshev I   : 'cheby1'
            - Chebyshev II  : 'cheby2'
            - Cauer/elliptic: 'ellip'
            - Bessel/Thomson: 'bessel'

    output : {'ba', 'zpk'}, optional
        Type of output:  numerator/denominator ('ba') or pole-zero ('zpk').
        Default is 'ba'.

    Returns
    -------
    b, a : ndarray, ndarray
        Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
        Only returned if ``output='ba'``.
    z, p, k : ndarray, ndarray, float
        Zeros, poles, and system gain of the IIR filter transfer
        function.  Only returned if ``output='zpk'``.

    See Also
    --------
    butter : Filter design using order and critical points
    cheby1, cheby2, ellip, bessel
    buttord : Find order and critical points from passband and stopband spec
    cheb1ord, cheb2ord, ellipord
    iirfilter : General filter design using order and critical frequencies


def iirfilter(N, Wn, rp=None, rs=None, btype='<STR_LIT>', analog=False,<EOL>ftype='<STR_LIT>', output='<STR_LIT>'):

ftype, btype, output = [x.lower() for x in (ftype, btype, output)]<EOL>Wn = asarray(Wn)<EOL>try:<EOL><INDENT>btype = band_dict[btype]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % btype)<EOL><DEDENT>try:<EOL><INDENT>typefunc = filter_dict[ftype][<NUM_LIT:0>]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError("<STR_LIT>" % ftype)<EOL><DEDENT>if output not in ['<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>raise ValueError("<STR_LIT>" % output)<EOL><DEDENT>if rp is not None and rp < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if rs is not None and rs < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if typefunc in [buttap, besselap]:<EOL><INDENT>z, p, k = typefunc(N)<EOL><DEDENT>elif typefunc == cheb1ap:<EOL><INDENT>if rp is None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>z, p, k = typefunc(N, rp)<EOL><DEDENT>elif typefunc == cheb2ap:<EOL><INDENT>if rs is None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>z, p, k = typefunc(N, rs)<EOL><DEDENT>elif typefunc == ellipap:<EOL><INDENT>if rs is None or rp is None:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>z, p, k = typefunc(N, rp, rs)<EOL><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>" % ftype)<EOL><DEDENT>if not analog:<EOL><INDENT>if numpy.any(Wn < <NUM_LIT:0>) or numpy.any(Wn > <NUM_LIT:1>):<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>fs = <NUM_LIT><EOL>warped = <NUM_LIT:2> * fs * tan(pi * Wn / fs)<EOL><DEDENT>else:<EOL><INDENT>warped = Wn<EOL><DEDENT>if btype in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>if numpy.size(Wn) != <NUM_LIT:1>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if btype == '<STR_LIT>':<EOL><INDENT>z, p, k = _zpklp2lp(z, p, k, wo=warped)<EOL><DEDENT>elif btype == '<STR_LIT>':<EOL><INDENT>z, p, k = _zpklp2hp(z, p, k, wo=warped)<EOL><DEDENT><DEDENT>elif btype in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>bw = warped[<NUM_LIT:1>] - warped[<NUM_LIT:0>]<EOL>wo = sqrt(warped[<NUM_LIT:0>] * warped[<NUM_LIT:1>])<EOL><DEDENT>except IndexError:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>if btype == '<STR_LIT>':<EOL><INDENT>z, p, k = _zpklp2bp(z, p, k, wo=wo, bw=bw)<EOL><DEDENT>elif btype == '<STR_LIT>':<EOL><INDENT>z, p, k = _zpklp2bs(z, p, k, wo=wo, bw=bw)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise NotImplementedError("<STR_LIT>" % btype)<EOL><DEDENT>if not analog:<EOL><INDENT>z, p, k = _zpkbilinear(z, p, k, fs=fs)<EOL><DEDENT>if output == '<STR_LIT>':<EOL><INDENT>return z, p, k<EOL><DEDENT>elif output == '<STR_LIT>':<EOL><INDENT>return zpk2tf(z, p, k)<EOL><DEDENT>

IIR digital and analog filter design given order and critical points.

Design an Nth order digital or analog filter and return the filter
coefficients in (B,A) (numerator, denominator) or (Z,P,K) form.

Parameters
----------
N : int
    The order of the filter.
Wn : array_like
    A scalar or length-2 sequence giving the critical frequencies.
    For digital filters, `Wn` is normalized from 0 to 1, where 1 is the
    Nyquist frequency, pi radians/sample.  (`Wn` is thus in
    half-cycles / sample.)
    For analog filters, `Wn` is an angular frequency (e.g. rad/s).
rp : float, optional
    For Chebyshev and elliptic filters, provides the maximum ripple
    in the passband. (dB)
rs : float, optional
    For Chebyshev and elliptic filters, provides the minimum attenuation
    in the stop band. (dB)
btype : {'bandpass', 'lowpass', 'highpass', 'bandstop'}, optional
    The type of filter.  Default is 'bandpass'.
analog : bool, optional
    When True, return an analog filter, otherwise a digital filter is
    returned.
ftype : str, optional
    The type of IIR filter to design:

        - Butterworth   : 'butter'
        - Chebyshev I   : 'cheby1'
        - Chebyshev II  : 'cheby2'
        - Cauer/elliptic: 'ellip'
        - Bessel/Thomson: 'bessel'

output : {'ba', 'zpk'}, optional
    Type of output:  numerator/denominator ('ba') or pole-zero ('zpk').
    Default is 'ba'.

See Also
--------
butter : Filter design using order and critical points
cheby1, cheby2, ellip, bessel
buttord : Find order and critical points from passband and stopband spec
cheb1ord, cheb2ord, ellipord
iirdesign : General filter design using passband and stopband spec

Examples
--------
Generate a 17th-order Chebyshev II bandpass filter and plot the frequency
response:

>>> from scipy import signal
>>> import matplotlib.pyplot as plt

>>> b, a = signal.iirfilter(17, [50, 200], rs=60, btype='band',
...                         analog=True, ftype='cheby2')
>>> w, h = signal.freqs(b, a, 1000)
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111)
>>> ax.semilogx(w, 20 * np.log10(abs(h)))
>>> ax.set_title('Chebyshev Type II bandpass frequency response')
>>> ax.set_xlabel('Frequency [radians / second]')
>>> ax.set_ylabel('Amplitude [dB]')
>>> ax.axis((10, 1000, -100, 10))
>>> ax.grid(which='both', axis='both')
>>> plt.show()


degree = len(p) - len(z)<EOL>if degree < <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>return degree<EOL><DEDENT>

Return relative degree of transfer function from zeros and poles


z = atleast_1d(z)<EOL>p = atleast_1d(p)<EOL>degree = _relative_degree(z, p)<EOL>fs2 = <NUM_LIT:2>*fs<EOL>z_z = (fs2 + z) / (fs2 - z)<EOL>p_z = (fs2 + p) / (fs2 - p)<EOL>z_z = append(z_z, -ones(degree))<EOL>k_z = k * real(prod(fs2 - z) / prod(fs2 - p))<EOL>return z_z, p_z, k_z<EOL>

Return a digital filter from an analog one using a bilinear transform.

Transform a set of poles and zeros from the analog s-plane to the digital
z-plane using Tustin's method, which substitutes ``(z-1) / (z+1)`` for
``s``, maintaining the shape of the frequency response.

Parameters
----------
z : ndarray
    Zeros of the analog IIR filter transfer function.
p : ndarray
    Poles of the analog IIR filter transfer function.
k : float
    System gain of the analog IIR filter transfer function.
fs : float
    Sample rate, as ordinary frequency (e.g. hertz). No prewarping is
    done in this function.

Returns
-------
z : ndarray
    Zeros of the transformed digital filter transfer function.
p : ndarray
    Poles of the transformed digital filter transfer function.
k : float
    System gain of the transformed digital filter.


def _zpklp2lp(z, p, k, wo=<NUM_LIT:1.0>):

z = atleast_1d(z)<EOL>p = atleast_1d(p)<EOL>wo = float(wo)  <EOL>degree = _relative_degree(z, p)<EOL>z_lp = wo * z<EOL>p_lp = wo * p<EOL>k_lp = k * wo**degree<EOL>return z_lp, p_lp, k_lp<EOL>

Transform a lowpass filter prototype to a different frequency.

Return an analog low-pass filter with cutoff frequency `wo`
from an analog low-pass filter prototype with unity cutoff frequency,
using zeros, poles, and gain ('zpk') representation.

Parameters
----------
z : ndarray
    Zeros of the analog IIR filter transfer function.
p : ndarray
    Poles of the analog IIR filter transfer function.
k : float
    System gain of the analog IIR filter transfer function.
wo : float
    Desired cutoff, as angular frequency (e.g. rad/s).
    Defaults to no change.

Returns
-------
z : ndarray
    Zeros of the transformed low-pass filter transfer function.
p : ndarray
    Poles of the transformed low-pass filter transfer function.
k : float
    System gain of the transformed low-pass filter.

Notes
-----
This is derived from the s-plane substitution

.. math:: s \rightarrow \frac{s}{\omega_0}


def _zpklp2hp(z, p, k, wo=<NUM_LIT:1.0>):

z = atleast_1d(z)<EOL>p = atleast_1d(p)<EOL>wo = float(wo)<EOL>degree = _relative_degree(z, p)<EOL>z_hp = wo / z<EOL>p_hp = wo / p<EOL>z_hp = append(z_hp, zeros(degree))<EOL>k_hp = k * real(prod(-z) / prod(-p))<EOL>return z_hp, p_hp, k_hp<EOL>

Transform a lowpass filter prototype to a highpass filter.

Return an analog high-pass filter with cutoff frequency `wo`
from an analog low-pass filter prototype with unity cutoff frequency,
using zeros, poles, and gain ('zpk') representation.

Parameters
----------
z : ndarray
    Zeros of the analog IIR filter transfer function.
p : ndarray
    Poles of the analog IIR filter transfer function.
k : float
    System gain of the analog IIR filter transfer function.
wo : float
    Desired cutoff, as angular frequency (e.g. rad/s).
    Defaults to no change.

Returns
-------
z : ndarray
    Zeros of the transformed high-pass filter transfer function.
p : ndarray
    Poles of the transformed high-pass filter transfer function.
k : float
    System gain of the transformed high-pass filter.

Notes
-----
This is derived from the s-plane substitution

.. math:: s \rightarrow \frac{\omega_0}{s}

This maintains symmetry of the lowpass and highpass responses on a
logarithmic scale.


def _zpklp2bp(z, p, k, wo=<NUM_LIT:1.0>, bw=<NUM_LIT:1.0>):

z = atleast_1d(z)<EOL>p = atleast_1d(p)<EOL>wo = float(wo)<EOL>bw = float(bw)<EOL>degree = _relative_degree(z, p)<EOL>z_lp = z * bw/<NUM_LIT:2><EOL>p_lp = p * bw/<NUM_LIT:2><EOL>z_lp = z_lp.astype(complex)<EOL>p_lp = p_lp.astype(complex)<EOL>z_bp = concatenate((z_lp + sqrt(z_lp**<NUM_LIT:2> - wo**<NUM_LIT:2>),<EOL>z_lp - sqrt(z_lp**<NUM_LIT:2> - wo**<NUM_LIT:2>)))<EOL>p_bp = concatenate((p_lp + sqrt(p_lp**<NUM_LIT:2> - wo**<NUM_LIT:2>),<EOL>p_lp - sqrt(p_lp**<NUM_LIT:2> - wo**<NUM_LIT:2>)))<EOL>z_bp = append(z_bp, zeros(degree))<EOL>k_bp = k * bw**degree<EOL>return z_bp, p_bp, k_bp<EOL>

Transform a lowpass filter prototype to a bandpass filter.

Return an analog band-pass filter with center frequency `wo` and
bandwidth `bw` from an analog low-pass filter prototype with unity
cutoff frequency, using zeros, poles, and gain ('zpk') representation.

Parameters
----------
z : ndarray
    Zeros of the analog IIR filter transfer function.
p : ndarray
    Poles of the analog IIR filter transfer function.
k : float
    System gain of the analog IIR filter transfer function.
wo : float
    Desired passband center, as angular frequency (e.g. rad/s).
    Defaults to no change.
bw : float
    Desired passband width, as angular frequency (e.g. rad/s).
    Defaults to 1.

Returns
-------
z : ndarray
    Zeros of the transformed band-pass filter transfer function.
p : ndarray
    Poles of the transformed band-pass filter transfer function.
k : float
    System gain of the transformed band-pass filter.

Notes
-----
This is derived from the s-plane substitution

.. math:: s \rightarrow \frac{s^2 + {\omega_0}^2}{s \cdot \mathrm{BW}}

This is the "wideband" transformation, producing a passband with
geometric (log frequency) symmetry about `wo`.


def _zpklp2bs(z, p, k, wo=<NUM_LIT:1.0>, bw=<NUM_LIT:1.0>):

z = atleast_1d(z)<EOL>p = atleast_1d(p)<EOL>wo = float(wo)<EOL>bw = float(bw)<EOL>degree = _relative_degree(z, p)<EOL>z_hp = (bw/<NUM_LIT:2>) / z<EOL>p_hp = (bw/<NUM_LIT:2>) / p<EOL>z_hp = z_hp.astype(complex)<EOL>p_hp = p_hp.astype(complex)<EOL>z_bs = concatenate((z_hp + sqrt(z_hp**<NUM_LIT:2> - wo**<NUM_LIT:2>),<EOL>z_hp - sqrt(z_hp**<NUM_LIT:2> - wo**<NUM_LIT:2>)))<EOL>p_bs = concatenate((p_hp + sqrt(p_hp**<NUM_LIT:2> - wo**<NUM_LIT:2>),<EOL>p_hp - sqrt(p_hp**<NUM_LIT:2> - wo**<NUM_LIT:2>)))<EOL>z_bs = append(z_bs, +<NUM_LIT>*wo * ones(degree))<EOL>z_bs = append(z_bs, -<NUM_LIT>*wo * ones(degree))<EOL>k_bs = k * real(prod(-z) / prod(-p))<EOL>return z_bs, p_bs, k_bs<EOL>

Transform a lowpass filter prototype to a bandstop filter.

Return an analog band-stop filter with center frequency `wo` and
stopband width `bw` from an analog low-pass filter prototype with unity
cutoff frequency, using zeros, poles, and gain ('zpk') representation.

Parameters
----------
z : ndarray
    Zeros of the analog IIR filter transfer function.
p : ndarray
    Poles of the analog IIR filter transfer function.
k : float
    System gain of the analog IIR filter transfer function.
wo : float
    Desired stopband center, as angular frequency (e.g. rad/s).
    Defaults to no change.
bw : float
    Desired stopband width, as angular frequency (e.g. rad/s).
    Defaults to 1.

Returns
-------
z : ndarray
    Zeros of the transformed band-stop filter transfer function.
p : ndarray
    Poles of the transformed band-stop filter transfer function.
k : float
    System gain of the transformed band-stop filter.

Notes
-----
This is derived from the s-plane substitution

.. math:: s \rightarrow \frac{s \cdot \mathrm{BW}}{s^2 + {\omega_0}^2}

This is the "wideband" transformation, producing a stopband with
geometric (log frequency) symmetry about `wo`.


def butter(N, Wn, btype='<STR_LIT>', analog=False, output='<STR_LIT>'):

return iirfilter(N, Wn, btype=btype, analog=analog,<EOL>output=output, ftype='<STR_LIT>')<EOL>

Butterworth digital and analog filter design.

Design an Nth order digital or analog Butterworth filter and return
the filter coefficients in (B,A) or (Z,P,K) form.

Parameters
----------
N : int
    The order of the filter.
Wn : array_like
    A scalar or length-2 sequence giving the critical frequencies.
    For a Butterworth filter, this is the point at which the gain
    drops to 1/sqrt(2) that of the passband (the "-3 dB point").
    For digital filters, `Wn` is normalized from 0 to 1, where 1 is the
    Nyquist frequency, pi radians/sample.  (`Wn` is thus in
    half-cycles / sample.)
    For analog filters, `Wn` is an angular frequency (e.g. rad/s).
btype : {'lowpass', 'highpass', 'bandpass', 'bandstop'}, optional
    The type of filter.  Default is 'lowpass'.
analog : bool, optional
    When True, return an analog filter, otherwise a digital filter is
    returned.
output : {'ba', 'zpk'}, optional
    Type of output:  numerator/denominator ('ba') or pole-zero ('zpk').
    Default is 'ba'.

Returns
-------
b, a : ndarray, ndarray
    Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
    Only returned if ``output='ba'``.
z, p, k : ndarray, ndarray, float
    Zeros, poles, and system gain of the IIR filter transfer
    function.  Only returned if ``output='zpk'``.

See also
--------
buttord

Notes
-----
The Butterworth filter has maximally flat frequency response in the
passband.

Examples
--------
Plot the filter's frequency response, showing the critical points:

>>> from scipy import signal
>>> import matplotlib.pyplot as plt

>>> b, a = signal.butter(4, 100, 'low', analog=True)
>>> w, h = signal.freqs(b, a)
>>> plt.semilogx(w, 20 * np.log10(abs(h)))
>>> plt.title('Butterworth filter frequency response')
>>> plt.xlabel('Frequency [radians / second]')
>>> plt.ylabel('Amplitude [dB]')
>>> plt.margins(0, 0.1)
>>> plt.grid(which='both', axis='both')
>>> plt.axvline(100, color='green') # cutoff frequency
>>> plt.show()


def cheby1(N, rp, Wn, btype='<STR_LIT>', analog=False, output='<STR_LIT>'):

return iirfilter(N, Wn, rp=rp, btype=btype, analog=analog,<EOL>output=output, ftype='<STR_LIT>')<EOL>

Chebyshev type I digital and analog filter design.

Design an Nth order digital or analog Chebyshev type I filter and
return the filter coefficients in (B,A) or (Z,P,K) form.

Parameters
----------
N : int
    The order of the filter.
rp : float
    The maximum ripple allowed below unity gain in the passband.
    Specified in decibels, as a positive number.
Wn : array_like
    A scalar or length-2 sequence giving the critical frequencies.
    For Type I filters, this is the point in the transition band at which
    the gain first drops below -`rp`.
    For digital filters, `Wn` is normalized from 0 to 1, where 1 is the
    Nyquist frequency, pi radians/sample.  (`Wn` is thus in
    half-cycles / sample.)
    For analog filters, `Wn` is an angular frequency (e.g. rad/s).
btype : {'lowpass', 'highpass', 'bandpass', 'bandstop'}, optional
    The type of filter.  Default is 'lowpass'.
analog : bool, optional
    When True, return an analog filter, otherwise a digital filter is
    returned.
output : {'ba', 'zpk'}, optional
    Type of output:  numerator/denominator ('ba') or pole-zero ('zpk').
    Default is 'ba'.

Returns
-------
b, a : ndarray, ndarray
    Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
    Only returned if ``output='ba'``.
z, p, k : ndarray, ndarray, float
    Zeros, poles, and system gain of the IIR filter transfer
    function.  Only returned if ``output='zpk'``.

See also
--------
cheb1ord

Notes
-----
The Chebyshev type I filter maximizes the rate of cutoff between the
frequency response's passband and stopband, at the expense of ripple in
the passband and increased ringing in the step response.

Type I filters roll off faster than Type II (`cheby2`), but Type II
filters do not have any ripple in the passband.

The equiripple passband has N maxima or minima (for example, a
5th-order filter has 3 maxima and 2 minima).  Consequently, the DC gain is
unity for odd-order filters, or -rp dB for even-order filters.

Examples
--------
Plot the filter's frequency response, showing the critical points:

>>> from scipy import signal
>>> import matplotlib.pyplot as plt

>>> b, a = signal.cheby1(4, 5, 100, 'low', analog=True)
>>> w, h = signal.freqs(b, a)
>>> plt.semilogx(w, 20 * np.log10(abs(h)))
>>> plt.title('Chebyshev Type I frequency response (rp=5)')
>>> plt.xlabel('Frequency [radians / second]')
>>> plt.ylabel('Amplitude [dB]')
>>> plt.margins(0, 0.1)
>>> plt.grid(which='both', axis='both')
>>> plt.axvline(100, color='green') # cutoff frequency
>>> plt.axhline(-5, color='green') # rp
>>> plt.show()


def cheby2(N, rs, Wn, btype='<STR_LIT>', analog=False, output='<STR_LIT>'):

return iirfilter(N, Wn, rs=rs, btype=btype, analog=analog,<EOL>output=output, ftype='<STR_LIT>')<EOL>

Chebyshev type II digital and analog filter design.

Design an Nth order digital or analog Chebyshev type II filter and
return the filter coefficients in (B,A) or (Z,P,K) form.

Parameters
----------
N : int
    The order of the filter.
rs : float
    The minimum attenuation required in the stop band.
    Specified in decibels, as a positive number.
Wn : array_like
    A scalar or length-2 sequence giving the critical frequencies.
    For Type II filters, this is the point in the transition band at which
    the gain first reaches -`rs`.
    For digital filters, `Wn` is normalized from 0 to 1, where 1 is the
    Nyquist frequency, pi radians/sample.  (`Wn` is thus in
    half-cycles / sample.)
    For analog filters, `Wn` is an angular frequency (e.g. rad/s).
btype : {'lowpass', 'highpass', 'bandpass', 'bandstop'}, optional
    The type of filter.  Default is 'lowpass'.
analog : bool, optional
    When True, return an analog filter, otherwise a digital filter is
    returned.
output : {'ba', 'zpk'}, optional
    Type of output:  numerator/denominator ('ba') or pole-zero ('zpk').
    Default is 'ba'.

Returns
-------
b, a : ndarray, ndarray
    Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
    Only returned if ``output='ba'``.
z, p, k : ndarray, ndarray, float
    Zeros, poles, and system gain of the IIR filter transfer
    function.  Only returned if ``output='zpk'``.

See also
--------
cheb2ord

Notes
-----
The Chebyshev type II filter maximizes the rate of cutoff between the
frequency response's passband and stopband, at the expense of ripple in
the stopband and increased ringing in the step response.

Type II filters do not roll off as fast as Type I (`cheby1`).

Examples
--------
Plot the filter's frequency response, showing the critical points:

>>> from scipy import signal
>>> import matplotlib.pyplot as plt

>>> b, a = signal.cheby2(4, 40, 100, 'low', analog=True)
>>> w, h = signal.freqs(b, a)
>>> plt.semilogx(w, 20 * np.log10(abs(h)))
>>> plt.title('Chebyshev Type II frequency response (rs=40)')
>>> plt.xlabel('Frequency [radians / second]')
>>> plt.ylabel('Amplitude [dB]')
>>> plt.margins(0, 0.1)
>>> plt.grid(which='both', axis='both')
>>> plt.axvline(100, color='green') # cutoff frequency
>>> plt.axhline(-40, color='green') # rs
>>> plt.show()


def ellip(N, rp, rs, Wn, btype='<STR_LIT>', analog=False, output='<STR_LIT>'):

return iirfilter(N, Wn, rs=rs, rp=rp, btype=btype, analog=analog,<EOL>output=output, ftype='<STR_LIT>')<EOL>

Elliptic (Cauer) digital and analog filter design.

Design an Nth order digital or analog elliptic filter and return
the filter coefficients in (B,A) or (Z,P,K) form.

Parameters
----------
N : int
    The order of the filter.
rp : float
    The maximum ripple allowed below unity gain in the passband.
    Specified in decibels, as a positive number.
rs : float
    The minimum attenuation required in the stop band.
    Specified in decibels, as a positive number.
Wn : array_like
    A scalar or length-2 sequence giving the critical frequencies.
    For elliptic filters, this is the point in the transition band at
    which the gain first drops below -`rp`.
    For digital filters, `Wn` is normalized from 0 to 1, where 1 is the
    Nyquist frequency, pi radians/sample.  (`Wn` is thus in
    half-cycles / sample.)
    For analog filters, `Wn` is an angular frequency (e.g. rad/s).
btype : {'lowpass', 'highpass', 'bandpass', 'bandstop'}, optional
    The type of filter.  Default is 'lowpass'.
analog : bool, optional
    When True, return an analog filter, otherwise a digital filter is
    returned.
output : {'ba', 'zpk'}, optional
    Type of output:  numerator/denominator ('ba') or pole-zero ('zpk').
    Default is 'ba'.

Returns
-------
b, a : ndarray, ndarray
    Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
    Only returned if ``output='ba'``.
z, p, k : ndarray, ndarray, float
    Zeros, poles, and system gain of the IIR filter transfer
    function.  Only returned if ``output='zpk'``.

See also
--------
ellipord

Notes
-----
Also known as Cauer or Zolotarev filters, the elliptical filter maximizes
the rate of transition between the frequency response's passband and
stopband, at the expense of ripple in both, and increased ringing in the
step response.

As `rp` approaches 0, the elliptical filter becomes a Chebyshev
type II filter (`cheby2`).  As `rs` approaches 0, it becomes a Chebyshev
type I filter (`cheby1`).  As both approach 0, it becomes a Butterworth
filter (`butter`).

The equiripple passband has N maxima or minima (for example, a
5th-order filter has 3 maxima and 2 minima).  Consequently, the DC gain is
unity for odd-order filters, or -rp dB for even-order filters.

Examples
--------
Plot the filter's frequency response, showing the critical points:

>>> from scipy import signal
>>> import matplotlib.pyplot as plt

>>> b, a = signal.ellip(4, 5, 40, 100, 'low', analog=True)
>>> w, h = signal.freqs(b, a)
>>> plt.semilogx(w, 20 * np.log10(abs(h)))
>>> plt.title('Elliptic filter frequency response (rp=5, rs=40)')
>>> plt.xlabel('Frequency [radians / second]')
>>> plt.ylabel('Amplitude [dB]')
>>> plt.margins(0, 0.1)
>>> plt.grid(which='both', axis='both')
>>> plt.axvline(100, color='green') # cutoff frequency
>>> plt.axhline(-40, color='green') # rs
>>> plt.axhline(-5, color='green') # rp
>>> plt.show()


def bessel(N, Wn, btype='<STR_LIT>', analog=False, output='<STR_LIT>'):

Bessel/Thomson digital and analog filter design.

    Design an Nth order digital or analog Bessel filter and return the
    filter coefficients in (B,A) or (Z,P,K) form.

    Parameters
    ----------
    N : int
        The order of the filter.
    Wn : array_like
        A scalar or length-2 sequence giving the critical frequencies.
        For a Bessel filter, this is defined as the point at which the
        asymptotes of the response are the same as a Butterworth filter of
        the same order.
        For digital filters, `Wn` is normalized from 0 to 1, where 1 is the
        Nyquist frequency, pi radians/sample.  (`Wn` is thus in
        half-cycles / sample.)
        For analog filters, `Wn` is an angular frequency (e.g. rad/s).
    btype : {'lowpass', 'highpass', 'bandpass', 'bandstop'}, optional
        The type of filter.  Default is 'lowpass'.
    analog : bool, optional
        When True, return an analog filter, otherwise a digital filter is
        returned.
    output : {'ba', 'zpk'}, optional
        Type of output:  numerator/denominator ('ba') or pole-zero ('zpk').
        Default is 'ba'.

    Returns
    -------
    b, a : ndarray, ndarray
        Numerator (`b`) and denominator (`a`) polynomials of the IIR filter.
        Only returned if ``output='ba'``.
    z, p, k : ndarray, ndarray, float
        Zeros, poles, and system gain of the IIR filter transfer
        function.  Only returned if ``output='zpk'``.

    Notes
    -----
    Also known as a Thomson filter, the analog Bessel filter has maximally
    flat group delay and maximally linear phase response, with very little
    ringing in the step response.

    As order increases, the Bessel filter approaches a Gaussian filter.

    The digital Bessel filter is generated using the bilinear
    transform, which does not preserve the phase response of the analog
    filter. As such, it is only approximately correct at frequencies
    below about fs/4.  To get maximally flat group delay at higher
    frequencies, the analog Bessel filter must be transformed using
    phase-preserving techniques.

    For a given `Wn`, the lowpass and highpass filter have the same phase vs
    frequency curves; they are "phase-matched".

    Examples
    --------
    Plot the filter's frequency response, showing the flat group delay and
    the relationship to the Butterworth's cutoff frequency:

    >>> from scipy import signal
    >>> import matplotlib.pyplot as plt

    >>> b, a = signal.butter(4, 100, 'low', analog=True)
    >>> w, h = signal.freqs(b, a)
    >>> plt.plot(w, 20 * np.log10(np.abs(h)), color='silver', ls='dashed')
    >>> b, a = signal.bessel(4, 100, 'low', analog=True)
    >>> w, h = signal.freqs(b, a)
    >>> plt.semilogx(w, 20 * np.log10(np.abs(h)))
    >>> plt.title('Bessel filter frequency response (with Butterworth)')
    >>> plt.xlabel('Frequency [radians / second]')
    >>> plt.ylabel('Amplitude [dB]')
    >>> plt.margins(0, 0.1)
    >>> plt.grid(which='both', axis='both')
    >>> plt.axvline(100, color='green') # cutoff frequency
    >>> plt.show()

    >>> plt.figure()
    >>> plt.semilogx(w[1:], -np.diff(np.unwrap(np.angle(h)))/np.diff(w))
    >>> plt.title('Bessel filter group delay')
    >>> plt.xlabel('Frequency [radians / second]')
    >>> plt.ylabel('Group delay [seconds]')
    >>> plt.margins(0, 0.1)
    >>> plt.grid(which='both', axis='both')
    >>> plt.show()


def band_stop_obj(wp, ind, passb, stopb, gpass, gstop, type):

passbC = passb.copy()<EOL>passbC[ind] = wp<EOL>nat = (stopb * (passbC[<NUM_LIT:0>] - passbC[<NUM_LIT:1>]) /<EOL>(stopb ** <NUM_LIT:2> - passbC[<NUM_LIT:0>] * passbC[<NUM_LIT:1>]))<EOL>nat = min(abs(nat))<EOL>if type == '<STR_LIT>':<EOL><INDENT>GSTOP = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gstop))<EOL>GPASS = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gpass))<EOL>n = (log10((GSTOP - <NUM_LIT:1.0>) / (GPASS - <NUM_LIT:1.0>)) / (<NUM_LIT:2> * log10(nat)))<EOL><DEDENT>elif type == '<STR_LIT>':<EOL><INDENT>GSTOP = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gstop))<EOL>GPASS = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gpass))<EOL>n = arccosh(sqrt((GSTOP - <NUM_LIT:1.0>) / (GPASS - <NUM_LIT:1.0>))) / arccosh(nat)<EOL><DEDENT>elif type == '<STR_LIT>':<EOL><INDENT>GSTOP = <NUM_LIT:10> ** (<NUM_LIT:0.1> * gstop)<EOL>GPASS = <NUM_LIT:10> ** (<NUM_LIT:0.1> * gpass)<EOL>arg1 = sqrt((GPASS - <NUM_LIT:1.0>) / (GSTOP - <NUM_LIT:1.0>))<EOL>arg0 = <NUM_LIT:1.0> / nat<EOL>d0 = special.ellipk([arg0 ** <NUM_LIT:2>, <NUM_LIT:1> - arg0 ** <NUM_LIT:2>])<EOL>d1 = special.ellipk([arg1 ** <NUM_LIT:2>, <NUM_LIT:1> - arg1 ** <NUM_LIT:2>])<EOL>n = (d0[<NUM_LIT:0>] * d1[<NUM_LIT:1>] / (d0[<NUM_LIT:1>] * d1[<NUM_LIT:0>]))<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % type)<EOL><DEDENT>return n<EOL>

Band Stop Objective Function for order minimization.

Returns the non-integer order for an analog band stop filter.

Parameters
----------
wp : scalar
    Edge of passband `passb`.
ind : int, {0, 1}
    Index specifying which `passb` edge to vary (0 or 1).
passb : ndarray
    Two element sequence of fixed passband edges.
stopb : ndarray
    Two element sequence of fixed stopband edges.
gstop : float
    Amount of attenuation in stopband in dB.
gpass : float
    Amount of ripple in the passband in dB.
type : {'butter', 'cheby', 'ellip'}
    Type of filter.

Returns
-------
n : scalar
    Filter order (possibly non-integer).


def buttord(wp, ws, gpass, gstop, analog=False):

wp = atleast_1d(wp)<EOL>ws = atleast_1d(ws)<EOL>filter_type = <NUM_LIT:2> * (len(wp) - <NUM_LIT:1>)<EOL>filter_type += <NUM_LIT:1><EOL>if wp[<NUM_LIT:0>] >= ws[<NUM_LIT:0>]:<EOL><INDENT>filter_type += <NUM_LIT:1><EOL><DEDENT>if not analog:<EOL><INDENT>passb = tan(pi * wp / <NUM_LIT>)<EOL>stopb = tan(pi * ws / <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>passb = wp * <NUM_LIT:1.0><EOL>stopb = ws * <NUM_LIT:1.0><EOL><DEDENT>if filter_type == <NUM_LIT:1>:            <EOL><INDENT>nat = stopb / passb<EOL><DEDENT>elif filter_type == <NUM_LIT:2>:          <EOL><INDENT>nat = passb / stopb<EOL><DEDENT>elif filter_type == <NUM_LIT:3>:          <EOL><INDENT>wp0 = optimize.fminbound(band_stop_obj, passb[<NUM_LIT:0>], stopb[<NUM_LIT:0>] - <NUM_LIT>,<EOL>args=(<NUM_LIT:0>, passb, stopb, gpass, gstop,<EOL>'<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:0>] = wp0<EOL>wp1 = optimize.fminbound(band_stop_obj, stopb[<NUM_LIT:1>] + <NUM_LIT>, passb[<NUM_LIT:1>],<EOL>args=(<NUM_LIT:1>, passb, stopb, gpass, gstop,<EOL>'<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:1>] = wp1<EOL>nat = ((stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])) /<EOL>(stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]))<EOL><DEDENT>elif filter_type == <NUM_LIT:4>:          <EOL><INDENT>nat = ((stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]) /<EOL>(stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])))<EOL><DEDENT>nat = min(abs(nat))<EOL>GSTOP = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gstop))<EOL>GPASS = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gpass))<EOL>ord = int(ceil(log10((GSTOP - <NUM_LIT:1.0>) / (GPASS - <NUM_LIT:1.0>)) / (<NUM_LIT:2> * log10(nat))))<EOL>try:<EOL><INDENT>W0 = (GPASS - <NUM_LIT:1.0>) ** (-<NUM_LIT:1.0> / (<NUM_LIT> * ord))<EOL><DEDENT>except ZeroDivisionError:<EOL><INDENT>W0 = <NUM_LIT:1.0><EOL>print("<STR_LIT>")<EOL><DEDENT>if filter_type == <NUM_LIT:1>:  <EOL><INDENT>WN = W0 * passb<EOL><DEDENT>elif filter_type == <NUM_LIT:2>:  <EOL><INDENT>WN = passb / W0<EOL><DEDENT>elif filter_type == <NUM_LIT:3>:  <EOL><INDENT>WN = numpy.zeros(<NUM_LIT:2>, float)<EOL>discr = sqrt((passb[<NUM_LIT:1>] - passb[<NUM_LIT:0>]) ** <NUM_LIT:2> +<EOL><NUM_LIT:4> * W0 ** <NUM_LIT:2> * passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>])<EOL>WN[<NUM_LIT:0>] = ((passb[<NUM_LIT:1>] - passb[<NUM_LIT:0>]) + discr) / (<NUM_LIT:2> * W0)<EOL>WN[<NUM_LIT:1>] = ((passb[<NUM_LIT:1>] - passb[<NUM_LIT:0>]) - discr) / (<NUM_LIT:2> * W0)<EOL>WN = numpy.sort(abs(WN))<EOL><DEDENT>elif filter_type == <NUM_LIT:4>:  <EOL><INDENT>W0 = numpy.array([-W0, W0], float)<EOL>WN = (-W0 * (passb[<NUM_LIT:1>] - passb[<NUM_LIT:0>]) / <NUM_LIT> +<EOL>sqrt(W0 ** <NUM_LIT:2> / <NUM_LIT> * (passb[<NUM_LIT:1>] - passb[<NUM_LIT:0>]) ** <NUM_LIT:2> +<EOL>passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]))<EOL>WN = numpy.sort(abs(WN))<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % filter_type)<EOL><DEDENT>if not analog:<EOL><INDENT>wn = (<NUM_LIT> / pi) * arctan(WN)<EOL><DEDENT>else:<EOL><INDENT>wn = WN<EOL><DEDENT>if len(wn) == <NUM_LIT:1>:<EOL><INDENT>wn = wn[<NUM_LIT:0>]<EOL><DEDENT>return ord, wn<EOL>

Butterworth filter order selection.

    Return the order of the lowest order digital or analog Butterworth 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 Butterworth filter which meets specs.
    wn : ndarray or float
        The Butterworth natural frequency (i.e. the "3dB frequency").  Should
        be used with `butter` to give filter results.

    See Also
    --------
    butter : Filter design using order and critical points
    cheb1ord : Find order and critical points from passband and stopband spec
    cheb2ord, ellipord
    iirfilter : General filter design using order and critical frequencies
    iirdesign : General filter design using passband and stopband spec

    Examples
    --------
    Design an analog bandpass filter with passband within 3 dB from 20 to
    50 rad/s, while rejecting at least -40 dB below 14 and above 60 rad/s.
    Plot its frequency response, showing the passband and stopband
    constraints in gray.

    >>> from scipy import signal
    >>> import matplotlib.pyplot as plt

    >>> N, Wn = signal.buttord([20, 50], [14, 60], 3, 40, True)
    >>> b, a = signal.butter(N, Wn, 'band', True)
    >>> w, h = signal.freqs(b, a, np.logspace(1, 2, 500))
    >>> plt.semilogx(w, 20 * np.log10(abs(h)))
    >>> plt.title('Butterworth bandpass filter fit to constraints')
    >>> plt.xlabel('Frequency [radians / second]')
    >>> plt.ylabel('Amplitude [dB]')
    >>> plt.grid(which='both', axis='both')
    >>> plt.fill([1,  14,  14,   1], [-40, -40, 99, 99], '0.9', lw=0) # stop
    >>> plt.fill([20, 20,  50,  50], [-99, -3, -3, -99], '0.9', lw=0) # pass
    >>> plt.fill([60, 60, 1e9, 1e9], [99, -40, -40, 99], '0.9', lw=0) # stop
    >>> plt.axis([10, 100, -60, 3])
    >>> plt.show()


def cheb1ord(wp, ws, gpass, gstop, analog=False):

wp = atleast_1d(wp)<EOL>ws = atleast_1d(ws)<EOL>filter_type = <NUM_LIT:2> * (len(wp) - <NUM_LIT:1>)<EOL>if wp[<NUM_LIT:0>] < ws[<NUM_LIT:0>]:<EOL><INDENT>filter_type += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>filter_type += <NUM_LIT:2><EOL><DEDENT>if not analog:<EOL><INDENT>passb = tan(pi * wp / <NUM_LIT>)<EOL>stopb = tan(pi * ws / <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>passb = wp * <NUM_LIT:1.0><EOL>stopb = ws * <NUM_LIT:1.0><EOL><DEDENT>if filter_type == <NUM_LIT:1>:           <EOL><INDENT>nat = stopb / passb<EOL><DEDENT>elif filter_type == <NUM_LIT:2>:          <EOL><INDENT>nat = passb / stopb<EOL><DEDENT>elif filter_type == <NUM_LIT:3>:     <EOL><INDENT>wp0 = optimize.fminbound(band_stop_obj, passb[<NUM_LIT:0>], stopb[<NUM_LIT:0>] - <NUM_LIT>,<EOL>args=(<NUM_LIT:0>, passb, stopb, gpass, gstop, '<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:0>] = wp0<EOL>wp1 = optimize.fminbound(band_stop_obj, stopb[<NUM_LIT:1>] + <NUM_LIT>, passb[<NUM_LIT:1>],<EOL>args=(<NUM_LIT:1>, passb, stopb, gpass, gstop, '<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:1>] = wp1<EOL>nat = ((stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])) /<EOL>(stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]))<EOL><DEDENT>elif filter_type == <NUM_LIT:4>:  <EOL><INDENT>nat = ((stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]) /<EOL>(stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])))<EOL><DEDENT>nat = min(abs(nat))<EOL>GSTOP = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gstop))<EOL>GPASS = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gpass))<EOL>ord = int(ceil(arccosh(sqrt((GSTOP - <NUM_LIT:1.0>) / (GPASS - <NUM_LIT:1.0>))) /<EOL>arccosh(nat)))<EOL>if not analog:<EOL><INDENT>wn = (<NUM_LIT> / pi) * arctan(passb)<EOL><DEDENT>else:<EOL><INDENT>wn = passb<EOL><DEDENT>if len(wn) == <NUM_LIT:1>:<EOL><INDENT>wn = wn[<NUM_LIT:0>]<EOL><DEDENT>return ord, wn<EOL>

Chebyshev type I filter order selection.

    Return the order of the lowest order digital or analog Chebyshev Type I
    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 I filter that meets specs.
    wn : ndarray or float
        The Chebyshev natural frequency (the "3dB frequency") for use with
        `cheby1` to give filter results.

    See Also
    --------
    cheby1 : Filter design using order and critical points
    buttord : Find order and critical points from passband and stopband spec
    cheb2ord, ellipord
    iirfilter : General filter design using order and critical frequencies
    iirdesign : General filter design using passband and stopband spec

    Examples
    --------
    Design a digital lowpass filter such that the passband is within 3 dB up
    to 0.2*(fs/2), while rejecting at least -40 dB above 0.3*(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.cheb1ord(0.2, 0.3, 3, 40)
    >>> b, a = signal.cheby1(N, 3, Wn, 'low')
    >>> w, h = signal.freqz(b, a)
    >>> plt.semilogx(w / np.pi, 20 * np.log10(abs(h)))
    >>> plt.title('Chebyshev I lowpass filter fit to constraints')
    >>> plt.xlabel('Normalized frequency')
    >>> plt.ylabel('Amplitude [dB]')
    >>> plt.grid(which='both', axis='both')
    >>> plt.fill([.01, 0.2, 0.2, .01], [-3, -3, -99, -99], '0.9', lw=0) # stop
    >>> plt.fill([0.3, 0.3,   2,   2], [ 9, -40, -40,  9], '0.9', lw=0) # pass
    >>> plt.axis([0.08, 1, -60, 3])
    >>> plt.show()


def cheb2ord(wp, ws, gpass, gstop, analog=False):

wp = atleast_1d(wp)<EOL>ws = atleast_1d(ws)<EOL>filter_type = <NUM_LIT:2> * (len(wp) - <NUM_LIT:1>)<EOL>if wp[<NUM_LIT:0>] < ws[<NUM_LIT:0>]:<EOL><INDENT>filter_type += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>filter_type += <NUM_LIT:2><EOL><DEDENT>if not analog:<EOL><INDENT>passb = tan(pi * wp / <NUM_LIT>)<EOL>stopb = tan(pi * ws / <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>passb = wp * <NUM_LIT:1.0><EOL>stopb = ws * <NUM_LIT:1.0><EOL><DEDENT>if filter_type == <NUM_LIT:1>:           <EOL><INDENT>nat = stopb / passb<EOL><DEDENT>elif filter_type == <NUM_LIT:2>:          <EOL><INDENT>nat = passb / stopb<EOL><DEDENT>elif filter_type == <NUM_LIT:3>:     <EOL><INDENT>wp0 = optimize.fminbound(band_stop_obj, passb[<NUM_LIT:0>], stopb[<NUM_LIT:0>] - <NUM_LIT>,<EOL>args=(<NUM_LIT:0>, passb, stopb, gpass, gstop, '<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:0>] = wp0<EOL>wp1 = optimize.fminbound(band_stop_obj, stopb[<NUM_LIT:1>] + <NUM_LIT>, passb[<NUM_LIT:1>],<EOL>args=(<NUM_LIT:1>, passb, stopb, gpass, gstop, '<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:1>] = wp1<EOL>nat = ((stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])) /<EOL>(stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]))<EOL><DEDENT>elif filter_type == <NUM_LIT:4>:  <EOL><INDENT>nat = ((stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]) /<EOL>(stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])))<EOL><DEDENT>nat = min(abs(nat))<EOL>GSTOP = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gstop))<EOL>GPASS = <NUM_LIT:10> ** (<NUM_LIT:0.1> * abs(gpass))<EOL>ord = int(ceil(arccosh(sqrt((GSTOP - <NUM_LIT:1.0>) / (GPASS - <NUM_LIT:1.0>))) /<EOL>arccosh(nat)))<EOL>new_freq = cosh(<NUM_LIT:1.0> / ord * arccosh(sqrt((GSTOP - <NUM_LIT:1.0>) / (GPASS - <NUM_LIT:1.0>))))<EOL>new_freq = <NUM_LIT:1.0> / new_freq<EOL>if filter_type == <NUM_LIT:1>:<EOL><INDENT>nat = passb / new_freq<EOL><DEDENT>elif filter_type == <NUM_LIT:2>:<EOL><INDENT>nat = passb * new_freq<EOL><DEDENT>elif filter_type == <NUM_LIT:3>:<EOL><INDENT>nat = numpy.zeros(<NUM_LIT:2>, float)<EOL>nat[<NUM_LIT:0>] = (new_freq / <NUM_LIT> * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>]) +<EOL>sqrt(new_freq ** <NUM_LIT:2> * (passb[<NUM_LIT:1>] - passb[<NUM_LIT:0>]) ** <NUM_LIT:2> / <NUM_LIT> +<EOL>passb[<NUM_LIT:1>] * passb[<NUM_LIT:0>]))<EOL>nat[<NUM_LIT:1>] = passb[<NUM_LIT:1>] * passb[<NUM_LIT:0>] / nat[<NUM_LIT:0>]<EOL><DEDENT>elif filter_type == <NUM_LIT:4>:<EOL><INDENT>nat = numpy.zeros(<NUM_LIT:2>, float)<EOL>nat[<NUM_LIT:0>] = (<NUM_LIT:1.0> / (<NUM_LIT> * new_freq) * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>]) +<EOL>sqrt((passb[<NUM_LIT:1>] - passb[<NUM_LIT:0>]) ** <NUM_LIT:2> / (<NUM_LIT> * new_freq ** <NUM_LIT:2>) +<EOL>passb[<NUM_LIT:1>] * passb[<NUM_LIT:0>]))<EOL>nat[<NUM_LIT:1>] = passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>] / nat[<NUM_LIT:0>]<EOL><DEDENT>if not analog:<EOL><INDENT>wn = (<NUM_LIT> / pi) * arctan(nat)<EOL><DEDENT>else:<EOL><INDENT>wn = nat<EOL><DEDENT>if len(wn) == <NUM_LIT:1>:<EOL><INDENT>wn = wn[<NUM_LIT:0>]<EOL><DEDENT>return ord, wn<EOL>

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


def ellipord(wp, ws, gpass, gstop, analog=False):

wp = atleast_1d(wp)<EOL>ws = atleast_1d(ws)<EOL>filter_type = <NUM_LIT:2> * (len(wp) - <NUM_LIT:1>)<EOL>filter_type += <NUM_LIT:1><EOL>if wp[<NUM_LIT:0>] >= ws[<NUM_LIT:0>]:<EOL><INDENT>filter_type += <NUM_LIT:1><EOL><DEDENT>if not analog:<EOL><INDENT>passb = tan(pi * wp / <NUM_LIT>)<EOL>stopb = tan(pi * ws / <NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>passb = wp * <NUM_LIT:1.0><EOL>stopb = ws * <NUM_LIT:1.0><EOL><DEDENT>if filter_type == <NUM_LIT:1>:           <EOL><INDENT>nat = stopb / passb<EOL><DEDENT>elif filter_type == <NUM_LIT:2>:          <EOL><INDENT>nat = passb / stopb<EOL><DEDENT>elif filter_type == <NUM_LIT:3>:     <EOL><INDENT>wp0 = optimize.fminbound(band_stop_obj, passb[<NUM_LIT:0>], stopb[<NUM_LIT:0>] - <NUM_LIT>,<EOL>args=(<NUM_LIT:0>, passb, stopb, gpass, gstop, '<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:0>] = wp0<EOL>wp1 = optimize.fminbound(band_stop_obj, stopb[<NUM_LIT:1>] + <NUM_LIT>, passb[<NUM_LIT:1>],<EOL>args=(<NUM_LIT:1>, passb, stopb, gpass, gstop, '<STR_LIT>'),<EOL>disp=<NUM_LIT:0>)<EOL>passb[<NUM_LIT:1>] = wp1<EOL>nat = ((stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])) /<EOL>(stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]))<EOL><DEDENT>elif filter_type == <NUM_LIT:4>:  <EOL><INDENT>nat = ((stopb ** <NUM_LIT:2> - passb[<NUM_LIT:0>] * passb[<NUM_LIT:1>]) /<EOL>(stopb * (passb[<NUM_LIT:0>] - passb[<NUM_LIT:1>])))<EOL><DEDENT>nat = min(abs(nat))<EOL>GSTOP = <NUM_LIT:10> ** (<NUM_LIT:0.1> * gstop)<EOL>GPASS = <NUM_LIT:10> ** (<NUM_LIT:0.1> * gpass)<EOL>arg1 = sqrt((GPASS - <NUM_LIT:1.0>) / (GSTOP - <NUM_LIT:1.0>))<EOL>arg0 = <NUM_LIT:1.0> / nat<EOL>d0 = special.ellipk([arg0 ** <NUM_LIT:2>, <NUM_LIT:1> - arg0 ** <NUM_LIT:2>])<EOL>d1 = special.ellipk([arg1 ** <NUM_LIT:2>, <NUM_LIT:1> - arg1 ** <NUM_LIT:2>])<EOL>ord = int(ceil(d0[<NUM_LIT:0>] * d1[<NUM_LIT:1>] / (d0[<NUM_LIT:1>] * d1[<NUM_LIT:0>])))<EOL>if not analog:<EOL><INDENT>wn = arctan(passb) * <NUM_LIT> / pi<EOL><DEDENT>else:<EOL><INDENT>wn = passb<EOL><DEDENT>if len(wn) == <NUM_LIT:1>:<EOL><INDENT>wn = wn[<NUM_LIT:0>]<EOL><DEDENT>return ord, wn<EOL>

Elliptic (Cauer) filter order selection.

    Return the order of the lowest order digital or analog elliptic 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 an Elliptic (Cauer) filter that meets specs.
    wn : ndarray or float
        The Chebyshev natural frequency (the "3dB frequency") for use with
        `ellip` to give filter results.

    See Also
    --------
    ellip : Filter design using order and critical points
    buttord : Find order and critical points from passband and stopband spec
    cheb1ord, cheb2ord
    iirfilter : General filter design using order and critical frequencies
    iirdesign : General filter design using passband and stopband spec

    Examples
    --------
    Design an analog highpass filter such that the passband is within 3 dB
    above 30 rad/s, while rejecting -60 dB at 10 rad/s.  Plot its
    frequency response, showing the passband and stopband constraints in gray.

    >>> from scipy import signal
    >>> import matplotlib.pyplot as plt

    >>> N, Wn = signal.ellipord(30, 10, 3, 60, True)
    >>> b, a = signal.ellip(N, 3, 60, Wn, 'high', True)
    >>> w, h = signal.freqs(b, a, np.logspace(0, 3, 500))
    >>> plt.semilogx(w, 20 * np.log10(abs(h)))
    >>> plt.title('Elliptical highpass filter fit to constraints')
    >>> plt.xlabel('Frequency [radians / second]')
    >>> plt.ylabel('Amplitude [dB]')
    >>> plt.grid(which='both', axis='both')
    >>> plt.fill([.1, 10,  10,  .1], [1e4, 1e4, -60, -60], '0.9', lw=0) # stop
    >>> plt.fill([30, 30, 1e9, 1e9], [-99,  -3,  -3, -99], '0.9', lw=0) # pass
    >>> plt.axis([1, 300, -80, 3])
    >>> plt.show()


if abs(int(N)) != N:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>z = numpy.array([])<EOL>m = numpy.arange(-N+<NUM_LIT:1>, N, <NUM_LIT:2>)<EOL>p = -numpy.exp(<NUM_LIT> * pi * m / (<NUM_LIT:2> * N))<EOL>k = <NUM_LIT:1><EOL>return z, p, k<EOL>

Return (z,p,k) for analog prototype of Nth order Butterworth filter.

    The filter will have an angular (e.g. rad/s) cutoff frequency of 1.


if abs(int(N)) != N:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif N == <NUM_LIT:0>:<EOL><INDENT>return numpy.array([]), numpy.array([]), <NUM_LIT:10>**(-rp/<NUM_LIT:20>)<EOL><DEDENT>z = numpy.array([])<EOL>eps = numpy.sqrt(<NUM_LIT:10> ** (<NUM_LIT:0.1> * rp) - <NUM_LIT:1.0>)<EOL>mu = <NUM_LIT:1.0> / N * arcsinh(<NUM_LIT:1> / eps)<EOL>m = numpy.arange(-N+<NUM_LIT:1>, N, <NUM_LIT:2>)<EOL>theta = pi * m / (<NUM_LIT:2>*N)<EOL>p = -sinh(mu + <NUM_LIT>*theta)<EOL>k = numpy.prod(-p, axis=<NUM_LIT:0>).real<EOL>if N % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>k = k / sqrt((<NUM_LIT:1> + eps * eps))<EOL><DEDENT>return z, p, k<EOL>

Return (z,p,k) for Nth order Chebyshev type I analog lowpass filter.

The returned filter prototype has `rp` decibels of ripple in the passband.

The filter's angular (e.g. rad/s) cutoff frequency is normalized to 1,
defined as the point at which the gain first drops below ``-rp``.


if abs(int(N)) != N:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif N == <NUM_LIT:0>:<EOL><INDENT>return numpy.array([]), numpy.array([]), <NUM_LIT:1><EOL><DEDENT>de = <NUM_LIT:1.0> / sqrt(<NUM_LIT:10> ** (<NUM_LIT:0.1> * rs) - <NUM_LIT:1>)<EOL>mu = arcsinh(<NUM_LIT:1.0> / de) / N<EOL>if N % <NUM_LIT:2>:<EOL><INDENT>m = numpy.concatenate((numpy.arange(-N+<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:2>),<EOL>numpy.arange(<NUM_LIT:2>, N, <NUM_LIT:2>)))<EOL><DEDENT>else:<EOL><INDENT>m = numpy.arange(-N+<NUM_LIT:1>, N, <NUM_LIT:2>)<EOL><DEDENT>z = -conjugate(<NUM_LIT> / sin(m * pi / (<NUM_LIT> * N)))<EOL>p = -exp(<NUM_LIT> * pi * numpy.arange(-N+<NUM_LIT:1>, N, <NUM_LIT:2>) / (<NUM_LIT:2> * N))<EOL>p = sinh(mu) * p.real + <NUM_LIT> * cosh(mu) * p.imag<EOL>p = <NUM_LIT:1.0> / p<EOL>k = (numpy.prod(-p, axis=<NUM_LIT:0>) / numpy.prod(-z, axis=<NUM_LIT:0>)).real<EOL>return z, p, k<EOL>

Return (z,p,k) for Nth order Chebyshev type I analog lowpass filter.

The returned filter prototype has `rs` decibels of ripple in the stopband.

The filter's angular (e.g. rad/s) cutoff frequency is normalized to 1,
defined as the point at which the gain first reaches ``-rs``.


if abs(int(N)) != N:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>elif N == <NUM_LIT:0>:<EOL><INDENT>return numpy.array([]), numpy.array([]), <NUM_LIT:10>**(-rp/<NUM_LIT:20>)<EOL><DEDENT>elif N == <NUM_LIT:1>:<EOL><INDENT>p = -sqrt(<NUM_LIT:1.0> / (<NUM_LIT:10> ** (<NUM_LIT:0.1> * rp) - <NUM_LIT:1.0>))<EOL>k = -p<EOL>z = []<EOL>return asarray(z), asarray(p), k<EOL><DEDENT>eps = numpy.sqrt(<NUM_LIT:10> ** (<NUM_LIT:0.1> * rp) - <NUM_LIT:1>)<EOL>ck1 = eps / numpy.sqrt(<NUM_LIT:10> ** (<NUM_LIT:0.1> * rs) - <NUM_LIT:1>)<EOL>ck1p = numpy.sqrt(<NUM_LIT:1> - ck1 * ck1)<EOL>if ck1p == <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>val = special.ellipk([ck1 * ck1, ck1p * ck1p])<EOL>if abs(<NUM_LIT:1> - ck1p * ck1p) < EPSILON:<EOL><INDENT>krat = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>krat = N * val[<NUM_LIT:0>] / val[<NUM_LIT:1>]<EOL><DEDENT>m = optimize.fmin(_kratio, [<NUM_LIT:0.5>], args=(krat,), maxfun=<NUM_LIT>, maxiter=<NUM_LIT>,<EOL>disp=<NUM_LIT:0>)<EOL>if m < <NUM_LIT:0> or m > <NUM_LIT:1>:<EOL><INDENT>m = optimize.fminbound(_kratio, <NUM_LIT:0>, <NUM_LIT:1>, args=(krat,), maxfun=<NUM_LIT>,<EOL>maxiter=<NUM_LIT>, disp=<NUM_LIT:0>)<EOL><DEDENT>capk = special.ellipk(m)<EOL>j = numpy.arange(<NUM_LIT:1> - N % <NUM_LIT:2>, N, <NUM_LIT:2>)<EOL>jj = len(j)<EOL>[s, c, d, phi] = special.ellipj(j * capk / N, m * numpy.ones(jj))<EOL>snew = numpy.compress(abs(s) > EPSILON, s, axis=-<NUM_LIT:1>)<EOL>z = <NUM_LIT:1.0> / (sqrt(m) * snew)<EOL>z = <NUM_LIT> * z<EOL>z = numpy.concatenate((z, conjugate(z)))<EOL>r = optimize.fmin(_vratio, special.ellipk(m), args=(<NUM_LIT:1.> / eps, ck1p * ck1p),<EOL>maxfun=<NUM_LIT>, maxiter=<NUM_LIT>, disp=<NUM_LIT:0>)<EOL>v0 = capk * r / (N * val[<NUM_LIT:0>])<EOL>[sv, cv, dv, phi] = special.ellipj(v0, <NUM_LIT:1> - m)<EOL>p = -(c * d * sv * cv + <NUM_LIT> * s * dv) / (<NUM_LIT:1> - (d * sv) ** <NUM_LIT>)<EOL>if N % <NUM_LIT:2>:<EOL><INDENT>newp = numpy.compress(abs(p.imag) > EPSILON *<EOL>numpy.sqrt(numpy.sum(p * numpy.conjugate(p),<EOL>axis=<NUM_LIT:0>).real),<EOL>p, axis=-<NUM_LIT:1>)<EOL>p = numpy.concatenate((p, conjugate(newp)))<EOL><DEDENT>else:<EOL><INDENT>p = numpy.concatenate((p, conjugate(p)))<EOL><DEDENT>k = (numpy.prod(-p, axis=<NUM_LIT:0>) / numpy.prod(-z, axis=<NUM_LIT:0>)).real<EOL>if N % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>k = k / numpy.sqrt((<NUM_LIT:1> + eps * eps))<EOL><DEDENT>return z, p, k<EOL>

Return (z,p,k) of Nth order elliptic analog lowpass filter.

    The filter is a normalized prototype that has `rp` decibels of ripple
    in the passband and a stopband `rs` decibels down.

    The filter's angular (e.g. rad/s) cutoff frequency is normalized to 1,
    defined as the point at which the gain first drops below ``-rp``.

    References
    ----------
    Lutova, Tosic, and Evans, "Filter Design for Signal Processing", Chapters 5
    and 12.


z = []<EOL>k = <NUM_LIT:1><EOL>if N == <NUM_LIT:0>:<EOL><INDENT>p = []<EOL><DEDENT>elif N == <NUM_LIT:1>:<EOL><INDENT>p = [-<NUM_LIT:1>]<EOL><DEDENT>elif N == <NUM_LIT:2>:<EOL><INDENT>p = [-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:3>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:4>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:5>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:6>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:7>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:8>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:9>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:10>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:11>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:12>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:15>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:16>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT:20>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>elif N == <NUM_LIT>:<EOL><INDENT>p = [-<NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>,<EOL>-<NUM_LIT> - <NUM_LIT>,<EOL>-<NUM_LIT> + <NUM_LIT>]<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>" % N)<EOL><DEDENT>return asarray(z), asarray(p), k<EOL>

Return (z,p,k) for analog prototype of an Nth order Bessel filter.

    The filter is normalized such that the filter asymptotes are the same as
    a Butterworth filter of the same order with an angular (e.g. rad/s)
    cutoff frequency of 1.

    Parameters
    ----------
    N : int
        The order of the Bessel filter to return zeros, poles and gain for.
        Values in the range 0-25 are supported.

    Returns
    -------
    z : ndarray
        Zeros. Is always an empty array.
    p : ndarray
        Poles.
    k : scalar
        Gain. Always 1.


return np.ones(M, float)<EOL>

Return a boxcar or rectangular window.

    Included for completeness, this is equivalent to no window at all.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        Whether the window is symmetric. (Has no effect for boxcar.)

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1.

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.boxcar(51)
    >>> plt.plot(window)
    >>> plt.title("Boxcar window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the boxcar window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>n = np.arange(<NUM_LIT:1>, (M + <NUM_LIT:1>) // <NUM_LIT:2> + <NUM_LIT:1>)<EOL>if M % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>w = (<NUM_LIT:2> * n - <NUM_LIT:1.0>) / M<EOL>w = np.r_[w, w[::-<NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>w = <NUM_LIT:2> * n / (M + <NUM_LIT:1.0>)<EOL>w = np.r_[w, w[-<NUM_LIT:2>::-<NUM_LIT:1>]]<EOL><DEDENT>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

Return a triangular window.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.triang(51)
    >>> plt.plot(window)
    >>> plt.title("Triangular window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the triangular window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>n = np.arange(-(M - <NUM_LIT:1>) / <NUM_LIT>, (M - <NUM_LIT:1>) / <NUM_LIT> + <NUM_LIT:0.5>, <NUM_LIT:1.0>)<EOL>na = np.extract(n < -(M - <NUM_LIT:1>) / <NUM_LIT>, n)<EOL>nb = np.extract(abs(n) <= (M - <NUM_LIT:1>) / <NUM_LIT>, n)<EOL>wa = <NUM_LIT:2> * (<NUM_LIT:1> - np.abs(na) / (M / <NUM_LIT>)) ** <NUM_LIT><EOL>wb = (<NUM_LIT:1> - <NUM_LIT:6> * (np.abs(nb) / (M / <NUM_LIT>)) ** <NUM_LIT> +<EOL><NUM_LIT:6> * (np.abs(nb) / (M / <NUM_LIT>)) ** <NUM_LIT>)<EOL>w = np.r_[wa, wb, wa[::-<NUM_LIT:1>]]<EOL>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

Return a Parzen window.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.parzen(51)
    >>> plt.plot(window)
    >>> plt.title("Parzen window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the Parzen window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>fac = np.abs(np.linspace(-<NUM_LIT:1>, <NUM_LIT:1>, M)[<NUM_LIT:1>:-<NUM_LIT:1>])<EOL>w = (<NUM_LIT:1> - fac) * np.cos(np.pi * fac) + <NUM_LIT:1.0> / np.pi * np.sin(np.pi * fac)<EOL>w = np.r_[<NUM_LIT:0>, w, <NUM_LIT:0>]<EOL>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

Return a Bohman window.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.bohman(51)
    >>> plt.plot(window)
    >>> plt.title("Bohman window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the Bohman window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


<EOL>if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>n = np.arange(<NUM_LIT:0>, M)<EOL>w = (<NUM_LIT> - <NUM_LIT:0.5> * np.cos(<NUM_LIT> * np.pi * n / (M - <NUM_LIT:1>)) +<EOL><NUM_LIT> * np.cos(<NUM_LIT> * np.pi * n / (M - <NUM_LIT:1>)))<EOL>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

r"""
    Return a Blackman window.

    The Blackman window is a taper formed by using the first three terms of
    a summation of cosines. It was designed to have close to the minimal
    leakage possible.  It is close to optimal, only slightly worse than a
    Kaiser window.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Notes
    -----
    The Blackman window is defined as

    .. math::  w(n) = 0.42 - 0.5 \cos(2\pi n/M) + 0.08 \cos(4\pi n/M)

    Most references to the Blackman window come from the signal processing
    literature, where it is used as one of many windowing functions for
    smoothing values.  It is also known as an apodization (which means
    "removing the foot", i.e. smoothing discontinuities at the beginning
    and end of the sampled signal) or tapering function. It is known as a
    "near optimal" tapering function, almost as good (by some measures)
    as the Kaiser window.

    References
    ----------
    .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power
           spectra, Dover Publications, New York.
    .. [2] Oppenheim, A.V., and R.W. Schafer. Discrete-Time Signal Processing.
           Upper Saddle River, NJ: Prentice-Hall, 1999, pp. 468-471.

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.blackman(51)
    >>> plt.plot(window)
    >>> plt.title("Blackman window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the Blackman window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>a = [<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>]<EOL>n = np.arange(<NUM_LIT:0>, M)<EOL>fac = n * <NUM_LIT:2> * np.pi / (M - <NUM_LIT:1.0>)<EOL>w = (a[<NUM_LIT:0>] - a[<NUM_LIT:1>] * np.cos(fac) +<EOL>a[<NUM_LIT:2>] * np.cos(<NUM_LIT:2> * fac) - a[<NUM_LIT:3>] * np.cos(<NUM_LIT:3> * fac))<EOL>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

Return a minimum 4-term Blackman-Harris window according to Nuttall.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.nuttall(51)
    >>> plt.plot(window)
    >>> plt.title("Nuttall window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the Nuttall window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


Return a minimum 4-term Blackman-Harris window.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.blackmanharris(51)
    >>> plt.plot(window)
    >>> plt.title("Blackman-Harris window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the Blackman-Harris window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>a = [<NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>]<EOL>n = np.arange(<NUM_LIT:0>, M)<EOL>fac = n * <NUM_LIT:2> * np.pi / (M - <NUM_LIT:1.0>)<EOL>w = (a[<NUM_LIT:0>] - a[<NUM_LIT:1>] * np.cos(fac) +<EOL>a[<NUM_LIT:2>] * np.cos(<NUM_LIT:2> * fac) - a[<NUM_LIT:3>] * np.cos(<NUM_LIT:3> * fac) +<EOL>a[<NUM_LIT:4>] * np.cos(<NUM_LIT:4> * fac))<EOL>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

Return a flat top window.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.flattop(51)
    >>> plt.plot(window)
    >>> plt.title("Flat top window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the flat top window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


<EOL>if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>n = np.arange(<NUM_LIT:0>, M)<EOL>w = np.where(np.less_equal(n, (M - <NUM_LIT:1>) / <NUM_LIT>),<EOL><NUM_LIT> * n / (M - <NUM_LIT:1>), <NUM_LIT> - <NUM_LIT> * n / (M - <NUM_LIT:1>))<EOL>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

r"""
    Return a Bartlett window.

    The Bartlett window is very similar to a triangular window, except
    that the end points are at zero.  It is often used in signal
    processing for tapering a signal, without generating too much
    ripple in the frequency domain.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The triangular window, with the first and last samples equal to zero
        and the maximum value normalized to 1 (though the value 1 does not
        appear if `M` is even and `sym` is True).

    Notes
    -----
    The Bartlett window is defined as

    .. math:: w(n) = \frac{2}{M-1} \left(
              \frac{M-1}{2} - \left|n - \frac{M-1}{2}\right|
              \right)

    Most references to the Bartlett window come from the signal
    processing literature, where it is used as one of many windowing
    functions for smoothing values.  Note that convolution with this
    window produces linear interpolation.  It is also known as an
    apodization (which means"removing the foot", i.e. smoothing
    discontinuities at the beginning and end of the sampled signal) or
    tapering function. The Fourier transform of the Bartlett is the product
    of two sinc functions.
    Note the excellent discussion in Kanasewich.

    References
    ----------
    .. [1] M.S. Bartlett, "Periodogram Analysis and Continuous Spectra",
           Biometrika 37, 1-16, 1950.
    .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics",
           The University of Alberta Press, 1975, pp. 109-110.
    .. [3] A.V. Oppenheim and R.W. Schafer, "Discrete-Time Signal
           Processing", Prentice-Hall, 1999, pp. 468-471.
    .. [4] Wikipedia, "Window function",
           http://en.wikipedia.org/wiki/Window_function
    .. [5] W.H. Press,  B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling,
           "Numerical Recipes", Cambridge University Press, 1986, page 429.

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.bartlett(51)
    >>> plt.plot(window)
    >>> plt.title("Bartlett window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the Bartlett window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")


<EOL>if M < <NUM_LIT:1>:<EOL><INDENT>return np.array([])<EOL><DEDENT>if M == <NUM_LIT:1>:<EOL><INDENT>return np.ones(<NUM_LIT:1>, '<STR_LIT:d>')<EOL><DEDENT>odd = M % <NUM_LIT:2><EOL>if not sym and not odd:<EOL><INDENT>M = M + <NUM_LIT:1><EOL><DEDENT>n = np.arange(<NUM_LIT:0>, M)<EOL>w = <NUM_LIT:0.5> - <NUM_LIT:0.5> * np.cos(<NUM_LIT> * np.pi * n / (M - <NUM_LIT:1>))<EOL>if not sym and not odd:<EOL><INDENT>w = w[:-<NUM_LIT:1>]<EOL><DEDENT>return w<EOL>

r"""
    Return a Hann window.

    The Hann window is a taper formed by using a raised cosine or sine-squared
    with ends that touch zero.

    Parameters
    ----------
    M : int
        Number of points in the output window. If zero or less, an empty
        array is returned.
    sym : bool, optional
        When True (default), generates a symmetric window, for use in filter
        design.
        When False, generates a periodic window, for use in spectral analysis.

    Returns
    -------
    w : ndarray
        The window, with the maximum value normalized to 1 (though the value 1
        does not appear if `M` is even and `sym` is True).

    Notes
    -----
    The Hann window is defined as

    .. math::  w(n) = 0.5 - 0.5 \cos\left(\frac{2\pi{n}}{M-1}\right)
               \qquad 0 \leq n \leq M-1

    The window was named for Julius van Hann, an Austrian meteorologist. It is
    also known as the Cosine Bell. It is sometimes erroneously referred to as
    the "Hanning" window, from the use of "hann" as a verb in the original
    paper and confusion with the very similar Hamming window.

    Most references to the Hann window come from the signal processing
    literature, where it is used as one of many windowing functions for
    smoothing values.  It is also known as an apodization (which means
    "removing the foot", i.e. smoothing discontinuities at the beginning
    and end of the sampled signal) or tapering function.

    References
    ----------
    .. [1] Blackman, R.B. and Tukey, J.W., (1958) The measurement of power
           spectra, Dover Publications, New York.
    .. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics",
           The University of Alberta Press, 1975, pp. 106-108.
    .. [3] Wikipedia, "Window function",
           http://en.wikipedia.org/wiki/Window_function
    .. [4] W.H. Press,  B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling,
           "Numerical Recipes", Cambridge University Press, 1986, page 425.

    Examples
    --------
    Plot the window and its frequency response:

    >>> from scipy import signal
    >>> from scipy.fftpack import fft, fftshift
    >>> import matplotlib.pyplot as plt

    >>> window = signal.hann(51)
    >>> plt.plot(window)
    >>> plt.title("Hann window")
    >>> plt.ylabel("Amplitude")
    >>> plt.xlabel("Sample")

    >>> plt.figure()
    >>> A = fft(window, 2048) / (len(window)/2.0)
    >>> freq = np.linspace(-0.5, 0.5, len(A))
    >>> response = 20 * np.log10(np.abs(fftshift(A / abs(A).max())))
    >>> plt.plot(freq, response)
    >>> plt.axis([-0.5, 0.5, -120, 0])
    >>> plt.title("Frequency response of the Hann window")
    >>> plt.ylabel("Normalized magnitude [dB]")
    >>> plt.xlabel("Normalized frequency [cycles per sample]")