Related to Could a DCT be used for an audio magnitude spectrum rather than DFT?, but more on the (audio) spectrogram side of things

I've been reading about the DCT (such as from here) and it seemingly provides quite a few advantages over the DFT such as having more frequency bins for the same number of samples and better power compaction, which sounds useful for signal analysis.

Yet all the programs I've used that have spectrograms seems to use the (magnitude of) DFT rather than DCT. Why is that? Is there something bad or "missing" from the DCT that is important for spectrograms?

(Note: I already understand the benefits of the DCT for compression, and this question is about audio (or other time-displacement) signals, so please avoid focusing too much on compression or images)

  • $\begingroup$ Curiously, I DCT'd a piece of music and then IDFT'd it back (making sure to append a mirrored DCT'd signal before feeding it to the IDFT and then unmirroring) and it sounded the same, though it had some small differences in the DFT spectrum of both. Taking the difference of both the signals also produced a rather small difference. $\endgroup$
    – 小太郎
    Jan 31, 2016 at 17:21
  • $\begingroup$ I recommend you actually look up the formulas for both DFT and DCT; you'll notice why the IDCT(DFT(signal)) is similar to the original signal. $\endgroup$ Jan 31, 2016 at 18:53

1 Answer 1


Let's define the N-point IDFT $y[n]$ of a signal $Y[f]$ as

$$\begin{align*} y[n] &= \sum\limits_{f=0}^{N-1} Y[f] e^{j2\pi n\,\frac{f}{N}},& n\in \{0,\dots,N-1 \}\tag{1} \end{align*}$$ The DCT-II (which is most probably what we're looking at; the others are mathematically useful, but less nice to implement) $\mathbf{Y}[f]$:

$$\begin{align*} \mathbf{Y}[f] &= \sum\limits_{n=0}^{N-1} y[n] \cos\left(\pi (k+\frac12) \frac nN \right) ,& f\in \{0,\dots,N-1\}\\ &\text{which, Euler says, is}\\ &= \frac12 \sum\limits_{n=0}^{N-1} y[n]\left(e^{j\pi (k+\frac12) \frac nN } + e^{-j\pi (k+\frac12) \frac nN }\right),& f\in \{0,\dots,N-1\}\text.\tag{2} \end{align*}$$

Now, calculating the inverse discrete Fourier of the discrete cosine transform becomes but a matter of diligence; calculating by inserting $(2)$ into $(1)$, you'll notice that the complex sinusoids are orthogonal w.r.t. the scalar product, ie. the sum over the element-wise products becomes zero for everything but the same exponents.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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