
    (phF             
          S r SSKrSSKrSSKrSSKJrJrJr	  / SQr
S rS rS rS9S	 jrS9S
 jrS9S jrS9S jrS9S jrS9S jrS9S jrS9S jrS9S jrS9S jrS9S jrS:S jrS9S jrS9S jrS9S jrS9S jrSS.S jrS9S jrS9S jr S9S jr!S9S jr"S;S jr#S<S  jr$S=S" jr%SS.S# jr&S$ r'0 S%\S!4_S&\S!4_S'\S!4_S(\S!4_S)\S!4_S*\S!4_S+\!S4_S,\"S!4_S-\%S4_S.\#S!4_S/\S!4_S0\S4_S1\S4_S2\ S4_S3\S4_S4\S!4_S5\S!4_\S4\S4\&S!4\S!4\S!4\$S!4\S!4\S!4S6.Er(0 r)\(RU                  5        H  u  r+r,\+ H  r-\,S   \)\-'   M     M     \." 5       r/\(RU                  5        H#  u  r+r,\,S7   (       d  M  \/Ra                  \+5        M%     S9S8 jr1g)>zThe suite of window functions.    N)linalgspecialfft)boxcartriangparzenbohmanblackmannuttallblackmanharrisflattopbartlettbarthannhammingkaiserkaiser_bessel_derivedgaussiangeneral_cosinegeneral_gaussiangeneral_hammingchebwincosinehannexponentialtukeytaylordpss
get_windowlanczosc                 L    [        U 5      U :w  d  U S:  a  [        S5      eU S:*  $ )z(Handle small or incorrect window lengthsr   z.Window length M must be a non-negative integer   )int
ValueError)Ms    P/var/www/html/venv/lib/python3.13/site-packages/scipy/signal/windows/_windows.py_len_guardsr&      s(    
1v{a!eIJJ6M    c                 &    U(       d  U S-   S4$ U S4$ )z9Extend window by 1 sample if needed for DFT-even symmetryr!   TF r$   syms     r%   _extendr,      s    1ud{%xr'   c                     U(       a  U SS $ U $ )z;Truncate window by 1 sample if needed for DFT-even symmetryNr)   )wneededs     r%   	_truncater1       s    "vr'   Tc                    [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " [        R
                  * [        R
                  U 5      n[        R                  " U 5      n[        [        U5      5       H#  nXQU   [        R                  " Xd-  5      -  -  nM%     [        XS5      $ )a	  
Generic weighted sum of cosine terms window

Parameters
----------
M : int
    Number of points in the output window
a : array_like
    Sequence of weighting coefficients. This uses the convention of being
    centered on the origin, so these will typically all be positive
    numbers, not alternating sign.
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 array of window values.

References
----------
.. [1] A. Nuttall, "Some windows with very good sidelobe behavior," IEEE
       Transactions on Acoustics, Speech, and Signal Processing, vol. 29,
       no. 1, pp. 84-91, Feb 1981. :doi:`10.1109/TASSP.1981.1163506`.
.. [2] Heinzel G. et al., "Spectrum and spectral density estimation by the
       Discrete Fourier transform (DFT), including a comprehensive list of
       window functions and some new flat-top windows", February 15, 2002
       https://holometer.fnal.gov/GH_FFT.pdf

Examples
--------
Heinzel describes a flat-top window named "HFT90D" with formula: [2]_

.. math::  w_j = 1 - 1.942604 \cos(z) + 1.340318 \cos(2z)
           - 0.440811 \cos(3z) + 0.043097 \cos(4z)

where

.. math::  z = \frac{2 \pi j}{N}, j = 0...N - 1

Since this uses the convention of starting at the origin, to reproduce the
window, we need to convert every other coefficient to a positive number:

>>> HFT90D = [1, 1.942604, 1.340318, 0.440811, 0.043097]

The paper states that the highest sidelobe is at -90.2 dB.  Reproduce
Figure 42 by plotting the window and its frequency response, and confirm
the sidelobe level in red:

>>> import numpy as np
>>> from scipy.signal.windows import general_cosine
>>> from scipy.fft import fft, fftshift
>>> import matplotlib.pyplot as plt

>>> window = general_cosine(1000, HFT90D, sym=False)
>>> plt.plot(window)
>>> plt.title("HFT90D window")
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("Sample")

>>> plt.figure()
>>> A = fft(window, 10000) / (len(window)/2.0)
>>> freq = np.linspace(-0.5, 0.5, len(A))
>>> response = np.abs(fftshift(A / abs(A).max()))
>>> response = 20 * np.log10(np.maximum(response, 1e-10))
>>> plt.plot(freq, response)
>>> plt.axis([-50/1000, 50/1000, -140, 0])
>>> plt.title("Frequency response of the HFT90D window")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")
>>> plt.axhline(-90.2, color='red')
>>> plt.show()
)r&   nponesr,   linspacepizerosrangelencosr1   )r$   ar+   needs_truncfacr/   ks          r%   r   r   (   s    X 1~~wwqzQ_NA
++ruufbeeQ
'C
A3q6]	qTBFF17O##  Q$$r'   c                     [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " U [        5      n[        X25      $ )a  Return a boxcar or rectangular window.

Also known as a rectangular window or Dirichlet window, this is equivalent
to no window at all.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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:

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

>>> window = signal.windows.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]")

)r&   r3   r4   r,   floatr1   r$   r+   r<   r/   s       r%   r   r      sB    Z 1~~wwqzQ_NA
5AQ$$r'   c                 f   [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " SU S-   S-  S-   5      nU S-  S:X  a&  SU-  S-
  U -  n[        R
                  XDSSS2   4   nO%SU-  U S-   -  n[        R
                  XDSSS2   4   n[        XB5      $ )ac  Return a triangular window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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).

See Also
--------
bartlett : A triangular window that touches zero

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

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

>>> window = signal.windows.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 = np.abs(fftshift(A / abs(A).max()))
>>> response = 20 * np.log10(np.maximum(response, 1e-10))
>>> 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]")

r!      r         ?Nr.   )r&   r3   r4   r,   aranger_r1   r$   r+   r<   nr/   s        r%   r   r      s    d 1~~wwqzQ_NA
		!a!e\A%&A1uzUS[AEE!ttW*EQWEE!rv2vY,Q$$r'   c                 p   [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " U S-
  * S-  U S-
  S-  S-   S5      n[        R
                  " X0S-
  * S-  :  U5      n[        R
                  " [        U5      U S-
  S-  :*  U5      nSS[        R                  " U5      U S-  -  -
  S-  -  nSS[        R                  " U5      U S-  -  S-  -  -
  S[        R                  " U5      U S-  -  S-  -  -   n[        R                  XgUS	S	S
2   4   n[        X5      $ )a  Return a Parzen window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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).

References
----------
.. [1] E. Parzen, "Mathematical Considerations in the Estimation of
       Spectra", Technometrics,  Vol. 3, No. 2 (May, 1961), pp. 167-190

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

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

>>> window = signal.windows.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]")

r!          @      ?rD   g      @rC   g      @   Nr.   )	r&   r3   r4   r,   rF   extractabsrG   r1   )	r$   r+   r<   rI   nanbwawbr/   s	            r%   r   r      s!   d 1~~wwqzQ_NA
		AE(S.1q5C-#"5s;A	Aa%3&	*B	CFq1um+Q	/B	
a"&&*C((S0	0B
a266":S)c11
1
rvvbzQW%#-
-.B
bb2hAQ$$r'   c                    [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " [        R
                  " SSU 5      SS 5      nSU-
  [        R                  " [        R                  U-  5      -  S[        R                  -  [        R                  " [        R                  U-  5      -  -   n[        R                  SUS4   n[        XB5      $ )a  Return a Bohman window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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:

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

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

>>> plt.figure()
>>> A = fft(window, 2047) / (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]")

r.   r!   rD   r   )r&   r3   r4   r,   rO   r5   r:   r6   sinrG   r1   )r$   r+   r<   r=   r/   s        r%   r	   r	   8  s    Z 1~~wwqzQ_NA
&&RA&q,
-C	
SBFF2553;''#+ruus{8K*KKA
aAgAQ$$r'   c                      [        U / SQU5      $ )a\  
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, an empty array
    is returned. An exception is thrown when it is negative.
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)

The "exact Blackman" window was designed to null out the third and fourth
sidelobes, but has discontinuities at the boundaries, resulting in a
6 dB/oct fall-off.  This window is an approximation of the "exact" window,
which does not null the sidelobes as well, but is smooth at the edges,
improving the fall-off rate to 18 dB/oct. [3]_

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.
.. [3] Harris, Fredric J. (Jan 1978). "On the use of Windows for Harmonic
       Analysis with the Discrete Fourier Transform". Proceedings of the
       IEEE 66 (1): 51-83. :doi:`10.1109/PROC.1978.10837`.

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

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

>>> window = signal.windows.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 = np.abs(fftshift(A / abs(A).max()))
>>> response = 20 * np.log10(np.maximum(response, 1e-10))
>>> 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]")

)gzG?rL   g{Gz?r   r*   s     r%   r
   r
   p  s    f !/55r'   c                      [        U / SQU5      $ )aL  Return a minimum 4-term Blackman-Harris window according to Nuttall.

This variation is called "Nuttall4c" by Heinzel. [2]_

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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).

References
----------
.. [1] A. Nuttall, "Some windows with very good sidelobe behavior," IEEE
       Transactions on Acoustics, Speech, and Signal Processing, vol. 29,
       no. 1, pp. 84-91, Feb 1981. :doi:`10.1109/TASSP.1981.1163506`.
.. [2] Heinzel G. et al., "Spectrum and spectral density estimation by the
       Discrete Fourier transform (DFT), including a comprehensive list of
       window functions and some new flat-top windows", February 15, 2002
       https://holometer.fnal.gov/GH_FFT.pdf

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

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

>>> window = signal.windows.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]")

)gzD?g;%N?g1|?gC ˅?rW   r*   s     r%   r   r     s    r !I3OOr'   c                      [        U / SQU5      $ )a  Return a minimum 4-term Blackman-Harris window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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:

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

>>> window = signal.windows.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]")

)g(\?g=$@?gʉv?gc#?rW   r*   s     r%   r   r     s    Z !A3GGr'   c                 "    / SQn[        XU5      $ )a  Return a flat top window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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
-----
Flat top windows are used for taking accurate measurements of signal
amplitude in the frequency domain, with minimal scalloping error from the
center of a frequency bin to its edges, compared to others.  This is a
5th-order cosine window, with the 5 terms optimized to make the main lobe
maximally flat. [1]_

References
----------
.. [1] D'Antona, Gabriele, and A. Ferrero, "Digital Signal Processing for
       Measurement Systems", Springer Media, 2006, p. 70
       :doi:`10.1007/0-387-28666-7`.

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

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

>>> window = signal.windows.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]")

)g^M?g+?g<?g'ne?gt|?rW   )r$   r+   r;   s      r%   r   r   2  s    v 	HA!$$r'   c                 :   [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " SU 5      n[        R
                  " [        R                  " X0S-
  S-  5      SU-  U S-
  -  SSU-  U S-
  -  -
  5      n[        XB5      $ )af  
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, an empty array
    is returned. An exception is thrown when it is negative.
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).

