There are quite a few similar/related questions on SO already which are well worth reading as the answers contain a lot of useful information and advice, but in essence you need to do this:
Convert the audio data to the format required by FFT (e.g. int -> float, with separate L/R channels);
Apply FFT (NB: if using typical complex-to-complex FFT then set all imaginary parts in the input array to zero);
Calculate the magnitude of the first N/2 FFT output bins (sqrt(re*re + im*im));
Optionally convert magnitude to dB (log) scale (20 * log10(magnitude) or 10 * log10(re*re + im*im));
Plot N/2 (log) magnitude values.
Note that while FFTW is a very good and very fast FFT it may be a little overwhelming for a beginner - it's also very expensive if you want to include it as part of a commercial product. I recommend starting with KissFFT instead.
发布评论
评论(1)
SO 上已经有很多类似/相关的问题,非常值得一读,因为答案包含很多有用的信息和建议,但本质上您需要这样做:
sqrt(re*re + im*im)
);20 * log10(magnitude)
或10 * log10(re*re + im*im)
);请注意,虽然 FFTW 是一种非常好且非常快的 FFT,但对于初学者来说可能有点难以承受 - 如果您想将其作为商业产品的一部分,它也非常昂贵。我建议从 KissFFT 开始。
There are quite a few similar/related questions on SO already which are well worth reading as the answers contain a lot of useful information and advice, but in essence you need to do this:
sqrt(re*re + im*im)
);20 * log10(magnitude)
or10 * log10(re*re + im*im)
);Note that while FFTW is a very good and very fast FFT it may be a little overwhelming for a beginner - it's also very expensive if you want to include it as part of a commercial product. I recommend starting with KissFFT instead.