0
$\begingroup$

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:

enter image description here

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);
$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Engineer Feb 10 at 20:17
  • $\begingroup$ @Engineer But, x3 is computed by taking the inverse FFT of real numbers too! $\endgroup$ – Abdulkader Feb 10 at 20:21
  • $\begingroup$ Ok, I missed that but what is the point? Do you need them all to be complex? $\endgroup$ – Engineer Feb 10 at 20:37
  • $\begingroup$ 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 $\endgroup$ – Engineer Feb 10 at 20:40
  • $\begingroup$ @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". $\endgroup$ – Abdulkader Feb 10 at 20:55
2
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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". $\endgroup$ – Abdulkader Feb 10 at 21:09
  • $\begingroup$ @Abdulkader See if my edit helps. $\endgroup$ – AnonSubmitter85 Feb 10 at 21:25
  • $\begingroup$ +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)? $\endgroup$ – Abdulkader Feb 10 at 21:58
  • $\begingroup$ 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? $\endgroup$ – AnonSubmitter85 Feb 10 at 22:07
  • 1
    $\begingroup$ @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. $\endgroup$ – AnonSubmitter85 Feb 10 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.