See Also
--------
triang : A triangular window that does not touch zero at the ends

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. [2]_

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",
       https://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:

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

>>> window = signal.windows.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]")

r   r!   rK   )r&   r3   r4   r,   rF   where
less_equalr1   rH   s        r%   r   r   q  s    p 1~~wwqzQ_NA
		!QA
qq5C-0qAE"C#'QU*;$;	=A Q$$r'   c                     [        U SU5      $ )aQ
  
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, an empty array
    is returned. An exception is thrown when it is negative.
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 von 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",
       https://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:

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

>>> window = signal.windows.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 = np.abs(fftshift(A / abs(A).max()))
>>> response = 20 * np.log10(np.maximum(response, 1e-10))
>>> 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]")

rL   r   r*   s     r%   r   r     s    ` 1c3''r'   c           	         [        U 5      (       a  [        R                  " U 5      $ US::  a  [        R                  " U S5      $ US:  a	  [        XS9$ [	        X5      u  p[        R
                  " SU 5      n[        [        R                  " XS-
  -  S-  5      5      nUSUS-    nXES-   X-
  S-
   nX@U-
  S-
  S nSS[        R                  " [        R                  S	SU-  U-  U S-
  -  -   -  5      -   -  n	[        R                  " UR                  5      n
SS[        R                  " [        R                  S
U-  S-   SU-  U-  U S-
  -  -   -  5      -   -  n[        R                  " XU45      n[        X5      $ )a~  Return a Tukey window, also known as a tapered cosine window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
alpha : float, optional
    Shape parameter of the Tukey window, representing the fraction of the
    window inside the cosine tapered region.
    If zero, the Tukey window is equivalent to a rectangular window.
    If one, the Tukey window is equivalent to a Hann window.
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).

References
----------
.. [1] Harris, Fredric J. (Jan 1978). "On the use of Windows for Harmonic
       Analysis with the Discrete Fourier Transform". Proceedings of the
       IEEE 66 (1): 51-83. :doi:`10.1109/PROC.1978.10837`
.. [2] Wikipedia, "Window function",
       https://en.wikipedia.org/wiki/Window_function#Tukey_window

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

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

>>> window = signal.windows.tukey(51)
>>> plt.plot(window)
>>> plt.title("Tukey window")
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("Sample")
>>> plt.ylim([0, 1.1])

>>> 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 Tukey window")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

r   drD   r+   r!   rK   NrL   r.   g       )r&   r3   r4   r   r,   rF   r"   floorr:   r6   shapeconcatenater1   )r$   alphar+   r<   rI   widthn1n2n3w1w2w3r/   s                r%   r   r   '  sU   v 1~~wwqzzwwq#	#AQ_NA
		!QA!S)*E	
1U1WB	
71719	B	
U719:B	BFF255BRqs);$;<==	>B		B	BFF255DJNSVE\1Q35G$GHII	JB
|$AQ$$r'   c                 T   [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " SU 5      n[        R
                  " X0S-
  -  S-
  5      nSSU-  -
  S[        R                  " S[        R                  -  U-  5      -  -   n[        XR5      $ )a  Return a modified Bartlett-Hann window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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:

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

>>> window = signal.windows.barthann(51)
>>> plt.plot(window)
>>> plt.title("Bartlett-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 Bartlett-Hann window")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

r   rD   rL   gףp=
?gQ?gRQ?rC   )	r&   r3   r4   r,   rF   rO   r:   r6   r1   )r$   r+   r<   rI   r=   r/   s         r%   r   r   {  s    Z 1~~wwqzQ_NA
		!QA
&&#g$
%CtczD266!bee)c/#:::AQ$$r'   c                 $    [        XSU-
  /U5      $ )a)  Return a generalized Hamming window.

The generalized Hamming window is constructed by multiplying a rectangular
window by one period of a cosine function [1]_.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
alpha : float
    The window coefficient, :math:`\alpha`
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).

See Also
--------
hamming, hann

Notes
-----
The generalized Hamming window is defined as

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

Both the common Hamming window and Hann window are special cases of the
generalized Hamming window with :math:`\alpha` = 0.54 and :math:`\alpha` =
0.5, respectively [2]_.

References
----------
.. [1] DSPRelated, "Generalized Hamming Window Family",
       https://www.dsprelated.com/freebooks/sasp/Generalized_Hamming_Window_Family.html
.. [2] Wikipedia, "Window function",
       https://en.wikipedia.org/wiki/Window_function
.. [3] Riccardo Piantanida ESA, "Sentinel-1 Level 1 Detailed Algorithm
       Definition",
       https://sentinel.esa.int/documents/247904/1877131/Sentinel-1-Level-1-Detailed-Algorithm-Definition
.. [4] Matthieu Bourbigot ESA, "Sentinel-1 Product Definition",
       https://sentinel.esa.int/documents/247904/1877131/Sentinel-1-Product-Definition

Examples
--------
The Sentinel-1A/B Instrument Processing Facility uses generalized Hamming
windows in the processing of spaceborne Synthetic Aperture Radar (SAR)
data [3]_. The facility uses various values for the :math:`\alpha`
parameter based on operating mode of the SAR instrument. Some common
:math:`\alpha` values include 0.75, 0.7 and 0.52 [4]_. As an example, we
plot these different windows.

>>> import numpy as np
>>> from scipy.signal.windows import general_hamming
>>> from scipy.fft import fft, fftshift
>>> import matplotlib.pyplot as plt

>>> fig1, spatial_plot = plt.subplots()
>>> spatial_plot.set_title("Generalized Hamming Windows")
>>> spatial_plot.set_ylabel("Amplitude")
>>> spatial_plot.set_xlabel("Sample")

>>> fig2, freq_plot = plt.subplots()
>>> freq_plot.set_title("Frequency Responses")
>>> freq_plot.set_ylabel("Normalized magnitude [dB]")
>>> freq_plot.set_xlabel("Normalized frequency [cycles per sample]")

>>> for alpha in [0.75, 0.7, 0.52]:
...     window = general_hamming(41, alpha)
...     spatial_plot.plot(window, label="{:.2f}".format(alpha))
...     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())))
...     freq_plot.plot(freq, response, label="{:.2f}".format(alpha))
>>> freq_plot.legend(loc="upper right")
>>> spatial_plot.legend(loc="upper right")

rD   rW   )r$   rf   r+   s      r%   r   r     s    l !R%Z0#66r'   c                     [        U SU5      $ )a
  Return a Hamming window.

The Hamming window is a taper formed by using a raised cosine with
non-zero endpoints, optimized to minimize the nearest side lobe.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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 Hamming window is defined as

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

The Hamming was named for R. W. Hamming, an associate of J. W. Tukey and
is described in Blackman and Tukey. It was recommended for smoothing the
truncated autocovariance function in the time domain.
Most references to the Hamming 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. 109-110.
.. [3] Wikipedia, "Window function",
       https://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:

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

>>> window = signal.windows.hamming(51)
>>> plt.plot(window)
>>> plt.title("Hamming 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 Hamming window")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

gHzG?r_   r*   s     r%   r   r     s    X 1dC((r'   c                 Z   [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " SU 5      nU S-
  S-  n[
        R                  " U[        R                  " SXE-
  U-  S-  -
  5      -  5      [
        R                  " U5      -  n[        Xc5      $ )a2  Return a Kaiser window.

The Kaiser window is a taper formed by using a Bessel function.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
beta : float
    Shape parameter, determines trade-off between main-lobe width and
    side lobe level. As beta gets large, the window narrows.
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 Kaiser window is defined as

.. math::  w(n) = I_0\left( \beta \sqrt{1-\frac{4n^2}{(M-1)^2}}
           \right)/I_0(\beta)

with

.. math:: \quad -\frac{M-1}{2} \leq n \leq \frac{M-1}{2},

where :math:`I_0` is the modified zeroth-order Bessel function.

The Kaiser was named for Jim Kaiser, who discovered a simple approximation
to the DPSS window based on Bessel functions.
The Kaiser window is a very good approximation to the discrete prolate
spheroidal sequence, or Slepian window, which is the transform which
maximizes the energy in the main lobe of the window relative to total
energy.

The Kaiser can approximate other windows by varying the beta parameter.
(Some literature uses alpha = beta/pi.) [4]_

====  =======================
beta  Window shape
====  =======================
0     Rectangular
5     Similar to a Hamming
6     Similar to a Hann
8.6   Similar to a Blackman
====  =======================

A beta value of 14 is probably a good starting point. Note that as beta
gets large, the window narrows, and so the number of samples needs to be
large enough to sample the increasingly narrow spike, otherwise NaNs will
be returned.

Most references to the Kaiser 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] J. F. Kaiser, "Digital Filters" - Ch 7 in "Systems analysis by
       digital computer", Editors: F.F. Kuo and J.F. Kaiser, p 218-285.
       John Wiley and Sons, New York, (1966).
.. [2] E.R. Kanasewich, "Time Sequence Analysis in Geophysics", The
       University of Alberta Press, 1975, pp. 177-178.
.. [3] Wikipedia, "Window function",
       https://en.wikipedia.org/wiki/Window_function
.. [4] F. J. Harris, "On the use of windows for harmonic analysis with the
       discrete Fourier transform," Proceedings of the IEEE, vol. 66,
       no. 1, pp. 51-83, Jan. 1978. :doi:`10.1109/PROC.1978.10837`.

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

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

>>> window = signal.windows.kaiser(51, beta=14)
>>> plt.plot(window)
>>> plt.title(r"Kaiser window ($\beta$=14)")
>>> 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(r"Frequency response of the Kaiser window ($\beta$=14)")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

r   r!   rK   )	r&   r3   r4   r,   rF   r   i0sqrtr1   )r$   betar+   r<   rI   rf   r/   s          r%   r   r   [  s    V 1~~wwqzQ_NA
		!QAUcME	D2771e(;'C#CDD	E	D	
A Q$$r'   rb   c                R   U(       d  [        S5      eU S:  a  [        R                  " / 5      $ U S-  (       a  [        S5      e[        U S-  S-   U5      n[        R                  " U5      n[        R
                  " USS US   -  5      n[        R                  " XUSSS2   4SS9nU$ )	a/  Return a Kaiser-Bessel derived window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
    Note that this window is only defined for an even
    number of points.
beta : float
    Kaiser window shape parameter.
sym : bool, optional
    This parameter only exists to comply with the interface offered by
    the other window functions and to be callable by `get_window`.
    When True (default), generates a symmetric window, for use in filter
    design.

Returns
-------
w : ndarray
    The window, normalized to fulfil the Princen-Bradley condition.

See Also
--------
kaiser

Notes
-----
It is designed to be suitable for use with the modified discrete cosine
transform (MDCT) and is mainly used in audio signal processing and
audio coding.

.. versionadded:: 1.9.0

References
----------
.. [1] Bosi, Marina, and Richard E. Goldberg. Introduction to Digital
       Audio Coding and Standards. Dordrecht: Kluwer, 2003.
.. [2] Wikipedia, "Kaiser window",
       https://en.wikipedia.org/wiki/Kaiser_window

Examples
--------
Plot the Kaiser-Bessel derived window based on the wikipedia
reference [2]_:

>>> import numpy as np
>>> from scipy import signal
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots()
>>> N = 50
>>> for alpha in [0.64, 2.55, 7.64, 31.83]:
...     ax.plot(signal.windows.kaiser_bessel_derived(2*N, np.pi*alpha),
...             label=f"{alpha=}")
>>> ax.grid(True)
>>> ax.set_title("Kaiser-Bessel derived window")
>>> ax.set_ylabel("Amplitude")
>>> ax.set_xlabel("Sample")
>>> ax.set_xticks([0, N, 2*N-1])
>>> ax.set_xticklabels(["0", "N", "2N+1"])  # doctest: +SKIP
>>> ax.set_yticks([0.0, 0.2, 0.4, 0.6, 0.707, 0.8, 1.0])
>>> fig.legend(loc="center")
>>> fig.tight_layout()
>>> fig.show()
zCKaiser-Bessel Derived windows are only defined for symmetric shapesr!   rC   zHKaiser-Bessel Derived windows are only defined for even number of pointsNr.   r   axis)r#   r3   arrayr   cumsumrs   re   )r$   rt   r+   kaiser_windowcsumhalf_windowr/   s          r%   r   r     s    D 
 	
 
Qxx|	
Q
 	

 16A:t,M99]#D''$s)d2h./K
2%67a@AHr'   c                    [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " SU 5      U S-
  S-  -
  nSU-  U-  n[        R
                  " US-  * U-  5      n[        Xc5      $ )a  Return a Gaussian window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
std : float
    The standard deviation, sigma.
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 Gaussian window is defined as

.. math::  w(n) = e^{ -\frac{1}{2}\left(\frac{n}{\sigma}\right)^2 }

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

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

>>> window = signal.windows.gaussian(51, std=7)
>>> plt.plot(window)
>>> plt.title(r"Gaussian window ($\sigma$=7)")
>>> 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(r"Frequency response of the Gaussian window ($\sigma$=7)")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

r   rD   rK   rC   )r&   r3   r4   r,   rF   expr1   )r$   stdr+   r<   rI   sig2r/   s          r%   r   r   (  ss    j 1~~wwqzQ_NA
		!Q1s7c/)As7S=D
Qw~AQ$$r'   c                 (   [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " SU 5      U S-
  S-  -
  n[        R
                  " S[        R                  " XR-  5      SU-  -  -  5      n[        Xd5      $ )a  Return a window with a generalized Gaussian shape.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
p : float
    Shape parameter.  p = 1 is identical to `gaussian`, p = 0.5 is
    the same shape as the Laplace distribution.
sig : float
    The standard deviation, sigma.
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 generalized Gaussian window is defined as

.. math::  w(n) = e^{ -\frac{1}{2}\left|\frac{n}{\sigma}\right|^{2p} }

the half-power point is at

.. math::  (2 \log(2))^{1/(2 p)} \sigma

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

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

>>> window = signal.windows.general_gaussian(51, p=1.5, sig=7)
>>> plt.plot(window)
>>> plt.title(r"Generalized Gaussian window (p=1.5, $\sigma$=7)")
>>> 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(r"Freq. resp. of the gen. Gaussian "
...           r"window (p=1.5, $\sigma$=7)")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

r   rD   rK   g      rC   )r&   r3   r4   r,   rF   r~   rO   r1   )r$   psigr+   r<   rI   r/   s          r%   r   r   h  st    z 1~~wwqzQ_NA
		!Q1s7c/)A
tbffQWo!a%001AQ$$r'   c           	         [         R                  " U5      S:  a  [        R                  " SSS9  [	        U 5      (       a  [         R
                  " U 5      $ [        X5      u  pU S-
  n[         R                  " SU-  [         R                  " S[         R                  " U5      S-  -  5      -  5      n[         R                  SU  S-  nU[         R                  " [         R                  U-  U -  5      -  n[         R                  " UR                  5      n[         R                  " U[         R                  " XwS	:     5      -  5      XS	:  '   SU S-  -  S	-
  [         R                  " U[         R                  " XwS
:     * 5      -  5      -  XS
:  '   [         R                  " U[         R                  " U[         R                  " U5      S	:*     5      -  5      U[         R                  " U5      S	:*  '   U S-  (       aX  [         R                  " [         R"                  " U5      5      n	U S	-   S-  n
U	SU
 n	[         R$                  " XS	-
  SS
2   U	45      n	OU[         R&                  " S[         R                  -  U -  [         R                  SU  -  5      -  n[         R                  " [         R"                  " U5      5      n	U S-  S	-   n
[         R$                  " XS	-
  SS
2   U	S	U
 45      n	U	[)        U	5      -  n	[+        X5      $ )a
  Return a Dolph-Chebyshev window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
at : float
    Attenuation (in dB).
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 always normalized to 1

Notes
-----
This window optimizes for the narrowest main lobe width for a given order
`M` and sidelobe equiripple attenuation `at`, using Chebyshev
polynomials.  It was originally developed by Dolph to optimize the
directionality of radio antenna arrays.

Unlike most windows, the Dolph-Chebyshev is defined in terms of its
frequency response:

.. math:: W(k) = \frac
          {\cos\{M \cos^{-1}[\beta \cos(\frac{\pi k}{M})]\}}
          {\cosh[M \cosh^{-1}(\beta)]}

where

.. math:: \beta = \cosh \left [\frac{1}{M}
          \cosh^{-1}(10^\frac{A}{20}) \right ]

and 0 <= abs(k) <= M-1. A is the attenuation in decibels (`at`).

The time domain window is then generated using the IFFT, so
power-of-two `M` are the fastest to generate, and prime number `M` are
the slowest.

The equiripple condition in the frequency domain creates impulses in the
time domain, which appear at the ends of the window.

References
----------
.. [1] C. Dolph, "A current distribution for broadside arrays which
       optimizes the relationship between beam width and side-lobe level",
       Proceedings of the IEEE, Vol. 34, Issue 6
.. [2] Peter Lynch, "The Dolph-Chebyshev Window: A Simple Optimal Filter",
       American Meteorological Society (April 1997)
       http://mathsci.ucd.ie/~plynch/Publications/Dolph.pdf
.. [3] F. J. Harris, "On the use of windows for harmonic analysis with the
       discrete Fourier transforms", Proceedings of the IEEE, Vol. 66,
       No. 1, January 1978

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

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

>>> window = signal.windows.chebwin(51, at=100)
>>> plt.plot(window)
>>> plt.title("Dolph-Chebyshev window (100 dB)")
>>> 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 Dolph-Chebyshev window (100 dB)")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

-   a  This window is not suitable for spectral analysis for attenuation values lower than about 45dB because the equivalent noise bandwidth of a Chebyshev window does not grow monotonically with increasing sidelobe attenuation when the attenuation is smaller than about 45 dB.rC   )
stacklevelrD   
   g      4@r   r!   r.   Ny              ?)r3   rO   warningswarnr&   r4   r,   cosharccoshrG   r:   r6   r7   rd   arccosrealsp_fftr   re   r~   maxr1   )r$   atr+   r<   orderrt   r>   xr   r/   rI   s              r%   r   r     sW   l 
vvbzB % "#	$ 1~~wwqzQ_NA GE773;B266":3C,D!EEFD
a
SArvvbeeai!m$$A 	Awwurzz!E(334A!eHa!eqBGGEBJJb&	z4J,J$KKA"fIuryy266!9>1B'CCDAbffQi1n 	1uGGFJJqM"UqLbqENNA!eAbjM1-.sRUU{Qq344GGFJJqM"FQJNNA!eAbjM1Qq623	CF
AQ$$r'   c                    [        U 5      (       a  [        R                  " U 5      $ [        X5      u  p[        R                  " [        R
                  U -  [        R                  " SU 5      S-   -  5      n[        X25      $ )a2  Return a window with a simple cosine shape.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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
-----

.. versionadded:: 0.13.0

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

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

>>> window = signal.windows.cosine(51)
>>> plt.plot(window)
>>> plt.title("Cosine window")
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("Sample")

>>> plt.figure()
>>> A = fft(window, 2047) / (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 cosine window")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")
>>> plt.show()

r   rL   )r&   r3   r4   r,   rU   r6   rF   r1   rA   s       r%   r   r   0  s\    f 1~~wwqzQ_NA
ruuqyBIIaOb012AQ$$r'   c                 L   U(       a  Ub  [        S5      e[        U 5      (       a  [        R                  " U 5      $ [	        X5      u  pUc  U S-
  S-  n[        R
                  " SU 5      n[        R                  " [        R                  " XQ-
  5      * U-  5      n[        Xd5      $ )a  Return an exponential (or Poisson) window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
center : float, optional
    Parameter defining the center location of the window function.
    The default value if not given is ``center = (M-1) / 2``.  This
    parameter must take its default value for symmetric windows.
tau : float, optional
    Parameter defining the decay.  For ``center = 0`` use
    ``tau = -(M-1) / ln(x)`` if ``x`` is the fraction of the window
    remaining at the end.
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 Exponential window is defined as

.. math::  w(n) = e^{-|n-center| / \tau}

References
----------
.. [1] S. Gade and H. Herlufsen, "Windows to FFT analysis (Part I)",
       Technical Review 3, Bruel & Kjaer, 1987.

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

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

>>> M = 51
>>> tau = 3.0
>>> window = signal.windows.exponential(M, tau=tau)
>>> plt.plot(window)
>>> plt.title("Exponential Window (tau=3.0)")
>>> 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, -35, 0])
>>> plt.title("Frequency response of the Exponential window (tau=3.0)")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

This function can also generate non-symmetric windows:

>>> tau2 = -(M-1) / np.log(0.01)
>>> window2 = signal.windows.exponential(M, 0, tau2, False)
>>> plt.figure()
>>> plt.plot(window2)
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("Sample")
z"If sym==True, center must be None.r!   rC   r   )	r#   r&   r3   r4   r,   rF   r~   rO   r1   )r$   centertaur+   r<   rI   r/   s          r%   r   r   l  s    T v!=>>1~~wwqzQ_NA~A#
		!QA
qx  3&'AQ$$r'   c           	      r  ^ ^^ [        T 5      (       a  [        R                  " T 5      $ [        T U5      u  m nSUS-  -  n[        R                  " U5      [        R
                  -  nUS-  US-  US-
  S-  -   -  n[        R                  " SU5      m[        R                  " US-
  5      m[        R                  " T5      n	SU	SSS2'   SU	SSS2'   TT-  n
[        T5       H  u  pX   [        R                  " SX   U-  US-  TS-
  S-  -   -  -
  5      -  nS[        R                  " SX   U
SU -  -
  5      -  [        R                  " SX   XS-   S -  -
  5      -  nX-  TU'   M     UU U4S jnU" [        R                  " T 5      5      nU(       a  S	U" T S-
  S-  5      -  nUU-  n[        UU5      $ )
ai  
Return a Taylor window.

The Taylor window taper function approximates the Dolph-Chebyshev window's
constant sidelobe level for a parameterized number of near-in sidelobes,
but then allows a taper beyond [2]_.

The SAR (synthetic aperture radar) community commonly uses Taylor
weighting for image formation processing because it provides strong,
selectable sidelobe suppression with minimum broadening of the
mainlobe [1]_.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
nbar : int, optional
    Number of nearly constant level sidelobes adjacent to the mainlobe.
sll : float, optional
    Desired suppression of sidelobe level in decibels (dB) relative to the
    DC gain of the mainlobe. This should be a positive number.
norm : bool, optional
    When True (default), divides the window by the largest (middle) value
    for odd-length windows or the value that would occur between the two
    repeated middle values for even-length windows such that all values
    are less than or equal to 1. When False the DC gain will remain at 1
    (0 dB) and the sidelobes will be `sll` dB down.
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
-------
out : array
    The window. When `norm` is True (default), the maximum value is
    normalized to 1 (though the value 1 does not appear if `M` is
    even and `sym` is True).

See Also
--------
chebwin, kaiser, bartlett, blackman, hamming, hann

References
----------
.. [1] W. Carrara, R. Goodman, and R. Majewski, "Spotlight Synthetic
       Aperture Radar: Signal Processing Algorithms" Pages 512-513,
       July 1995.
.. [2] Armin Doerry, "Catalog of Window Taper Functions for
       Sidelobe Control", 2017.
       https://www.researchgate.net/profile/Armin_Doerry/publication/316281181_Catalog_of_Window_Taper_Functions_for_Sidelobe_Control/links/58f92cb2a6fdccb121c9d54d/Catalog-of-Window-Taper-Functions-for-Sidelobe-Control.pdf

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

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

>>> window = signal.windows.taylor(51, nbar=20, sll=100, norm=False)
>>> plt.plot(window)
>>> plt.title("Taylor window (100 dB)")
>>> 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 Taylor window (100 dB)")
>>> plt.ylabel("Normalized magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")

r      rC   rL   r!   Nr.   c                    > SS[         R                  " T[         R                  " S[         R                  -  TS S 2[         R                  4   -  U TS-  -
  S-   -  T-  5      5      -  -   $ )Nr!   rC   rK   rL   )r3   dotr:   r6   newaxis)rI   Fmr$   mas    r%   Wtaylor.<locals>.W+  sb    1RVVBbeeGBq"**}%%q2vcz214!6 7 7 7 	7r'   rD   )r&   r3   r4   r,   r   r6   rF   empty
empty_like	enumerateprodr1   )r$   nbarsllnormr+   r<   BAs2signsm2mimnumerdenomr   r/   scaler   r   s   `                 @@r%   r   r     s   ` 1~~wwqzQ_NA{
 	S2XA


1A	qAqDD3J?*	+B	1d	B	$q&	BMM"EE#A#JE!$Q$K	BB2	BGGAr	1a428a-3G(H$HIIBGGAr#2w.//"''!bfR1Y>N:N2OO2 
7 	
"))A,A aQ!n$	U
Q$$r'   Fc           	         [        U 5      (       a  [        R                  " U 5      $ Uc  Uc  SOSnSnXF;  a  [        SU SU 35      eUc  SnSnOS	n[        R
                  " U5      nS
Us=:  a  U ::  d  O  [        S5      eXS-  :  a  [        S5      eUS
::  a  [        S5      e[        X5      u  p[        U5      U -  n	[        R                  " U 5      n
U S-
  SU
-  -
  S-  S-  [        R                  " S[        R                  -  U	-  5      -  nU
SS X
SS -
  -  S-  n[        R                  " XSX-
  U S-
  4S9u  pUSSS2   nUSS2SSS24   R                  nUSSS2   R                  SS9S
:  n[        U5       H  u  nnU(       d  M  USU-  ==   S-  ss'   M!     [!        SSU -  5      n[        USSS2   5       H,  u  nnXU-  U:     S
   S
:  d  M  USU-  S-   ==   S-  ss'   M.     U(       aX  [#        U5      nSU	-  [        R$                  " SU	-  U
-  5      -  nSU	-  US
'   [        R&                  " UU5      nU(       a  US
   nUS:w  a  XR!                  5       -  nU S-  S
:X  a  US:X  a  U S-  [        U S-  U-   5      -  nO[(        R*                  " US
   5      nSSU -  -
  * [        R                  " SU S-  S-   5      -  nUSS=== S[        R,                  " S[        R                  -  U-  5      -  -  sss& U UR.                  R                  5       -  nUU-  nU(       a  USS2SS24   nU(       a  US
   nU(       a  UW4$ U$ )aN  
Compute the Discrete Prolate Spheroidal Sequences (DPSS).

DPSS (or Slepian sequences) are often used in multitaper power spectral
density estimation (see [1]_). The first window in the sequence can be
used to maximize the energy concentration in the main lobe, and is also
called the Slepian window.

Parameters
----------
M : int
    Window length.
NW : float
    Standardized half bandwidth corresponding to ``2*NW = BW/f0 = BW*M*dt``
    where ``dt`` is taken as 1.
Kmax : int | None, optional
    Number of DPSS windows to return (orders ``0`` through ``Kmax-1``).
    If None (default), return only a single window of shape ``(M,)``
    instead of an array of windows of shape ``(Kmax, M)``.
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.
norm : {2, 'approximate', 'subsample'} | None, optional
    If 'approximate' or 'subsample', then the windows are normalized by the
    maximum, and a correction scale-factor for even-length windows
    is applied either using ``M**2/(M**2+NW)`` ("approximate") or
    a FFT-based subsample shift ("subsample"), see Notes for details.
    If None, then "approximate" is used when ``Kmax=None`` and 2 otherwise
    (which uses the l2 norm).
return_ratios : bool, optional
    If True, also return the concentration ratios in addition to the
    windows.

Returns
-------
v : ndarray, shape (Kmax, M) or (M,)
    The DPSS windows. Will be 1D if `Kmax` is None.
r : ndarray, shape (Kmax,) or float, optional
    The concentration ratios for the windows. Only returned if
    `return_ratios` evaluates to True. Will be 0D if `Kmax` is None.

Notes
-----
This computation uses the tridiagonal eigenvector formulation given
in [2]_.

The default normalization for ``Kmax=None``, i.e. window-generation mode,
simply using the l-infinity norm would create a window with two unity
values, which creates slight normalization differences between even and odd
orders. The approximate correction of ``M**2/float(M**2+NW)`` for even
sample numbers is used to counteract this effect (see Examples below).

For very long signals (e.g., 1e6 elements), it can be useful to compute
windows orders of magnitude shorter and use interpolation (e.g.,
`scipy.interpolate.interp1d`) to obtain tapers of length `M`,
but this in general will not preserve orthogonality between the tapers.

.. versionadded:: 1.1

References
----------
.. [1] Percival DB, Walden WT. Spectral Analysis for Physical Applications:
   Multitaper and Conventional Univariate Techniques.
   Cambridge University Press; 1993.
.. [2] Slepian, D. Prolate spheroidal wave functions, Fourier analysis, and
   uncertainty V: The discrete case. Bell System Technical Journal,
   Volume 57 (1978), 1371430.
.. [3] Kaiser, JF, Schafer RW. On the Use of the I0-Sinh Window for
   Spectrum Analysis. IEEE Transactions on Acoustics, Speech and
   Signal Processing. ASSP-28 (1): 105-107; 1980.

Examples
--------
We can compare the window to `kaiser`, which was invented as an alternative
that was easier to calculate [3]_ (example adapted from
`here <https://ccrma.stanford.edu/~jos/sasp/Kaiser_DPSS_Windows_Compared.html>`_):

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.signal import windows, freqz
>>> M = 51
>>> fig, axes = plt.subplots(3, 2, figsize=(5, 7))
>>> for ai, alpha in enumerate((1, 3, 5)):
...     win_dpss = windows.dpss(M, alpha)
...     beta = alpha*np.pi
...     win_kaiser = windows.kaiser(M, beta)
...     for win, c in ((win_dpss, 'k'), (win_kaiser, 'r')):
...         win /= win.sum()
...         axes[ai, 0].plot(win, color=c, lw=1.)
...         axes[ai, 0].set(xlim=[0, M-1], title=r'$\alpha$ = %s' % alpha,
...                         ylabel='Amplitude')
...         w, h = freqz(win)
...         axes[ai, 1].plot(w, 20 * np.log10(np.abs(h)), color=c, lw=1.)
...         axes[ai, 1].set(xlim=[0, np.pi],
...                         title=r'$\beta$ = %0.2f' % beta,
...                         ylabel='Magnitude (dB)')
>>> for ax in axes.ravel():
...     ax.grid(True)
>>> axes[2, 1].legend(['DPSS', 'Kaiser'])
>>> fig.tight_layout()
>>> plt.show()

