
    tKg>                         d dl Z d dlZd dlmZ d dlmZ d dlmZ g dZ	dZ
d Zd Zdd	Zdd
Zd Zd ZddZddZddZy)    N)eig)comb)convolve)daubqmfcascademorletrickermorlet2cwtzvscipy.signal.%s is deprecated in SciPy 1.12 and will be removed
in SciPy 1.15. We recommend using PyWavelets instead.
c           	      ,   t        j                  t        dz  t        d       t        j
                  }| dk  rt        d      | dk(  r"d |d      z  }t	        j                  ||g      S | dk(  r; |d      dz  } |d      }|t	        j                  d|z   d|z   d|z
  d|z
  g      z  S | dk(  rd |d	      z  }d
 |d|z         dz  z   d |d       ||dz
        z   z  dz  z
  }t	        j                  |      } |d      dz  }t	        j                  d|z
  d|z
  z        }t	        j                  ||z        }dt	        j                  |      z  }	||z  t	        j                  |d|z  |	z
  d|z  d|	z  z
  dz   |d|	z  z
  dz   d|	z
  dg      z  S | dk  rg| dk  rGt        |       D 
cg c]  }
t        | dz
  |
z   |
d       c}
ddd   }t	        j                  |      }nOt        |       D 
cg c]  }
t        | dz
  |
z   |
d      d|
z  z   c}
ddd   }t	        j                  |      dz  }t	        j                  ddg      | z  }t	        j                  dg      }t        | dz
        D ]@  }
||
   }d |||dz
  z        z  }dd|z  z
  }||z   }t        |      dk  r||z
  }|d| gz  }B |t	        j                  |      z  }|t	        j                  |      z   |d      z  }|j                   ddd   S t        d      c c}
w c c}
w )a  
    The coefficients for the FIR low-pass filter producing Daubechies wavelets.

    .. deprecated:: 1.12.0

        scipy.signal.daub is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

    p>=1 gives the order of the zero at f=1/2.
    There are 2p filter coefficients.

    Parameters
    ----------
    p : int
        Order of the zero at f=1/2, can have values from 1 to 34.

    Returns
    -------
    daub : ndarray
        Return

    r      
stacklevel   zp must be at least 1.         
   g      ?                    ?#   )exactNg      @   z<Polynomial factorization does not work well for p too large.)warningswarn_msgDeprecationWarningnpsqrt
ValueErrorarrayconjrealranger   rootspoly1dabssumc)pr"   r,   ftmpz1z1cd0a0a1kPyjqyvalpartconsts                    Z/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/scipy/signal/_wavelets.pyr   r      s7   . MM$-!3B77D1u011AvQKxxA	
aGaKG288QUAE1q5!a%8999	
a48m4S>A%%d2hcBh.G(H1(LLggbkGaKWWa"fS)*WWR#X_2v"a"frk1r6AF?Q3F"$q2v+/1r61"> ? ? 	?	
Rr66;Ah?ha!eai!,h?"EA!B  ($"Q a!eai!,sAv5"$$(bD*A!qB IIq!fq IIqcNq1uAa5DtDD1H-..DDLEBB1}T\QHA  
Nq	MDG#ss4R4y 1 2 	21 @$s   ,L3!Lc                     t        j                  t        dz  t        d       t	        |       dz
  }t        |dz         D cg c]  }ddd|dz      }}| ddd   t        j                  |      z  S c c}w )a  
    Return high-pass qmf filter from low-pass

    .. deprecated:: 1.12.0

        scipy.signal.qmf is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

    Parameters
    ----------
    hk : array_like
        Coefficients of high-pass filter.

    Returns
    -------
    array_like
        High-pass filter coefficients.

    r   r   r   r   r   r   r   N)r   r   r   r    lenr'   r!   r$   )hkNr5   asgns       r<   r   r   \   so    ( MM$, 2qAB!A*/A,7,QbM!a% ,D7dd8bhhtn$$ 8s   A4c           	      h   t        j                  t        dz  t        d       t	        |       dz
  }|dt        j                  |dz         z
  kD  rt        d      |dk  rt        d      t
        j                  d|d|f   \  }}t        j                  d      }t
        j                  | d	f   }t        |       }t
        j                  |d	f   }t        j                  d|z  |z
  d
|dz         }	t        j                  d|z  |z
  dz   d
