簡體   English   中英

需要幫助選擇頻率范圍以進行FFT操作后的峰搜索

[英]Need help selecting frequency range for peaks search after FFT operation

我對此(和編程)有點陌生。 我正在嘗試編寫一個腳本,該腳本將幫助我分析較大的.wav文件。 從理論上講,它將在時間段上運行fft,輸出與功率相對於頻率相對應的數據,在一系列頻率上執行峰值功率搜索,並將其附加到另一個新數組中,我將在稍后使用該新數組來構建直方圖。

我堅持的步驟是選擇一個頻率范圍,並讓屏幕顯示該頻率范圍的最大功率(我的嘗試是在plt.show()之后),我希望能夠返回該頻率范圍的峰值功率260-270Hz ...有什么建議(我已經在該主塊中進行了調整,以便已經返回dbm v Hz)?

for i in range(reads-1):
    if i > 0:
        break
    print 'working on set {:d} \n'.format(i) 
    waveData = wavFile.readframes(int(Windowsize))
    waveDataunpack = struct.unpack(formatstring,waveData)
    fftData = ((np.fft.rfft(waveDataunpack)/Windowsize))
    freqs = np.fft.fftfreq(Windowsize+1, float(1.0/rate))
    plt.plot(freqs[:16385],10*np.log10(np.abs(fftData)))
    plt.ylabel('power (dBm)')
    plt.xlabel('frequency (Hz)')
    plt.ylim((0,50))
    plt.xlim((0,500)) 
    #plt.show()

    pointy = fftData[freqs.index(260)]
    #print pointy
    #print(fftData.max)
    #print max(10*np.log10(np.abs(fftData)));

我通過枚舉找到了解決范圍問題的答案。

ind = [i for i, x in enumerate(windowed_freqs) if x >= 240 and x <= 285]

#now take the DB data only at the indicies where x is between the proper range.
value = fftData_inDB[ind]

#print freqs[ind]
maxval=-1000
maxind=0
for j in ind:
    if fftData_inDB[j] > maxval:
        maxval = fftData_inDB[j]
        maxind = j
print 'max power in range is {} dBm'.format(maxval)
print 'corresponding frequency is {} Hz'.format(freqs[maxind])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM