Converting Real and Imaginary FFT output to Frequency and Amplitude

12,296

Solution 1

The FFT result will give you an array of complex values. The twice the magnitude (square root of sum of the complex components squared) of each array element is an amplitude. Or do a log magnitude if you want a dB scale. The array index will give you the center of the frequency bin with that amplitude. You need to know the sample rate and length to get the frequency of each array element or bin.

f[i] = i * sampleRate / fftLength

for the first half of the array (the other half is just duplicate information in the form of complex conjugates for real audio input).

The frequency of each FFT result bin may be different from any actual spectral frequencies present in the audio signal, due to windowing or so-called spectral leakage. Look up frequency estimation methods for the details.

Solution 2

Well, the bad news is, there's no way around needing to understand complex numbers. The good news is, just because they're called complex numbers doesn't mean they're, y'know, complicated. So first, check out the wikipedia page, and for an audio application I'd say, read down to about section 3.2, maybe skipping the section on square roots: http://en.wikipedia.org/wiki/Complex_number

What that's telling you is that if you have a complex number, a + bi, you can picture it as living in the x,y plane at location (a,b). To get the magnitude and phase, all you have to do is find two quantities:

  • The distance from the origin of the plane, which is the magnitude, and
  • The angle from the x-axis, which is the phase.

The magnitude is simple enough: sqrt(a^2 + b^2).

The phase is equally simple: atan2(b,a).

Share:
12,296
Dave Moore
Author by

Dave Moore

Updated on July 13, 2022

Comments

  • Dave Moore
    Dave Moore almost 2 years

    I'm designing a real time Audio Analyser to be embedded on a FPGA chip. The finished system will read in a live audio stream and output frequency and amplitude pairs for the X most prevalent frequencies.

    I've managed to implement the FFT so far, but it's current output is just the real and imaginary parts for each window, and what I want to know is, how do I convert this into the frequency and amplitude pairs?

    I've been doing some reading on the FFT, and I see how they can be turned into a magnitude and phase relationship but I need a format that someone without a knowledge of complex mathematics could read!

    Thanks


    Thanks for these quick responses!

    The output from the FFT I'm getting at the moment is a continuous stream of real and imaginary pairs. I'm not sure whether to break these up into packets of the same size as my input packets (64 values), and treat them as an array, or deal with them individually.

    The sample rate, I have no problem with. As I configured the FFT myself, I know that it's running off the global clock of 50MHz. As for the Array Index (if the output is an array of course...), I have no idea.

    If we say that the output is a series of One-Dimensional arrays of 64 complex values:

    1) How do I find the array index [i]?

    2) Will each array return a single frequency part, or a number of them?

    Thankyou so much for all your help! I'd be lost without it.