开发者

How to convert wave data into Complex numbers

I'm reading raw data from a mic and feeding into FFT. Two of the FFT libraries I'm trying (AForge and Exocortex.DSP) takes Complex numbers as input and gives Complex numbers as output.

I'm trying to understand what complex numbers are.

More specifically - how do I convert the raw audio data obtained from a microphone into complex numbers for processing in FFT?

And how do I plot the output to a nice spectrogram (that is; reading the frequencies and amplitudes from the output)?

Added bonus: What FFT libs are there for .Net other than the two mention开发者_如何学Ced?


When performing an FFT on real data then you just need to set the imaginary part of the input to zero. (Note that the output of the FFT will still be complex though.)

Plotting a spectrogram is more complex - there are previous posts on SO about this but essentially you need to compute the power spectrum for successive overlapping time windows (typical overlap = 50%) and then plot the log (dB) magnitude of these power spectra using colour or grey scale intensity for magnitude (with time on the X axis and frequency on the Y axis usually). To compute the power spectrum:

  • apply window function to input data (e.g. Hanning window)
  • FFT
  • take magnitude squared of first N/2 values of FFT output (re*re + im*im)
  • convert magnitude to dB value (10 * log10 (magnitude squared))


For plotting a "nice looking" spectrogram:

An FFT computes the local spectrum of your data convolved with the transform of the window.

If you don't use a window function in front of an FFT, the window function ends up being a rectangular window of the FFT length by default, which has a transform that might seem quite ugly looking if you don't expect it (some call it spectral "leakage"). You might want to try using some other window function (Von Hann, et.al.) where the convolution produced by the windowed FFT might result in a "nicer looking" spectrogram.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