|dz         }
t        j                  dd||fd      }t        j                  ||	d	      |d<   t        j                  ||
d	      |d<   t        j                  ||	d	      |d<   t        j                  ||
d	      |d<   ||z  }t        j                  d	|d|z  z  t               d|z  z  }d	|z  }d	|z  }t#        |d         \  }}t        j$                  t        j&                  |dz
              }t        j(                  |dd|f         }t        j*                  |      }|d	k  r| }| }d||z  i}t        j,                  |d   |d         |d<   d|z  }|d   |dd|<   |d   |d|dz
  z  d|<   t        j,                  |d   |d         |dd|<   t        j,                  |d   |d         |d|dz
  z  d|<   dg}t/        d|dz         D ]  }dD cg c]  }|D ]	  }d||fz    }}}d||z
  z  }|D ]  }d	}t/        |      D ]  }||   dk(  s|d|dz
  |z
  z  z  } ||dd    }t1        |d	         }t        j,                  |d	|f   |      } | ||<   | |||z  d|<   t        j,                  |d|f   |      |||z  d|<    |} |||fS c c}}w )a  
    Return (x, phi, psi) at dyadic points ``K/2**J`` from filter coefficients.

    .. deprecated:: 1.12.0

        scipy.signal.cascade is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

    Parameters
    ----------
    hk : array_like
        Coefficients of low-pass filter.
    J : int, optional
        Values will be computed at grid points ``K/2**J``. Default is 7.

    Returns
    -------
    x : ndarray
        The dyadic points ``K/2**J`` for ``K=0...N * (2**J)-1`` where
        ``len(hk) = len(gk) = N+1``.
    phi : ndarray
        The scaling function ``phi(x)`` at `x`:
        ``phi(x) = sum(hk * phi(2x-k))``, where k is from 0 to N.
    psi : ndarray, optional
        The wavelet function ``psi(x)`` at `x`:
        ``phi(x) = sum(gk * phi(2x-k))``, where k is from 0 to N.
        `psi` is only returned if `gk` is not None.

    Notes
    -----
    The algorithm uses the vector cascade algorithm described by Strang and
    Nguyen in "Wavelets and Filter Banks".  It builds a dictionary of values
    and slices for quick reuse.  Then inserts vectors into final vector at the
    end.

    r   r   r   r      zToo many levels.zToo few levels.Nr   r   d)r   r   r>   )r   r   )r   r   dtype01z%d%s)r   r   r   r    r?   r!   log2r#   ogridr"   r_r   clipemptytakearangefloatr   argminabsoluter&   r+   dotr'   int)!r@   JrA   nnkks2thkgktgkindx1indx2mxphipsilamvindsmbitdicstepprevkeyslevelxxyynewkeysfackeynumpospastphiiitemps!                                    r<   r   r   w   s   J MM$"$61EB!A	BQ+,,	A*++ XXbqb"1"fFB	B
