[英]Waveform frequency lower than musical note frequency?
I'm trying to extract the frequency of a note from an mp3 file that includes a synthesized sample of an A3 note, which should be 220 Hz. 我正在尝试从mp3文件中提取一个笔记的频率,该文件包含一个合成的A3笔记样本,应为220 Hz。
This is part of the waveform I obtain using librosa
: 这是我使用
librosa
获得的波形的一部分:
As you can see, the wave seems to repeat itself every 400 samples. 如您所见,该波似乎每400个样本重复一次。 Therefore, by dividing the sampling rate, which is 22050 Hz, by 400 I should get the frequency of the waveform.
因此,通过将22050 Hz的采样率除以400 I,可以得到波形的频率。 However, I get 55.125 Hz instead of 220. Am I missing something or making a mistake?
但是,我得到的频率是55.125 Hz,而不是220。我是否遗漏了某些东西或出错了?
EDIT : Here's the code I'm using 编辑 :这是我正在使用的代码
import librosa
from matplotlib import pyplot as plt
import numpy as np
%matplotlib notebook
y, sr = librosa.load("Simple_synth/A3-saw.mp3")
plt.figure(figsize=(18,6))
plt.plot(y[2000:3000])
note_freq = sr/400
Link to the audio file: https://www.filefactory.com/file/7aqmrvq375n9/A3-saw.mp3 链接到音频文件: https : //www.filefactory.com/file/7aqmrvq375n9/A3-saw.mp3
For the given audio sample 对于给定的音频样本
import librosa
from matplotlib import pyplot as plt
import numpy as np
y, sr = librosa.load("A3-saw.mp3")
it is possible to calculate fourier transform (see how to extract frequency associated with fft values in python ) 可以计算傅立叶变换(请参阅如何在python中提取与fft值关联的频率 )
# calculate fast fourier transform
w = np.fft.fft(y)
# frequencies associated to the fourier transform
freqs = np.fft.fftfreq(len(y))
And then find the highest peak in the fourier transform and its frequency in Hz 然后在傅立叶变换中找到最高峰,其频率以Hz为单位
idx = np.argmax(np.abs(w))
freq = freqs[idx]
freq_in_hertz = abs(freq * sr)
print(freq_in_hertz)
54.90196078431373
54.90196078431373
There are also higher harmonics involved in the sample, which can be seen by plotting more peaks 样品中还包含更高的谐波,可以通过绘制更多的峰来看出
plt.plot(sr*freqs[0:500],abs(w[0:500]))
plt.plot(sr*freqs[0:2000],abs(w[0:2000]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.