Esempio n. 1
0
def true_envelope(m_sp, in_type='abs', ncoeffs=60, thres_db=0.1):
    '''
    in_type: 'abs', 'db', or 'log'
    TODO: Test cases 'db' and 'log'
    '''

    if in_type == 'db':
        m_sp_db = m_sp
    elif in_type == 'abs':
        m_sp_db = db(m_sp)
    elif in_type == 'log':
        m_sp_db = (20.0 / np.log(10.0)) * m_sp

    m_sp_db_env = np.zeros(m_sp_db.shape)
    nFrms = m_sp_db.shape[0]
    n_maxiter = 100

    for f in xrange(nFrms):
        v_sp_db = m_sp_db[f, :]
        for i in xrange(n_maxiter):
            v_sp_db_sm = spectral_smoothing_rceps(v_sp_db[None, :],
                                                  nc_total=ncoeffs,
                                                  fade_to_total=0.7)[0]

            # Debug:
            if False:
                from libplot import lp
                lp.figure(1)
                lp.plot(m_sp_db[f, :], '.-b')
                lp.plot(v_sp_db, '.-r')
                lp.plot(v_sp_db_sm, '.-g')
                lp.grid()

            if np.mean(np.abs(v_sp_db - v_sp_db_sm)) < thres_db:
                break

            v_sp_db = np.maximum(v_sp_db, v_sp_db_sm)

        m_sp_db_env[f, :] = v_sp_db_sm

    if in_type == 'db':
        m_sp_env = m_sp_db_env
    elif in_type == 'abs':
        m_sp_env = db(m_sp_db_env, b_inv=True)
    elif in_type == 'log':
        m_sp_env = (np.log(10.0) / 20.0) * m_sp_db_env

    return m_sp_env
def plots(m_mag, m_real, m_imag, v_f0):
    lp.plotm(la.db(m_mag))  # in decibels for better visualisation
    lp.title('Magnitude Spectrum (dB)')
    lp.xlabel('Time (frames)')
    lp.ylabel('Frequency bins')

    lp.plotm(m_real)
    lp.title('"R" Feature Phase Spectrum')
    lp.xlabel('Time (frames)')
    lp.ylabel('Frequency bins')

    lp.plotm(m_imag)
    lp.title('"I" Feature Phase Spectrum')
    lp.xlabel('Time (frames)')
    lp.ylabel('Frequency bins')

    lp.figure()
    lp.plot(v_f0)
    lp.title('F0')
    lp.xlabel('Time (frames)')
    lp.ylabel('F0')
    lp.grid()
    return
def plots(m_mag, m_real, m_imag, v_f0):
    lp.plotm(la.db(m_mag)) # in decibels for better visualisation
    lp.title('Magnitude Spectrum (dB)')
    lp.xlabel('Time (frames)')
    lp.ylabel('Frequency bins')

    lp.plotm(m_real)
    lp.title('"R" Feature Phase Spectrum')
    lp.xlabel('Time (frames)')
    lp.ylabel('Frequency bins')

    lp.plotm(m_imag)
    lp.title('"I" Feature Phase Spectrum')
    lp.xlabel('Time (frames)')
    lp.ylabel('Frequency bins')

    lp.figure()
    lp.plot(v_f0)
    lp.title('F0')
    lp.xlabel('Time (frames)')
    lp.ylabel('F0')
    lp.grid()
    return
def plots(m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0):
    lp.plotm(m_mag_mel_log)
    lp.title('Log-Magnitude Spectrum')
    lp.xlabel('Time (frames)')
    lp.ylabel('Mel-scaled frequency bins')

    lp.plotm(m_real_mel)
    lp.title('"R" Feature Phase Spectrum')
    lp.xlabel('Time (frames)')
    lp.ylabel('Mel-scaled frequency bins')

    lp.plotm(m_imag_mel)
    lp.title('"I" Feature Phase Spectrum')
    lp.xlabel('Time (frames)')
    lp.ylabel('Mel-scaled frequency bins')

    lp.figure()
    lp.plot(np.exp(v_lf0))  # unlog for better visualisation
    lp.title('F0')
    lp.xlabel('Time (frames)')
    lp.ylabel('F0')
    lp.grid()
    return
Esempio n. 5
0
    if False:
        lp.plotm(m_mag_ref)
        lp.plotm(m_mag_a)
        lp.plotm(m_mag_ref - m_mag_a)
        lp.plotm((m_mag_ref - m_mag_a)[:50, :50])

        lp.plotm(np.diff(m_mag_ref, axis=0))
        lp.plotm(np.diff(m_mag_a, axis=0))

    if True:
        nx = 26
        lp.figure()
        lp.plot(m_mag_ref[nx, :])
        lp.plot(m_mag_a[nx, :])
        lp.grid()

    if True:
        nx = 26
        lp.figure()
        lp.plot(m_mag_ref[nx, :])
        lp.plot(m_mag_a[nx, :])
        lp.plot(m_mag_ref[nx - 1, :])
        lp.plot(m_mag_a[nx - 1, :])
        lp.grid()
        nx = 37
        lp.figure()
        lp.plot(m_mag_ref[nx, :])
        lp.plot(m_mag_a[nx, :])
        lp.plot(m_mag_ref[nx - 1, :])
        lp.plot(m_mag_a[nx - 1, :])