%%A,C	RB
%%A,CGGAFRKQU+EGGAFRK!ORQ/E
!Q1s#Aggc5!$AdGggc5!$AdGggc5!$AdGggc5!$AdGGA 			!Q!q&\/16:A
a%C
a%C 4\FC
))BKKa(
)C 	!S&	A 
B	AvBS1r6]F&&4&+.F3K6D+C$K &sCq1u&&4&+.C$K "qws <Cq1u
 uHq!a%/5Iv"6RH$$vIAICCU|s8s?A%!)c/23C $ SWoGSVB66!ArE(G,DF3K#'Cc	4 #%66!ArE(G#<Cc	4    !" c3;! Js   0N.c                    t        j                  t        dz  t        d       t	        j
                  | dz  t        j                  z  |dz  t        j                  z  |       }t	        j                  d|z  |z        }|r|t	        j                  d|dz  z        z  }|t	        j                  d|dz  z        t        j                  dz  z  z  }|S )a%  
    Complex Morlet wavelet.

    .. deprecated:: 1.12.0

        scipy.signal.morlet is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

    Parameters
    ----------
    M : int
        Length of the wavelet.
    w : float, optional
        Omega0. Default is 5
    s : float, optional
        Scaling factor, windowed from ``-s*2*pi`` to ``+s*2*pi``. Default is 1.
    complete : bool, optional
        Whether to use the complete or the standard version.

    Returns
    -------
    morlet : (M,) ndarray

    See Also
    --------
    morlet2 : Implementation of Morlet wavelet, compatible with `cwt`.
    scipy.signal.gausspulse

    Notes
    -----
    The standard version::

        pi**-0.25 * exp(1j*w*x) * exp(-0.5*(x**2))

    This commonly used wavelet is often referred to simply as the
    Morlet wavelet.  Note that this simplified version can cause
    admissibility problems at low values of `w`.

    The complete version::

        pi**-0.25 * (exp(1j*w*x) - exp(-0.5*(w**2))) * exp(-0.5*(x**2))

    This version has a correction
    term to improve admissibility. For `w` greater than 5, the
    correction term is negligible.

    Note that the energy of the return wavelet is not normalised
    according to `s`.

    The fundamental frequency of this wavelet in Hz is given
    by ``f = 2*s*w*r / M`` where `r` is the sampling rate.

    Note: This function was created before `cwt` and is not compatible
    with it.

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

    >>> M = 100
    >>> s = 4.0
    >>> w = 2.0
    >>> wavelet = signal.morlet(M, s, w)
    >>> plt.plot(wavelet.real, label="real")
    >>> plt.plot(wavelet.imag, label="imag")
    >>> plt.legend()
    >>> plt.show()

    r	   r   r   r               п)r   r   r   r    r!   linspacepiexp)Mwscompleter`   outputs         r<   r	   r	      s    N MM$/#5!D
QBFRUUNAEBEEM15AVVBFQJF"&&A''
bffTQT]#beeen44FM    c                 `    t        j                  t        dz  t        d       t	        | |      S )a  
    Return a Ricker wavelet, also known as the "Mexican hat wavelet".

    .. deprecated:: 1.12.0

        scipy.signal.ricker is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

    It models the function:

        ``A * (1 - (x/a)**2) * exp(-0.5*(x/a)**2)``,

    where ``A = 2/(sqrt(3*a)*(pi**0.25))``.

    Parameters
    ----------
    points : int
        Number of points in `vector`.
        Will be centered around 0.
    a : scalar
        Width parameter of the wavelet.

    Returns
    -------
    vector : (N,) ndarray
        Array of length `points` in shape of ricker curve.

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

    >>> points = 100
    >>> a = 4.0
    >>> vec2 = signal.ricker(points, a)
    >>> print(len(vec2))
    100
    >>> plt.plot(vec2)
    >>> plt.show()

    r
   r   r   )r   r   r   r    _ricker)pointsas     r<   r
   r
   <  s'    T MM$/#5!D61r   c                    dt        j                  d|z        t         j                  dz  z  z  }|dz  }t        j                  d|       | dz
  dz  z
  }|dz  }d||z  z
  }t        j                  | d|z  z        }||z  |z  }|S )Nr   r   g      ?r         ?r   )r!   r"   ry   rP   rz   )	r   r   Awsqvecxsqmodgausstotals	            r<   r   r   j  s    	RWWQU^ruud{+,A
Q$C
))Av
&3,!!3
3C
q&CsSy=CFFC41s7#$EGeOELr   c                 `   t        j                  t        dz  t        d       t	        j
                  d|       | dz
  dz  z
  }||z  }t	        j                  d|z  |z        t	        j                  d|dz  z        z  t        j                  dz  z  }t	        j                  d	|z        |z  }|S )
