U
    ?h                  
   @   s   d Z ddlmZmZmZ ddlZddlZddlm	Z	 ddl
mZmZmZ ddd	d
ddddddg
ZdZdd Zdd Zdd Zdd Zdd ZdddZd ddZd!dd	Zd"dd
Zdd Zdd ZdS )#z"
Other wavelet related functions.
    )divisionprint_functionabsolute_importN)fft   )DiscreteContinuousWaveletWaveletContinuousWaveletintegrate_waveletcentral_frequencyscale2frequencyfrequency2scaleqmforthogonal_filter_bankintwavecentrfrqscal2frqorthfiltzT`{old}` has been renamed to `{new}` and will be removed in a future version of pywt.c                 C   s   t | }||9 }|S )N)npZcumsum)ZarrstepZintegral r   A/var/www/html/venv/lib/python3.8/site-packages/pywt/_functions.py
_integrate   s    
r   c                  O   s$   t jddd}t|t t| |S )Nr   r
   oldnew)_DEPRECATION_MSGformatwarningswarnDeprecationWarningr
   argskwargsmsgr   r   r   r   $   s    c                  O   s$   t jddd}t|t t| |S )Nr   r   r   )r   r   r   r   r    r   r!   r   r   r   r   *   s    c                  O   s$   t jddd}t|t t| |S )Nr   r   r   )r   r   r   r   r    r   r!   r   r   r   r   0   s    c                  O   s$   t jddd}t|t t| |S )Nr   r   r   )r   r   r   r   r    r   r!   r   r   r   r   6   s       c                 C   s,  t | ttfkr"d}t|t nt| ttfs8t	| } t | ttfkrt
| d t
| d  }}|d |d  }t|||fS | |}t|dkr|\}}|d |d  }t|||fS t|dkr|\}}}|d |d  }t|||fS |\}}	}
}}|d |d  }t|	|t|||fS dS )ac  
    Integrate `psi` wavelet function from -Inf to x using the rectangle
    integration method.

    Parameters
    ----------
    wavelet : Wavelet instance or str
        Wavelet to integrate.  If a string, should be the name of a wavelet.
    precision : int, optional
        Precision that will be used for wavelet function
        approximation computed with the wavefun(level=precision)
        Wavelet's method (default: 8).

    Returns
    -------
    [int_psi, x] :
        for orthogonal wavelets
    [int_psi_d, int_psi_r, x] :
        for other wavelets


    Examples
    --------
    >>> from pywt import Wavelet, integrate_wavelet
    >>> wavelet1 = Wavelet('db2')
    >>> [int_psi, x] = integrate_wavelet(wavelet1, precision=5)
    >>> wavelet2 = Wavelet('bior1.3')
    >>> [int_psi_d, int_psi_r, x] = integrate_wavelet(wavelet2, precision=5)

    z^Integration of a general signal is deprecated and will be removed in a future version of pywt.r   r         N)typetuplelistr   r   r    
isinstancer   r	   r   r   asarrayr   wavefunlen)wavelet	precisionr$   psixr   functions_approximationsphiZphi_dZpsi_dZphi_rZpsi_rr   r   r   r
   <   s*    !

c                 C   s   t | ttfst| } | |}t|dkr6|\}}n|d |d  }}t|d |d  }|dkshtt	t
t|dd d }|t|d krt|| d }d||d   S )a  
    Computes the central frequency of the `psi` wavelet function.

    Parameters
    ----------
    wavelet : Wavelet instance, str or tuple
        Wavelet to integrate.  If a string, should be the name of a wavelet.
    precision : int, optional
        Precision that will be used for wavelet function
        approximation computed with the wavefun(level=precision)
        Wavelet's method (default: 8).

    Returns
    -------
    scalar

    r&   r   r   Ng      ?)r+   r   r	   r   r-   r.   floatAssertionErrorr   Zargmaxabsr   )r/   r0   r3   r1   r2   domainindexr   r   r   r   {   s    

c                 C   s   t | |d| S )a  Convert from CWT "scale" to normalized frequency.

    Parameters
    ----------
    wavelet : Wavelet instance or str
        Wavelet to integrate.  If a string, should be the name of a wavelet.
    scale : scalar
        The scale of the CWT.
    precision : int, optional
        Precision that will be used for wavelet function approximation computed
        with ``wavelet.wavefun(level=precision)``.  Default is 8.

    Returns
    -------
    freq : scalar
        Frequency normalized to the sampling frequency. In other words, for a
        sampling interval of `dt` seconds, the normalized frequency of 1.0
        corresponds to (`1/dt` Hz).

    r0   r   )r/   scaler0   r   r   r   r      s    c                 C   s   t | |d| S )a  Convert from to normalized frequency to CWT "scale".

    Parameters
    ----------
    wavelet : Wavelet instance or str
        Wavelet to integrate.  If a string, should be the name of a wavelet.
    freq : scalar
        Frequency, normalized so that the sampling frequency corresponds to a
        value of 1.0.
    precision : int, optional
        Precision that will be used for wavelet function approximation computed
        with ``wavelet.wavefun(level=precision)``.  Default is 8.

    Returns
    -------
    scale : scalar

    r;   r<   )r/   freqr0   r   r   r   r      s    c                 C   s2   t | ddd }|ddd  |ddd< |S )ad  
    Returns the Quadrature Mirror Filter(QMF).

    The magnitude response of QMF is mirror image about `pi/2` of that of the
    input filter.

    Parameters
    ----------
    filt : array_like
        Input filter for which QMF needs to be computed.

    Returns
    -------
    qm_filter : ndarray
        Quadrature mirror of the input filter.

    Nr5   r   r&   )r   array)ZfiltZ	qm_filterr   r   r   r      s    c                 C   st   t | d dkstdtj| tjd} td|  t|  }|ddd }t|}|ddd }||||f}|S )a,  
    Returns the orthogonal filter bank.

    The orthogonal filter bank consists of the HPFs and LPFs at
    decomposition and reconstruction stage for the input scaling filter.

    Parameters
    ----------
    scaling_filter : array_like
        Input scaling filter (father wavelet).

    Returns
    -------
    orth_filt_bank : tuple of 4 ndarrays
        The orthogonal filter bank of the input scaling filter in the order :
        1] Decomposition LPF
        2] Decomposition HPF
        3] Reconstruction LPF
        4] Reconstruction HPF

    r&   r   z'`scaling_filter` length has to be even.)ZdtypeNr5   )r.   
ValueErrorr   r,   Zfloat64sqrtsumr   )Zscaling_filterZrec_loZdec_loZrec_hiZdec_hiZorth_filt_bankr   r   r   r      s    )r%   )r%   )r%   )r%   )__doc__
__future__r   r   r   r   numpyr   Z	numpy.fftr   Z_extensions._pywtr   r   r	   __all__r   r   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   <module>   s6        
?
)

