我对这个(和编程)有点陌生。我正在尝试编写一个脚本来帮助我分析一个大型的.wav文件。理论上,它将对时间段运行fft,输出与功率v频率相对应的数据,对某个频率范围执行峰值功率搜索,并将其附加到另一个新的数组中,我稍后将使用它来构建直方图。
我坚持的步骤是选择一个频率范围并让屏幕打印出该频率范围的最大功率(我的尝试是在plt.show()之后),我希望能够返回频率范围为260-270 of的峰值功率.有什么建议(我已经在主板上做了调整以返回dbm )?
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)));发布于 2014-04-18 22:47:09
我通过枚举找到了我的范围问题的答案。
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])https://stackoverflow.com/questions/22998768
复制相似问题