# MATLAB: Applying Inverse Fast Fourier Transform to an array of real numbers

I'm trying to understand the difference between applying the Discrete Cosine Transform (DCT) and the Inverse Discrete Fourier Transform (IDFT) to the log Mel-filterbank energies as explained in the answer here. So, I tried the following pretty simple example in MATLAB:

x1 = [1. 2. 3.];
X1 = fft(x1);
x2 = ifft(abs(X1));
x3 = ifft(x1);


The classes of the results are: Why do x2 and x3 have two different classes?

Update:

Here is the file 'myVoice.wav' in the following test:

[signal, fs] = audioread('myVoice.wav');
segmentLength = 240;
x = signal(20490 : 20490 + segmentLength - 1);
x = x .* hamming(segmentLength);
res = ifft(abs(fft(x)) .^ 2);

• This may be off-topic since it doesn't have a direct signal processing question to it, but x2 is type double because the magnitude of X1 is no longer complex. Same logic goes for x3, it is computed by taking the inverse FFT of a complex vector so it too is complex Feb 10, 2020 at 20:17
• @Engineer But, x3 is computed by taking the inverse FFT of real numbers too! Feb 10, 2020 at 20:21
• Ok, I missed that but what is the point? Do you need them all to be complex? Feb 10, 2020 at 20:37
• You know what inverse FFT is right? It makes sense it would return complex values. If you need everything to be complex you can always do complex(x, 0) to the real vectors and there you go, they are now complex Feb 10, 2020 at 20:40
• @Engineer Yes, I know what IFFT is, but I want to understand why does the ifft function return vectors of two different classes in this example! Also, when I applied ifft to the power spectrum (a real-valued vector) of a speech window, it returns a real-valued vector instead of a complex-valued vector, while the answer in the attached link said: "after applying the ifft we get complex-valued coefficients". Feb 10, 2020 at 20:55

Since $$\vert X_1 \vert$$ is a real even function, its FFT (IFFT) is a real function. This is a basic property of Fourier transforms.

The power spectrum can be real but not even, in which case the ifft will give complex coefficients. In the example you linked, they start with a non-even real signal and then take the FFT. This will give complex values coefficients for the FFT. The answer then says that

The problem is that we have only our log-energies, no phase information, so after applying the ifft we get complex-valued coefficients

So, after taking the FFT, the phase is discarded, and this loss of information makes it impossible to get back to the original real signal. (The Fourier transform is bijective). Once the phase is discarded you have a real but non-even function, the IFFT of which will yield complex coefficients.

• Could you please give more details, because when I applied ifft to the power spectrum (a real-valued vector) of a speech window, it returns a real-valued vector instead of a complex-valued vector, while the answer in the attached link said: "after applying the ifft we get complex-valued coefficients". Feb 10, 2020 at 21:09
• @Abdulkader See if my edit helps. Feb 10, 2020 at 21:25
• +1 Thank you for these useful details. The following two points are still unclear for me: 1) Why is the power spectrum $|DFT(x[n])|^2$ not even function, but the amplitude spectrum $|DFT(x[n])|$ is a real even function? 2) Why is the result of ifft(abs(fft(my_windowed_signal)) .^ 2) a real-valued vector (not complex-valued)? Feb 10, 2020 at 21:58
• If the amplitude of the DFT is an even function, then so must be its squared value. As for ifft(abs(fft(my_windowed_signal)) .^ 2) being real-valued, it must be the case that its even. If my_windowed_signal is real-valued, then I think that is guaranteed to be the case. Can you include some example inputs that are causing confusion? Feb 10, 2020 at 22:07
• @Abdulkader Your input is real-valued, so its FFT is even symetric. Thus, its power (i.e., abs(X).^2) is also even symmetric and its IFFT will be real-valued. Feb 10, 2020 at 22:39