简体   繁体   English

Java-使用FFT查找音频信号的频率和幅度

[英]Java - Finding frequency and amplitude of audio signal using FFT

After reading a no. 看完后没有 of posts here itself i have applied an FFT algorithm on the recorded audio(.wav) file to transform it from time domain to frequency domain. 在这里的帖子本身我已经对记录的audio(.wav)文件应用了FFT算法,将其从时域转换到频域。

As a result i have got an array containing some values as 结果我得到了一个包含一些值的数组

magnitude[i] = sqrt(re*re+im*im);

Now as the title says i have to find frequency and amplitude of the signal(complex sound ie voice) using this magnitude array, but i have no idea of how to do further processing using this array.The size of FFT is 1024 and sample rate is 48000Hz. 现在正如标题所述,我必须使用此幅度数组来找到信号(复杂声音即语音)的频率和幅度,但是我不知道如何使用此数组进行进一步处理.FFT的大小为1024,采样率为是48000Hz。 Please help me for further processing. 请帮我进一步处理。

If you're just looking for the single largest (sinusoidal) component then scan through the magnitude array until you find the maximum value, and then convert the index of this value to its corresponding frequency, ie 如果您只是在寻找最大的(正弦波)分量,请扫描幅度数组,直到找到最大值,然后将该值的索引转换为其相应的频率,即

mag_max = magnitude[0];
i_max = 0;
for (i = 1; i < N; ++i)
{
    if (magnitude[i] > mag_max)
    {
        mag_max = magnitude[i];
        i_max = i;
    }
}

You now have the value of the peak in mag_max and its index in i_max . 你现在有高峰在价值mag_max及其指数i_max You can get the frequency like this: 您可以这样获得频率:

f_max = i_max * Fs / N;

where Fs is the sample rate (and N is the FFT size of course). 其中Fs是采样率( N是当然的FFT大小)。

Of course if you're looking for something like the pitch of a complex sound (eg a voice or a musical instrument) then things get a lot more complicated. 当然,如果你正在寻找的东西像一个复杂声音的音高 (如语音或乐器),那么事情就会变得更加复杂。 You might want to take a look at the Harmonic Product Spectrum algorithm and pitch detection algorithms in general. 通常,您可能需要看一下谐波积谱算法和音高检测算法

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

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