具有高频率的倒谱倒谱的不准确的基频(峰值,音调)

时间:2016-01-19 05:29:53

标签: python audio-processing

我试图检测声音的基本频率

我使用倒谱来找到频率。

除高频外,它的效果很好。

我想检测钢琴的最高频率,C8(4186Hz)

然而,为了检测4186Hz,采样率为44100,我需要得到频率10.5,这是不可能的,因为quefrency是样本数。

所以我得到了10个频率,而44100/10 = 4410赫兹接近C#8(4435Hz)

我应该如何检测准确的基频。

修改

samplerate, samples = wav.read(audiopath)
print "samplerate= " + str(samplerate)
samples = (samples[:, 0] + samples[:, 1]) / 2
overlapFac = 0.9
s = stft(samples, binsize, overlapFac)

break_flag = False
fund_freq_list = []
for i in range(len(s)):
    ceps = np.fft.irfft(np.power(np.log(np.abs(s[i])), 2))      
    for nan in np.isnan(ceps):      
        if nan:
            break_flag = True
            break

    if break_flag:
        break

    plt.plot(ceps)


    ignore_begin = int(samplerate/4500 - 2)
    ceps = ceps[ignore_begin:]


    for under_zero in ceps:
        if under_zero < 0:
            under_zero = np.where(ceps == under_zero)[0][0]
            break


    print "under_zero = " + str(under_zero+ignore_begin)


    ceps = ceps[under_zero:int(samplerate/27.5 + 2)]
    hertz = str(samplerate/float(ceps.argmax() + under_zero + ignore_begin))
    print "hertz = " + hertz
    print "sec = %3.3f ~ %3.3f" % (float((binsize*i*(1-overlapFac)))/float((samplerate)), float((binsize*(i+1)*(1-overlapFac)))/float((samplerate)))
    print "val = " + str(ceps.max())
    print "--------------------"

    fund_freq_list.append({'s_num': i, 'hertz': float(hertz)})

0 个答案:

没有答案