a  
    Complex Morlet wavelet, designed to work with `cwt`.

    .. deprecated:: 1.12.0

        scipy.signal.morlet2 is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

    Returns the complete version of morlet wavelet, normalised
    according to `s`::

        exp(1j*w*x/s) * exp(-0.5*(x/s)**2) * pi**(-0.25) * sqrt(1/s)

    Parameters
    ----------
    M : int
        Length of the wavelet.
    s : float
        Width parameter of the wavelet.
    w : float, optional
        Omega0. Default is 5

    Returns
    -------
    morlet : (M,) ndarray

    See Also
    --------
    morlet : Implementation of Morlet wavelet, incompatible with `cwt`

    Notes
    -----

    .. versionadded:: 1.4.0

    This function was designed to work with `cwt`. Because `morlet2`
    returns an array of complex numbers, the `dtype` argument of `cwt`
    should be set to `complex128` for best results.

    Note the difference in implementation with `morlet`.
    The fundamental frequency of this wavelet in Hz is given by::

        f = w*fs / (2*s*np.pi)

    where ``fs`` is the sampling rate and `s` is the wavelet width parameter.
    Similarly we can get the wavelet width parameter at ``f``::

        s = w*fs / (2*f*np.pi)

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import signal
    >>> import matplotlib.pyplot as plt

    >>> M = 100
    >>> s = 4.0
    >>> w = 2.0
    >>> wavelet = signal.morlet2(M, s, w)
    >>> plt.plot(abs(wavelet))
    >>> plt.show()

    This example shows basic use of `morlet2` with `cwt` in time-frequency
    analysis:

    >>> t, dt = np.linspace(0, 1, 200, retstep=True)
    >>> fs = 1/dt
    >>> w = 6.
    >>> sig = np.cos(2*np.pi*(50 + 10*t)*t) + np.sin(40*np.pi*t)
    >>> freq = np.linspace(1, fs/2, 100)
    >>> widths = w*fs / (2*freq*np.pi)
    >>> cwtm = signal.cwt(sig, signal.morlet2, widths, w=w)
    >>> plt.pcolormesh(t, freq, np.abs(cwtm), cmap='viridis', shading='gouraud')
    >>> plt.show()

    r   r   r   r   r   r   rv   rw   r   )	r   r   r   r    r!   rP   rz   ry   r"   )r{   r}   r|   r`   waveletr   s         r<   r   r   u  s    Z MM$"$61E
		!Q1s7a-'A	AAffR!VaZ 266$A+#66GGWWQqS\G#FMr   c                 f    t        j                  t        dz  t        d       t	        | |||fi |S )aR
  
    Continuous wavelet transform.

    .. deprecated:: 1.12.0

        scipy.signal.cwt is deprecated in SciPy 1.12 and will be removed
        in SciPy 1.15. We recommend using PyWavelets instead.

    Performs a continuous wavelet transform on `data`,
    using the `wavelet` function. A CWT performs a convolution
    with `data` using the `wavelet` function, which is characterized
    by a width parameter and length parameter. The `wavelet` function
    is allowed to be complex.

    Parameters
    ----------
    data : (N,) ndarray
        data on which to perform the transform.
    wavelet : function
        Wavelet function, which should take 2 arguments.
        The first argument is the number of points that the returned vector
        will have (len(wavelet(length,width)) == length).
        The second is a width parameter, defining the size of the wavelet
        (e.g. standard deviation of a gaussian). See `ricker`, which
        satisfies these requirements.
    widths : (M,) sequence
        Widths to use for transform.
    dtype : data-type, optional
        The desired data type of output. Defaults to ``float64`` if the
        output of `wavelet` is real and ``complex128`` if it is complex.

        .. versionadded:: 1.4.0

    kwargs
        Keyword arguments passed to wavelet function.

        .. versionadded:: 1.4.0

    Returns
    -------
    cwt: (M, N) ndarray
        Will have shape of (len(widths), len(data)).

    Notes
    -----

    .. versionadded:: 1.4.0

    For non-symmetric, complex-valued wavelets, the input signal is convolved
    with the time-reversed complex-conjugate of the wavelet data [1].

    ::

        length = min(10 * width[ii], len(data))
        cwt[ii,:] = signal.convolve(data, np.conj(wavelet(length, width[ii],
                                        **kwargs))[::-1], mode='same')

    References
    ----------
    .. [1] S. Mallat, "A Wavelet Tour of Signal Processing (3rd Edition)",
        Academic Press, 2009.

    Examples
    --------
    >>> import numpy as np
    >>> from scipy import signal
    >>> import matplotlib.pyplot as plt
    >>> t = np.linspace(-1, 1, 200, endpoint=False)
    >>> sig  = np.cos(2 * np.pi * 7 * t) + signal.gausspulse(t - 0.4, fc=2)
    >>> widths = np.arange(1, 31)
    >>> cwtmatr = signal.cwt(sig, signal.ricker, widths)

    .. note:: For cwt matrix plotting it is advisable to flip the y-axis

    >>> cwtmatr_yflip = np.flipud(cwtmatr)
    >>> plt.imshow(cwtmatr_yflip, extent=[-1, 1, 1, 31], cmap='PRGn', aspect='auto',
    ...            vmax=abs(cwtmatr).max(), vmin=-abs(cwtmatr).max())
    >>> plt.show()
    r   r   r   )r   r   r   r    _cwt)datar   widthsrG   kwargss        r<   r   r     s0    ` MM$, 2qAgvu777r   c                    |Wt        j                   |d|d   fi |      j                  j                  dv rt         j                  }nt         j
                  }t        j                  t        |      t        |       f|      }t        |      D ]\  \  }}t        j                  d|z  t        |       g      }t        j                   |||fi |d d d         }	t        | |	d      ||<   ^ |S )	Nr   r   FDGrF   r   r   same)mode)r!   asarrayrG   char
complex128float64rN   r?   	enumerateminr%   r   )
r   r   r   rG   r   r   re   widthrA   wavelet_datas
             r<   r   r     s    }::ga5f56<<AAUJMMEJJEXXs6{CI.e<F'
UFFBJD	*+wwwq%:6:4R4@At\?s ( Mr   )   )g      @r   T)   )N)r   numpyr!   scipy.linalgr   scipy.specialr   scipy.signalr   __all__r   r   r   r   r	   r
   r   r   r   r    r   r<   <module>r      sX        !
J
I2X%6nbQh+\SlQ8hr   