SoundUtils.py 文件源码

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

项目:PyPeVoc 作者: goiosunsw 项目源码 文件源码
def SpecFlux(x, sr=1, nwind=1024, nhop=512, minf=0,
             maxf=np.inf, windfunc=np.blackman):
    '''
    Calculates the spectral flux in sunud
    '''

    nsam = len(x)
    # first window
    ist = 0
    iend = ist+nwind

    t = []
    res = []

    wind = windfunc(nwind)
    minbin = int(minf/sr*nwind)
    maxbinf = (float(maxf)/sr*nwind)
    if maxbinf > nwind:
        maxbin = nwind
    else:
        maxbin = int(maxbinf)

    while (iend < nsam-nhop):
        thisx = x[ist:iend]
        nextx = x[ist+nhop:iend+nhop]

        ff = np.abs(np.fft.fft(thisx*wind))
        fl = np.abs(np.fft.fft(nextx*wind))

        res.append(np.sqrt(sum((ff[minbin:maxbin]-fl[minbin:maxbin])**2)))
        t.append(float(ist+iend+nhop)/2.0/float(sr))

        ist = ist+nhop
        iend = ist+nwind

    return np.array(res), np.array(t)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号