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

查看:26
本文介绍了您如何分析 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 中的每个点都是一个bin".频率,因此如果您的 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.

如果您希望它非常准确,则需要具有高分辨率和大量 bin(= 大量内存和大量计算)的长 FFT.您还可以使用 二次插值 在对数缩放频谱上,效果出奇地好.

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.

请记住,在许多乐器(如钢琴或吉他)中,基频以上的分音不是完美的泛音.每个部分都是实际上有点走调,或者不和谐.因此,FFT 中的高频峰值不会正好位于基波的整数倍上,并且波形会从一个周期到下一个周期略有变化,从而导致自相关.

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天全站免登陆