MusicFeatures.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:Math412S2017 作者: ctralie 项目源码 文件源码
def Specgram(X, W, H):
    """A function to compute the spectrogram of a signal
    :parm X: N x 1 Audio Signal
    :param W: Window Size
    :param H HopSize
    :returns: S, an N x NBins spectrogram array
    """
    Q = W/H
    if Q - np.floor(Q) > 0:
        print('Warning: Window size is not integer multiple of hop size\n')
    win = np.hamming(W)
    NWin = int(np.floor((len(X) - W)/float(H)) + 1)
    S = np.zeros((NWin, W))
    for i in range(NWin):
        x = X[i*H:i*H+W]
        S[i, :] = np.abs(np.fft.fft(win*x))
    #Second half of the spectrum is redundant for real signals
    if W % 2 == 0:
        #Even Case
        S = S[:, 0:W/2]
    else:
        #Odd Case
        S = S[:, 0:(W-1)/2+1]
    return S
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号