And here are examples of the first four windows, along with their
concentration ratios:

>>> M = 512
>>> NW = 2.5
>>> win, eigvals = windows.dpss(M, NW, 4, return_ratios=True)
>>> fig, ax = plt.subplots(1)
>>> ax.plot(win.T, linewidth=1.)
>>> ax.set(xlim=[0, M-1], ylim=[-0.1, 0.1], xlabel='Samples',
...        title='DPSS, M=%d, NW=%0.1f' % (M, NW))
>>> ax.legend(['win[%d] (%0.4f)' % (ii, ratio)
...            for ii, ratio in enumerate(eigvals)])
>>> fig.tight_layout()
>>> plt.show()

Using a standard :math:`l_{\infty}` norm would produce two unity values
for even `M`, but only one unity value for odd `M`. This produces uneven
window power that can be counteracted by the approximate correction
``M**2/float(M**2+NW)``, which can be selected by using
``norm='approximate'`` (which is the same as ``norm=None`` when
``Kmax=None``, as is the case here). Alternatively, the slower
``norm='subsample'`` can be used, which uses subsample shifting in the
frequency domain (FFT) to compute the correction:

>>> Ms = np.arange(1, 41)
>>> factors = (50, 20, 10, 5, 2.0001)
>>> energy = np.empty((3, len(Ms), len(factors)))
>>> for mi, M in enumerate(Ms):
...     for fi, factor in enumerate(factors):
...         NW = M / float(factor)
...         # Corrected using empirical approximation (default)
...         win = windows.dpss(M, NW)
...         energy[0, mi, fi] = np.sum(win ** 2) / np.sqrt(M)
...         # Corrected using subsample shifting
...         win = windows.dpss(M, NW, norm='subsample')
...         energy[1, mi, fi] = np.sum(win ** 2) / np.sqrt(M)
...         # Uncorrected (using l-infinity norm)
...         win /= win.max()
...         energy[2, mi, fi] = np.sum(win ** 2) / np.sqrt(M)
>>> fig, ax = plt.subplots(1)
>>> hs = ax.plot(Ms, energy[2], '-o', markersize=4,
...              markeredgecolor='none')
>>> leg = [hs[-1]]
>>> for hi, hh in enumerate(hs):
...     h1 = ax.plot(Ms, energy[0, :, hi], '-o', markersize=4,
...                  color=hh.get_color(), markeredgecolor='none',
...                  alpha=0.66)
...     h2 = ax.plot(Ms, energy[1, :, hi], '-o', markersize=4,
...                  color=hh.get_color(), markeredgecolor='none',
...                  alpha=0.33)
...     if hi == len(hs) - 1:
...         leg.insert(0, h1[0])
...         leg.insert(0, h2[0])
>>> ax.set(xlabel='M (samples)', ylabel=r'Power / $\sqrt{M}$')
>>> ax.legend(leg, ['Uncorrected', r'Corrected: $\frac{M^2}{M^2+NW}$',
...                 'Corrected (subsample)'])
>>> fig.tight_layout()

