# How should this fft output be intepreted?

I am currently reading some code, so I can understand how this FFT output is actually been stored.

I have a function which computes FFT of audio file, and stores is in the format.

[real0, realN/2-1, real1, im1, real2, im2, ...]


which kind of confuses me, as I remember DFT/FFT converts from time domain to frequency domain, in which the real part is the amplitude, and the complex part is the phase, but aren't I missing some information regarding what frequency has what amplitude and what phase?

• Am I missing something?
• Or am I right when i say that I can't from these complex numbers extract the amplitude for a certain frequency?

I am currently using Kaldi framework, in which i am trying to compute the spectogram of an audio file...

The output file it has generated looks like this.

This output was generated from a 1 second audio file. sampled with 16 kHz, and frame length = 25 ms and hop_length = 10ms. The number of datapoint the function has generated is 25816. I am not sure how i should interpret it, i mean is each value supposed to be the power for a given frequency, and if so which frequency ?

"[...] the real part is the amplitude, and the complex part is the phase [...]" No, complex numbers (and that's what the output of a DFT/FFT is) can be represented either by their real and imaginary parts (as in the output vector of your routine), or by their magnitudes and phases. Please refer to the linked page on how to convert one representation to the other.

The indices $i=0,1,\ldots N-1$ of the output vector of a length $N$ DFT/FFT are related to actual frequencies via the sampling frequency $f_s$:

$$f_i=\frac{if_s}{N}$$

If the input vector is real-valued, the first $N/2+1$ values (assuming $N$ is even) contain all information about the signal.

you can definitely extract the amplitude for a particular frequency bin(which might include few frequencies depending on your DFT resolution).

Am I missing something? or am I right when i say that i can't from these complex numbers extract the amplitude for a certain frequency?

So you are not exactly right that you can't extract amplitude of particular frequency. you can extract amplitude for a particular frequency bin using real and imaginary part corresponding to its index in your array.

Let us start with a typical FFT output for real signal $[1\,, 2\,, 3\,, -4 \,,-5\,, 6]$ of length $N=6$:

$$3 + 0i \,, 10 - 3.4641i \,, -6 +10.3923i \,, -5 + 0i \,, -6 -10.3923i \,, 10 + 3.4641i$$

Coefficient $c_0$ and $c_3$ are real, $c_1$ and $c_5$ are complex conjugate, as for $c_2$ and $c_4$. So knowing $c_0$ to $c_3$ only, you can reconstruct $c_4$ and $c_5$. So basically, you only need coefficients $c_0$ to $c_{6/2}$ (hence apparently $N/2+1$ coefficients) to have all the information you need.

In general, if you have an even number $N$ of samples, the standard representation follows the same pattern: $c_0$ and $c_{N/2}$ are real (always), the others can be complex. To store complex coefficients in a real array, all coefficients $c_j$ from $c_1$ and $c_{N/2-1}$ require two reals, the real and the imaginary part: $\text{re} {c_j}$ and $\text{im} {c_j}$. For storage convenience, the two coefficients $c_0$ and $c_{N/2}$ can be stored in a duplet as well. Thus, you can store all required coefficients in a $N/2\times 2$ array, as done in your example. All coefficients are real/imag duplets, except the first duplet, gather the two (always) real coefficients. This is described in HOMEOSTASIS / kaldi-rocio:

// now we have in waveform, first half of complex spectrum
// it's stored as [real0, realN/2-1, real1, im1, real2, im2, ...]


Hence your: $[c_0\,,c_{N/2}\,,\text{re} {c_1}\,,\text{im} {c_1}\ldots ]$

Yet, honestly, I do not really understand why realN/2-1 is used (the -1 part).

• Well... Yes, I am using the kaldi framework, and I am currently trying to display the spectogram. Jan 12, 2017 at 0:14
• I changed the question, adding Kaldi.. Jan 12, 2017 at 0:19