问题
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?
回答1:
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)
)
回答2:
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.
来源:https://stackoverflow.com/questions/6581001/how-to-convert-wave-data-into-complex-numbers