Exemplo n.º 1
0
def mc2e(mc, alpha=0.35, irlen=256):
    """Compute energy from mel-cepstrum

    Inspired from hts_engine

    Parameters
    ----------
    mc : array
        Mel-spectrum

    alpha : float
        All-pass constant.

    irlen : int
        IIR filter length

    Returns
    -------
    energy : floating point, scalar
        frame energy
    """
    # back to linear frequency domain
    c = freqt(mc, irlen - 1, -alpha)

    # compute impule response from cepsturm
    ir = c2ir(c, irlen)

    return np.sum(np.abs(ir * ir))
Exemplo n.º 2
0
def sp2mc(powerspec, order, alpha):
    """Convert spectrum envelope to mel-cepstrum

    This is a simplified implementation of ``mcep`` for input type
    is 4.

    Parameters
    ----------
    powerspec : array
        Power spectrum

    order : int
        Order of mel-cepstrum

    alpha : float
        All-pass constant.

    Returns
    -------
    mc : array, shape(``order+1``)
        mel-cepstrum

    See Also
    --------
    pysptk.sptk.mcep
    pysptk.conversion.mc2sp

    """

    # |X(ω)|² -> log(|X(ω)²|)
    logperiodogram = np.log(powerspec)

    # transform log-periodogram to real cepstrum
    # log(|X(ω)|²) -> c(m)
    c = np.fft.irfft(logperiodogram)
    c[0] /= 2.0

    # c(m) -> cₐ(m)
    return freqt(c, order, alpha)
Exemplo n.º 3
0
def mc2sp(mc, alpha, fftlen):
    """Convert mel-cepstrum back to power spectrum

    Parameters
    ----------
    mc : array
        Mel-spectrum

    alpha : float
        All-pass constant.

    fftlen : int
        FFT length

    Returns
    -------
    powerspec : array, shape(``fftlen//2 +1``)
        Power spectrum

    See Also
    --------
    pysptk.sptk.mcep
    pysptk.conversion.sp2mc

    """
    # back to cepstrum from mel-cesptrum
    # cₐ(m) -> c(m)
    c = freqt(mc, int(fftlen // 2), -alpha)
    c[0] *= 2.0

    symc = np.zeros(fftlen)
    symc[0] = c[0]
    for i in range(1, len(c)):
        symc[i] = c[i]
        symc[-i] = c[i]

    # back to power spectrum
    # c(m) -> log(|X(ω)|²) -> |X(ω)|²
    return np.exp(np.fft.rfft(symc).real)