
    `i              	           d dl Z  e j        ddddd          Zdd	Z e j        d
dddddd          ZddZ e j        dddddd          Zd Z e j        dddddd          Zd dZ	dS )!    Nz
T spectrumzT outputz*
    output = log( abs( spectrum ) );
    _real_cepstrum_kernel)z
-std=c++11)optionsc                     t          j        |           } t           j                            | ||          }t          |          }t           j                            |||          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	   spectrums       u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cupyx/signal/_acoustics/_cepstrum.pyreal_cepstrumr   $   sT    * 	QAx||A|..H$X..H8==QT=2277    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 ) ) };)r   return_tuple	loop_prepc                 6   t          j        |           } t           j                            | ||          }t          j        t          j        |                    }t          ||          \  }}t           j                            |||          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cepss           r   complex_cepstrumr   P   s}    * 	QAx||A|..HDJx0011I3HiHHL&8===66;D<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   r   c                     t          j        |           } 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   icepss        r   inverse_complex_cepstrumr#   |   sT     <D8<<%%L/fdgNNHHMM(##(ELr   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 };                const int bend { static_cast<int>( 0.5 *                     ( _ind.size() + odd ) ) };c                    |t          |           }t          | |          }t          |          }t          j                            t          j        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ms        r   minimum_phaser*      sf     	yFFa   D"4((Fdhtx||F334455:AHr   )Nr   )N)
r
   ElementwiseKernelr   r   r   r   r   r#   r$   r*    r   r   <module>r-      s1  ,  /.    8 8 8 86 241! "   "   < $:4#9.
 'B$ $ $    . /.
 0!   ,     r   