How to convert wave data to complex numbers

I read the raw data from the microphone and feed it to the FFT. Two of the FFT libraries I'm trying ( AForge and Exocortex. DSP ) take complex numbers as input and give complex numbers as output.

I am trying to understand what are complex numbers.

More specifically, how do you convert raw audio data received from a microphone into complex numbers for processing in FFT?
And how can I build a conclusion on a good spectrogram (that is, by reading the frequencies and amplitudes from the output)?

Bonus added: what FFT libraries exist for .Net, except for the two mentioned?

+6
source share
2 answers

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

The construction of the spectral graph is more complicated - it contains previous reports on SO, but essentially you need to calculate the power spectrum for successive overlapping time windows (typical overlap = 50%), and then plot the log (dB) values ​​of these power spectra using intensity color or gray scale for the value (with time on the X axis and frequency on the Y axis usually). To calculate the power spectrum:

  • apply window function for data input (for example, Hanning window)
  • Fft
  • take the square of the square of the first N/2 FFT output values ​​( re*re + im*im )
  • convert value to dB value ( 10 * log10 (magnitude squared) )
+5
source

To build a "beautiful" spectrogram:

FFT calculates the local spectrum of your data, minimized with window conversion.

If you do not use the window function in front of the FFT, then the window function by default turns out to be a rectangular window of FFT length, which has a transform that may seem pretty ugly if you do not expect this (some call this spectral leakage). You might want to try using some other window function (Von Hann, et.al.), where the convolution created by the window FFT can lead to a β€œmore pleasant” spectrogram.

+1
source

Source: https://habr.com/ru/post/892014/


All Articles