您如何分析PCM或WAV样本的基频? [英] How do you analyse the fundamental frequency of a PCM or WAV sample?

查看:161
本文介绍了您如何分析PCM或WAV样本的基频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个样本保存在DirectX的缓冲区中.这是从乐器弹奏和捕捉的音符样本.如何分析样本的频率(就像吉他调音器一样)?我相信涉及FFT,但是我没有指向HOWTO的指针.

I have a sample held in a buffer from DirectX. It's a sample of a note played and captured from an instrument. How do I analyse the frequency of the sample (like a guitar tuner does)? I believe FFTs are involved, but I have no pointers to HOWTOs.

推荐答案

FFT可以帮助您确定频率在哪里,但不能准确地告诉您频率是什么. FFT中的每个点都是一个频率"频率,因此,如果您的FFT中有一个峰值,您所知道的就是您想要的频率在该频率或频率范围内.

The FFT can help you figure out where the frequency is, but it can't tell you exactly what the frequency is. Each point in the FFT is a "bin" of frequencies, so if there's a peak in your FFT, all you know is that the frequency you want is somewhere within that bin, or range of frequencies.

如果您想要真正的准确,则需要具有高分辨率的长FFT和大量的bin(=大量的内存和大量的计算).您也可以使用二次插值在对数刻度范围内,效果非常好.

If you want it really accurate, you need a long FFT with a high resolution and lots of bins (= lots of memory and lots of computation). You can also guess the true peak from a low-resolution FFT using quadratic interpolation on the log-scaled spectrum, which works surprisingly well.

如果计算成本最为重要,则可以尝试将信号转换为可以计数零交叉的形式,然后计数越多,测量越准确.

If computational cost is most important, you can try to get the signal into a form in which you can count zero crossings, and then the more you count, the more accurate your measurement.

但是,如果缺少基础知识,则这些方法都将无效. :)

None of these will work if the fundamental is missing, though. :)

我在此处概述了几种不同的算法,并且插值FFT通常是最准确(尽管只有在基波是最强的谐波时,此功能 -否则,您需要更聪明地找到它),并在接近零的时刻过零(尽管这仅适用于每个周期只有一个交叉的波形).这些条件都不是典型的.

I've outlined a few different algorithms here, and the interpolated FFT is usually the most accurate (though this only works when the fundamental is the strongest harmonic - otherwise you need to be smarter about finding it), with zero-crossings a close second (though this only works for waveforms with one crossing per cycle). Neither of these conditions is typical.

请记住,在许多乐器(例如钢琴或吉他)中,高于基频的部分不是完美的谐波.每个部分都是实际上有点失调,或

Keep in mind that the partials above the fundamental frequency are not perfect harmonics in many instruments, like piano or guitar. Each partial is actually a little bit out of tune, or inharmonic. So the higher-frequency peaks in the FFT will not be exactly on the integer multiples of the fundamental, and the wave shape will change slightly from one cycle to the next, which throws off autocorrelation.

要获得真正准确的频率读数,我会说要使用自相关来猜测基频,然后使用二次插值找到真实的峰值. (您可以在频域中进行自相关以节省CPU周期.)有很多陷阱,正确的使用方法实际上取决于您的应用程序.

To get a really accurate frequency reading, I'd say to use the autocorrelation to guess the fundamental, then find the true peak using quadratic interpolation. (You can do the autocorrelation in the frequency domain to save CPU cycles.) There are a lot of gotchas, and the right method to use really depends on your application.

这篇关于您如何分析PCM或WAV样本的基频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