NapproximaterC   )rC   r   	subsampleznorm must be one of z, got Tr!   Fr   z+Kmax must be greater than 0 and less than MrK   zNW must be less than M/2.zNW must be positivei)selectselect_ranger.   rv   gHz>rD      y             )r&   r3   r4   r#   operatorindexr,   r@   rF   r:   r6   r   eigh_tridiagonalTsumr   r   _fftautocorrsincr   r   rfftr~   r   )r$   NWKmaxr+   r   return_ratiosknown_norms	singletonr<   r   nidxra   er/   windowsfix_evenr   fthreshdpss_rxxrratios
correctionsshifts                            r%   r   r   9  so   F 1~~wwqz| $}!1K/}F4&IJJ|		>>$Dt=q=FGG	rTz455	Qw.//Q_NAb	AA99Q<D( a%!d(
b	 Q&BEE	A)>>AQRAQRL!B&A ((	S!a%'8:JA	$B$Aa2g  G !  a (1,H(#11AENb N $ rAvF'!$Q$-(1UV^Q!#AEAI"$ ) (EBGGAEDL))1u!!$AYFqy;;= q5A:}$TE!Q$)$44
KK
+bd(bii1a4!8&<<!"RVVC"%%K%$7888-
z!G!SbS&/!* -GV:7:r'   c                t   [        U 5      (       a  [        R                  " U 5      $ [        X5      u  pS nU S-  S:X  a6  U" U S-  U 5      n[        R                  [        R
                  " U5      U4   nO9U" U S-   S-  U 5      n[        R                  [        R
                  " U5      SU4   n[        XR5      $ )a  Return a Lanczos window also known as a sinc window.

Parameters
----------
M : int
    Number of points in the output window. If zero, an empty array
    is returned. An exception is thrown when it is negative.
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 Lanczos window is defined as

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

where

.. math::  sinc(x) = \frac{\sin(\pi x)}{\pi x}

The Lanczos window has reduced Gibbs oscillations and is widely used for
filtering climate timeseries with good properties in the physical and
spectral domains.

.. versionadded:: 1.10

References
----------
.. [1] Lanczos, C., and Teichmann, T. (1957). Applied analysis.
       Physics Today, 10, 44.
.. [2] Duchon C. E. (1979) Lanczos Filtering in One and Two Dimensions.
       Journal of Applied Meteorology, Vol 18, pp 1016-1022.
.. [3] Thomson, R. E. and Emery, W. J. (2014) Data Analysis Methods in
       Physical Oceanography (Third Edition), Elsevier, pp 593-637.
.. [4] Wikipedia, "Window function",
       http://en.wikipedia.org/wiki/Window_function

Examples
--------
Plot the window

>>> import numpy as np
>>> from scipy.signal.windows import lanczos
>>> from scipy.fft import fft, fftshift
>>> import matplotlib.pyplot as plt
>>> fig, ax = plt.subplots(1)
>>> window = lanczos(51)
>>> ax.plot(window)
>>> ax.set_title("Lanczos window")
>>> ax.set_ylabel("Amplitude")
>>> ax.set_xlabel("Sample")
>>> fig.tight_layout()
>>> plt.show()

and its frequency response:

>>> fig, ax = plt.subplots(1)
>>> 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())))
>>> ax.plot(freq, response)
>>> ax.set_xlim(-0.5, 0.5)
>>> ax.set_ylim(-120, 0)
>>> ax.set_title("Frequency response of the lanczos window")
>>> ax.set_ylabel("Normalized magnitude [dB]")
>>> ax.set_xlabel("Normalized frequency [cycles per sample]")
>>> fig.tight_layout()
>>> plt.show()
c                 n    [         R                  " S[         R                  " X5      -  US-
  -  S-
  5      $ )NrK   r!   rD   )r3   r   rF   )rI   r   s     r%   _calc_right_side_lanczos)lanczos.<locals>._calc_right_side_lanczos  s,    wwrBIIaO+q1u5;<<r'   rC   r   r!   rD   )r&   r3   r4   r,   rG   flipr1   )r$   r+   r<   r   whr/   s         r%   r   r   <  s    \ 1~~wwqzQ_NA
= 	1uz%ac1-EE"''"+r/"%qsAgq1EE"''"+sB&'Q$$r'   c                     U R                   S   n[        R                  " SU-  S-
  5      n[        R                  " XSS9n[        R                  " X3R                  5       -  US9SS2SU24   nU$ )z@Compute the autocorrelation of a real array and crop the result.r.   rC   r!   rv   )rI   N)rd   r   next_fast_lenr   irfftconj)r   Nuse_Nx_fftcxys        r%   r   r     sd    	A  1Q'EKKr*E
,,uzz|+u
5a!e
<C Jr'   )r   brthanbth)r   bartbrt)r
   blackblk)r   	blackharrbkh)r	   bmanbmn)r   boxr4   rectrectangular)r   cheb)r   
halfcosine)r   )r   poisson)r   flatflt)r   gaussgss)zgeneral cosiner   )zgeneral gaussianr   zgeneral gaussgeneral_gaussggs)zgeneral hammingr   )r   hammham)r   han))r   ksr)zkaiser bessel derivedkbd)r   r   )r   nutlnut)r   parzpar)r   	taylorwin)triangler   tri)r   tukr!   c                    U(       + n [        U 5      n[        nX4nU" US
U06$ ! [        [        4 a  nSn[	        U [
        5      (       a  U S   n	[        U 5      S:  a  U SS nOU[	        U [        5      (       a  U [        ;   a  [        SU -   S-   5      UeU n	O![        [        [        U 5      5       S35      Ue [        U	   nO! [         a  n[        S5      UeSnAff = fU[        L a  U4U-   S	-   n SnANU4U-   n SnANSnAff = f)a  
Return a window of a given length and type.

Parameters
----------
window : string, float, or tuple
    The type of window to create. See below for more details.
Nx : int
    The number of samples in the window.
fftbins : bool, optional
    If True (default), create a "periodic" window, ready to use with
    `ifftshift` and be multiplied by the result of an FFT (see also
    :func:`~scipy.fft.fftfreq`).
    If False, create a "symmetric" window, for use in filter design.

Returns
-------
get_window : ndarray
    Returns a window of length `Nx` and type `window`

Notes
-----
Window types:

- `~scipy.signal.windows.boxcar`
- `~scipy.signal.windows.triang`
- `~scipy.signal.windows.blackman`
- `~scipy.signal.windows.hamming`
- `~scipy.signal.windows.hann`
- `~scipy.signal.windows.bartlett`
- `~scipy.signal.windows.flattop`
- `~scipy.signal.windows.parzen`
- `~scipy.signal.windows.bohman`
- `~scipy.signal.windows.blackmanharris`
- `~scipy.signal.windows.nuttall`
- `~scipy.signal.windows.barthann`
- `~scipy.signal.windows.cosine`
- `~scipy.signal.windows.exponential`
- `~scipy.signal.windows.tukey`
- `~scipy.signal.windows.taylor`
- `~scipy.signal.windows.lanczos`
- `~scipy.signal.windows.kaiser` (needs beta)
- `~scipy.signal.windows.kaiser_bessel_derived` (needs beta)
- `~scipy.signal.windows.gaussian` (needs standard deviation)
- `~scipy.signal.windows.general_cosine` (needs weighting coefficients)
- `~scipy.signal.windows.general_gaussian` (needs power, width)
- `~scipy.signal.windows.general_hamming` (needs window coefficient)
- `~scipy.signal.windows.dpss` (needs normalized half-bandwidth)
- `~scipy.signal.windows.chebwin` (needs attenuation)


If the window requires no parameters, then `window` can be a string.

If the window requires parameters, then `window` must be a tuple
with the first argument the string name of the window, and the next
arguments the needed parameters.

If `window` is a floating point number, it is interpreted as the beta
parameter of the `~scipy.signal.windows.kaiser` window.

Each of the window types listed above is also the name of
a function that can be called directly to create a window of
that type.

Examples
--------
>>> from scipy import signal
>>> signal.get_window('triang', 7)
array([ 0.125,  0.375,  0.625,  0.875,  0.875,  0.625,  0.375])
>>> signal.get_window(('kaiser', 4.0), 9)
array([ 0.08848053,  0.29425961,  0.56437221,  0.82160913,  0.97885093,
        0.97885093,  0.82160913,  0.56437221,  0.29425961])
>>> signal.get_window(('exponential', None, 1.), 9)
array([ 0.011109  ,  0.03019738,  0.082085  ,  0.22313016,  0.60653066,
        0.60653066,  0.22313016,  0.082085  ,  0.03019738])
>>> signal.get_window(4.0, 9)
array([ 0.08848053,  0.29425961,  0.56437221,  0.82160913,  0.97885093,
        0.97885093,  0.82160913,  0.56437221,  0.29425961])

r)   r   r!   NzThe 'z6' window needs one or more parameters -- pass a tuple.z! as window type is not supported.zUnknown window type.)Nr+   )r@   r   	TypeErrorr#   
isinstancetupler9   str_needs_paramtype
_win_equivKeyErrorr   )
windowNxfftbinsr+   rt   winfuncparamsr   argswinstrs
             r%   r   r     s:   b +CV}6 F$$$; z" "fe$$AYF6{Qabz$$% 6!1 5D "D EJKL  tF|$%%FGINOP	< (G 	<34!;	< d?UT\G+FUT\F1"s?   % DBD<	CD
C!CC!!D;DD)T)rL   T)NrD   T)r      TT)NTNF)2__doc__r   r   numpyr3   scipyr   r   r   r   __all__r&   r,   r1   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   _win_equiv_rawr	  itemsr>   vkeysetr  updater   r)   r'   r%   <module>r     s   $    0 0,U%p3%l>%B>%B5%pS6l9Px-H`<%~`%FP(fQ%h5%pV7rL)^t%n +/ Sl=%@D%P}%@9%xV%rq%h@;F  _%D	!He#4(E!2 !8U"3 +^U,C	
 !' '4 vuo d| e 4 % 0 !8T"2 )>4*@13CT2J!" +_d,C#$ % 0%& dE]'( ~'<d&C!5)!(% 0 &$e_$*E?en7> 
  "DAqA$
3  #
 u  "DAqttA #
q%r'   