简体   繁体   English

波形频率低于音符频率?

[英]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.

相关问题 当 A 列中的值低于 B 列时的计数频率 - Count frequency when value in column A is lower than column B FFT 的波形频率分辨率——有什么方法可以提高它? - Waveform frequency resolution for FFT – any way to increase it? 为什么最高 FFT 峰值不是音调的基频? - Why is the highest FFT peak not the fundamental frequency of a musical tone? Python中的频率分析-使用频率而不是频率来打印字母 - Frequency Analysis in Python -Print letters with frequency rather than numbers with frequency 使用高频数据作为低频数据的代理 - Using higher frequency data as a proxy for lower-frequency data AttributeError: 'list' object 在词频逆文档频率中没有属性 'lower' - AttributeError: 'list' object has no attribute 'lower' in term frequency inverse document frequency 如何获得频率大于的单词列表? - How to get a list of words with frequency greater than? 按频率排序,而不是按字母顺序排列(在Python中) - Ordering by frequency rather than alphabetically in a set (in Python) Numba在频率计数方面比纯Python慢 - Numba slower than pure Python in frequency counting 如何以较低的频率重新采样 Pandas DataFrame 并阻止它产生 NaN? - How to resample a Pandas DataFrame at a lower frequency and stop it creating NaN's?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM