How to convert wave data into Complex numbers

2019-03-29 06:28发布

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 mentioned?

2条回答
狗以群分
2楼-- · 2019-03-29 07:07

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))
查看更多
对你真心纯属浪费
3楼-- · 2019-03-29 07:09

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.

查看更多
登录 后发表回答