简体   繁体   English

Unity3D中音频信号谐波的幅度

[英]Amplitude of audio signal harmonics in Unity3D

I have managed to calculate the pitch of audio input from microphone using the GetSpectrumData function. 我已经设法使用GetSpectrumData函数来计算从麦克风输入的音频的音调。 But now I need to get the amplitudes of the first 7 harmonics of audio (Project requirement) I have very less knowledge of Audio dsp. 但是现在我需要获得音频的前7个谐波的幅度(项目要求),我对音频dsp的了解很少。 Only thing I understood is that harmonics are multiples of the fundamental frequency. 我唯一了解的是谐波是基频的倍数。 But how will I get the amplitudes of the harmonics. 但是我将如何获得谐波的幅度。

Thanks 谢谢

First you need to figure out which FFT bin your fundamental frequency is in. Say it resides in bin# 10. The harmonics will reside in integer multiples of that bin so the 2nd harmonic will be in bin 20, 3rd in bin 30 and so on. 首先,您需要确定您的基本频率位于哪个FFT箱中。假设它位于箱#10中。谐波将以该箱的整数倍驻留,因此二次谐波将在箱20中,三次在箱30中,依此类推。 。 For each of these harmonic bins you need to compute the amplitude. 对于每个谐波箱,您需要计算振幅。 Depending on the window function you used in the FFT you will need to include a small number of bins in the calculation (google spectral leakage if you're interested). 根据您在FFT中使用的窗口函数,您需要在计算中包括少量的bin(如果您感兴趣,则为Google频谱泄漏)。

double computeAmpl(double[] spectrum, int windowHalfLen, int peakBin, int harmonic)
{
    double sumOfSquares = 0.0;
    for (int bin = peakBin-windowHalfLen; bin <= peakBin+windowHalfLen; bin++)
    {
        sumOfSquares += spectrum[bin] * spectrum[bin];
    }
    return sqrt(sumOfSquares);
}

As I mentioned the window half length depends on the window. 正如我提到的,窗口的一半长度取决于窗口。 Some common ones are: 一些常见的是:

  • blackman-harris 3 - 3 布莱克曼·哈里斯3-3
  • blackman-harris 4 - 4 布莱克曼哈里斯4-4
  • flat top - 5 平顶-5
  • hann - 3 汉-3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM