Python 在只有一个音调的声音时查找音调?
我正在使用iPython查找WAV文件中只有一个音高的音高。我的方法是找到基频及其谐波。然后以某种方式使用这些值来计算螺距。我的基本方法是找到峰值频率的所有索引,然后将它们存储在一个数组中。我的方法错了吗?既然im wav文件只有一个音调,我该怎么办。我已经设法找到了所有的组件,但我不确定如何使用它们来找到基本的。或者我应该使用周期时间,并尝试找到该周期的最高频率Python 在只有一个音调的声音时查找音调?,python,audio,ipython,Python,Audio,Ipython,我正在使用iPython查找WAV文件中只有一个音高的音高。我的方法是找到基频及其谐波。然后以某种方式使用这些值来计算螺距。我的基本方法是找到峰值频率的所有索引,然后将它们存储在一个数组中。我的方法错了吗?既然im wav文件只有一个音调,我该怎么办。我已经设法找到了所有的组件,但我不确定如何使用它们来找到基本的。或者我应该使用周期时间,并尝试找到该周期的最高频率 def getPitchInHz(filename): file3 = wavReadMono(filename)
def getPitchInHz(filename):
file3 = wavReadMono(filename)
play(file3)
spec = abs(fft.fft(file3)) #compute the magnitude spectrum
rate = 44100 #44100 Hz
freqs = fft.fftfreq(size(spec))*rate #array of frequencies corresponding to bins
Spec = spec[0:size(spec)/2] #spectrum up to the Nyquist
duration = size(Spec)/rate
#periodic time = 1/frequency
pt = 1/freqs
t = arange(0, duration, 1/rate) #t is an array of equally-spaced time points
#plot(t[0:size(spec)/2], spec[0:size(spec)/2])
harmonics = 5
i = 0
plot(freqs[0:6000], Spec[0:6000]) #
xlabel("Frequency, Hz")
ylabel("Magnitude")
#v = []
#print "Fundamental frequency approx. ", freqs[peakIndex], "Hz"
print "Duration", duration
print "The length of the spectrum is ", size(Spec)
while i < harmonics:
peakIndex = argmax(Spec)#find index for peak frequency
if peakIndex in v: #if index is already in array do
Spec[peakIndex] = 0 #Set this peak to zero so that we can use argmax to find the next highest:
else:
v[i] = peakIndex #then add index to array
i+1
for x in range( len(v)):#loop through array of index starting with the peak frequency that occurs earliet
print "harmonic ", x , " Frequency ", freqs[v[x]], "Hz ", abs(Spec[v[x]]), "magnitude"
return pitch
好吧,那有什么不起作用的呢?“你的实际问题是什么?”我更新了我的问题。我的代码找到了彼此相邻的频率,而不是和谐的频率。我也不知道该如何检查我拥有的是基本功能/尝试应用窗口功能和谷歌光谱泄漏。