0
$\begingroup$

Sorry if this sounds like a stupid question, I'm new to DCT.

I've implemented various types of DCT (like IV and II) and they all give vastly different coefficients. From what I've read, the DCT expresses a signal as a sum of cosine waves with various oscillating frequencies. How can different formulas that give different coefficients express the same signal? I created 7 cosine waves (With one DC coefficient) on a graph with proportional periods according to N, and summed them but end up with a function that doesn't represent the signal at all. I'm probably doing this wrong, but here's what I did:

Calculated the 1D-DCT-II of this array:
[1 2 3 4 5 6 7 8]

DCT:

[12.727922061358 -6.4423230227051 -1.3322676295502E-15 -0.67345480090394 0 -0.200902903736 -1.5765166949677E-14 -0.050702322759621]

Now I don't know if this is how to do it but I tried this (with a window of length 8):

12.72 + -6.44cos((pi/7)x)+ 0cos((pi/3.5)x)...

I can use the inverse DCT (DCT-III) and get the input values back, but I want to see the signal that represents the original input values. I tried summing the frequencies but I don't know if I'm doing it right so can someone guide me? Btw the formula I used was

$y[$n]= $realarray[$n]*cos((M_PI/$N)*($n+0.5)*($k));

$\endgroup$
  • $\begingroup$ Have you looked at how the DCT variations are defined? $\endgroup$ – Batman Jan 4 '17 at 0:23
  • $\begingroup$ Wikipedia: Using the normalization conventions above, the inverse of DCT-I is DCT-I multiplied by 2/(N-1). The inverse of DCT-IV is DCT-IV multiplied by 2/N. The inverse of DCT-II is DCT-III multiplied by 2/N and vice versa. $\endgroup$ – msm Jan 4 '17 at 1:16
  • $\begingroup$ I was curious as to how exactly would one find the individual waves and plot it on a graph to show that the summation of the cosine waves is equal to the signal at (x=0, x=1, x=2 ... x=N-1) For example, do we use the (coefficient of N0)cos(0x)+(coefficient of N1)cos(1x)+... (coefficient of N-1)cos((N-1)x)? $\endgroup$ – Nicolas du Roy Jan 7 '17 at 10:42
1
$\begingroup$

You used the DCT-II with a certain scaling convention:

$$X[k]=s[k]\sum_{n=0}^{N-1}x[n]\cos\left(\frac{\pi}{2N} (2n+1)k\right),\qquad k=0,1,\ldots,N-1\tag{1}$$

where $s[0]=1/\sqrt{N}$, and $s[k]=\sqrt{\frac{2}{N}}$ for $k=1,\ldots,N-1$. Its inverse is given by an appropriately scaled DTC-III:

$$x[n]=\sum_{k=0}^{N-1}s[k]X[k]\cos\left(\frac{\pi}{2N} (2n+1)k\right),\qquad n=0,1,\ldots,N-1\tag{2}$$

where $s[k]$ are the same scaling coefficients as used in $(1)$.

So, given the scaled DCT-II coefficients $X[k]$, the original signal can be written as

$$x[n]=\sqrt{\frac{2}{N}}\left[\frac{1}{\sqrt{2}}X[0]+X[1]\cos\left(\frac{\pi(2n+1)}{2N}\right)+X[2]\cos\left(\frac{\pi(2n+1)}{N}\right)+\ldots\right]$$

$\endgroup$
  • $\begingroup$ You forgot to add k in the last equation. k increments by one after each instance of addition. I tried with and without k and the signal is only represented if k is used $\endgroup$ – user4757174 Jan 4 '17 at 23:56
  • $\begingroup$ @user4757174: Yes, that was a typo, it's corrected now. But it was just the last term, the first two terms were correct. $\endgroup$ – Matt L. Jan 5 '17 at 8:32

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.