o
    X۷i                     @  s   d dl mZ d dlZeddddZd"dd	Zejd
ddddddZd"ddZejddddddZdd Z	ejddddddZ
d#d d!ZdS )$    )annotationsNz
T spectrumzT outputz*
    output = log( abs( spectrum ) );
    _real_cepstrum_kernelc                 C  s8   t | } t jj| ||d}t|}t jj|||djS )aa  
    Calculates the real cepstrum of an input sequence x where the cepstrum is
    defined as the inverse Fourier transform of the log magnitude DFT
    (spectrum) of a signal. It's primarily used for source/speaker separation
    in speech signal processing

    Parameters
    ----------
    x : ndarray
        Input sequence, if x is a matrix, return cepstrum in direction of axis
    n : int
        Size of Fourier Transform; If none, will use length of input array
    axis: int
        Direction for cepstrum calculation

    Returns
    -------
    ceps : ndarray
        Complex cepstrum result
    naxis)cupyasarrayfftr   ifftreal)xr   r   spectrum r   W/home/ubuntu/vllm_env/lib/python3.10/site-packages/cupyx/signal/_acoustics/_cepstrum.pyreal_cepstrum$   s   
r   zC spectrum, raw T unwrappedzC output, T ndelayz
    ndelay = round( unwrapped[center] / M_PI );
    const T temp { unwrapped[i] - ( M_PI * ndelay * i / center ) };

    output = log( abs( spectrum ) ) + C( 0, temp );
    _complex_cepstrum_kernelTzKconst int center { static_cast<int>( 0.5 *         ( _ind.size() + 1 ) ) };)return_tuple	loop_prepc                 C  sV   t | } t jj| ||d}t t |}t||\}}t jj|||dj}||fS )a  
    Calculates the complex cepstrum of a real valued input sequence x
    where the cepstrum is defined as the inverse Fourier transform
    of the log magnitude DFT (spectrum) of a signal. It's primarily
    used for source/speaker separation in speech signal processing.

    The input is altered to have zero-phase at pi radians (180 degrees)
    Parameters
    ----------
    x : ndarray
        Input sequence, if x is a matrix, return cepstrum in direction of axis
    n : int
       Size of Fourier Transform; If none, will use length of input array
    axis: int
        Direction for cepstrum calculation
    Returns
    -------
    ceps : ndarray
        Complex cepstrum result
    r   )r   r	   r
   unwrapangler   r   r   )r   r   r   r   	unwrappedlog_spectrumndelaycepsr   r   r   complex_cepstrumO   s   
r   z(C log_spectrum, int32 ndelay, float64 piz
C spectrumz
    const double wrapped { log_spectrum.imag() + M_PI * ndelay * i / center };

    spectrum = exp( C( log_spectrum.real(), wrapped ) )
     _inverse_complex_cepstrum_kernelz2const double center { 0.5 * ( _ind.size() + 1 ) };)r   c                 C  s6   t | } t j| }t||t j}t j|j}|S )a6  Compute the inverse complex cepstrum of a real sequence.
    ceps : ndarray
        Real sequence to compute inverse complex cepstrum of.
    ndelay: int
        The amount of samples of circular delay added to `x`.
    Returns
    -------
    x : ndarray
        The inverse complex cepstrum of the real sequence `ceps`.
    The inverse complex cepstrum is given by
    .. math:: x[n] = F^{-1}\left{\exp(F(c[n]))\right}
    where :math:`c_[n]` is the input signal and :math:`F` and :math:`F_{-1}
    are respectively the forward and backward Fourier transform.
    )r   r	   r
   r   pir   r   )r   r   r   r   icepsr   r   r   inverse_complex_cepstrumz   s
   
r   zT cepszT windowz
    if ( !i ) {
        window = ceps;
    } else if ( i < bend ) {
        window = ceps * 2.0;
    } else if ( i == bend ) {
        window = ceps * ( 1 - odd );
    } else {
        window = 0;
    }
    _minimum_phase_kernelzconst bool odd { (_ind.size() & 1) != 0 };                const int bend { static_cast<int>( 0.5 *                     ( _ind.size() + odd ) ) };c                 C  sD   |du rt | }t| |d}t|}tjttj|j}|S )a  Compute the minimum phase reconstruction of a real sequence.
    x : ndarray
        Real sequence to compute the minimum phase reconstruction of.
    n : {None, int}, optional
        Length of the Fourier transform.
    Compute the minimum phase reconstruction of a real sequence using the
    real cepstrum.
    Returns
    -------
    m : ndarray
        The minimum phase reconstruction of the real sequence `x`.
    N)r   )lenr   r    r   r
   r   expr   )r   r   r   windowmr   r   r   minimum_phase   s   r%   )Nr   )N)
__future__r   r   ElementwiseKernelr   r   r   r   r   r   r    r%   r   r   r   r   <module>   sD   


