コード例 #1
0
def logMelSpectrum(input, samplingrate=20000, plotfilers=False):
    """
    Calculates the log output of a Mel filterbank when the input is the power spectrum

    Args:
        input: array of power spectrum coefficients [N x nfft] where N is the number of frames and
               nfft the length of each spectrum
        samplingrate: sampling rate of the original signal (used to calculate the filterbank shapes)
    Output:
        array of Mel filterbank log outputs [N x nmelfilters] where nmelfilters is the number
        of filters in the filterbank
    Note: use the trfbank function provided in tools.py to calculate the filterbank shapes and
          nmelfilters
    """

    filter_bank = trfbank(samplingrate, np.shape(input)[1])

    if plotfilers:
        plt.plot(filter_bank)
        plt.xlabel("spectrum length")
        plt.ylabel("filter amplitudes")
        plt.title("Mel filters in linear frequency scale")
        plt.show()

    return np.log(input.dot(filter_bank.T))
コード例 #2
0
def logMelSpectrum(inp, samplingrate=20000):
    filters = to.trfbank(samplingrate, 512)
    print(inp.shape)
    #print(filters)
    #print(filters.shape)
    #plt.plot(np.transpose(filters))
    #plt.title('Mel Filterbank',fontsize=20)
    #plt.plot(filters[1,:])
    #plt.show()
    #plt.show()
    mel = np.log(np.matmul(inp, np.transpose(filters)))
    print(mel)
    return np.log(np.matmul(inp, np.transpose(filters)))
    """
コード例 #3
0
def logMelSpectrum(input, samplingrate):
    """
    Calculates the log output of a Mel filterbank when the input is the power spectrum

    Args:
        input: array of power spectrum coefficients [N x nfft] where N is the number of frames and
               nfft the length of each spectrum
        samplingrate: sampling rate of the original signal (used to calculate the filterbank shapes)
    Output:
        array of Mel filterbank log outputs [N x nmelfilters] where nmelfilters is the number
        of filters in the filterbank
    Note: use the trfbank function provided in tools.py to calculate the filterbank shapes and
          nmelfilters
    """
    filter_bank = trfbank(samplingrate, input.shape[1])
    return np.log(input.dot(filter_bank.T))
コード例 #4
0
def logMelSpectrum(input, samplingrate):
    """
    Calculates the log output of a Mel filterbank when the input is the power spectrum

    Args:
        input: array of power spectrum coefficients [N x nfft] where N is the number of frames and
               nfft the length of each spectrum
        samplingrate: sampling rate of the original signal (used to calculate the filterbanks)
    Output:
        array of Mel filterbank log outputs [N x nmelfilters] where nmelfilters is the number
        of filters in the filterbank
    Note: use the trfbank function provided in tools.py to calculate the filterbank shapes and
          nmelfilters
    """
    N, nfft = input.shape
    flt = tools.trfbank(samplingrate, nfft)
    return np.log( np.dot( input, flt.transpose() ) )
コード例 #5
0
def logMelSpectrum(input, samplingrate):
    """
    Calculates the log output of a Mel filterbank when the input is the power spectrum

    Args:
        input: array of power spectrum coefficients [N x nfft] where N is the number of frames and
               nfft the length of each spectrum
        samplingrate: sampling rate of the original signal (used to calculate the filterbank shapes)
    Output:
        array of Mel filterbank log outputs [N x nmelfilters] where nmelfilters is the number
        of filters in the filterbank
    Note: use the trfbank function provided in tools.py to calculate the filterbank shapes and
          nmelfilters
    """
    nfft = input.shape[1]
    triangular_filters = tools.trfbank(samplingrate, nfft)
    # plt.plot(triangular_filters)
    # plt.title('Mel filterbank filters, number of filters = %d'%len(triangular_filters))
    # plt.show()
    return np.log(np.dot(input, triangular_filters.T))
コード例 #6
0
def logMelSpectrum(input, samplingrate):
    """
    Calculates the log output of a Mel filterbank when the input is the power spectrum

    Args:
        input: array of power spectrum coefficients [N x nfft] where N is the number of frames and
               nfft the length of each spectrum
        samplingrate: sampling rate of the original signal (used to calculate the filterbank shapes)
    Output:
        array of Mel filterbank log outputs [N x nmelfilters] where nmelfilters is the number
        of filters in the filterbank
    Note: use the trfbank function provided in tools.py to calculate the filterbank shapes and
          nmelfilters
    """
    global fbank
    nfft = len(input[0])
    fs = samplingrate
    fbank = tools.trfbank(fs, nfft)
    Melspec = np.dot(input, fbank.T)
    return np.log(Melspec)
コード例 #7
0
def logMelSpectrum(input, samplingrate):
    """
    Calculates the log output of a Mel filterbank when the input is the power spectrum
    Args:
        input: array of power spectrum coefficients [N x nfft] where N is the number of frames and
               nfft the length of each spectrum
        samplingrate: sampling rate of the original signal (used to calculate the filterbank shapes)
    Output:
        array of Mel filterbank log outputs [N x nmelfilters] where nmelfilters is the number
        of filters in the filterbank
    Note: use the trfbank function provided in lab1_tools.py to calculate the filterbank shapes and
          nmelfilters
    """
    N = len(input)  # 92frames
    Mel = tools.trfbank(samplingrate, len(input[0]))  # 40filters*512
    M = Mel.shape[0]
    # plot the filters in linear frequency scale x=k*512/fs(20000)
    #plt.figure()
    x = np.zeros((N, M))
    for i in range(N):
        for j in range(M):
            x[i, j] = np.log(np.sum(input[i, :] * Mel[j, :]))
    return x