# Discrete Cosine Transform (DCT)

I need your help. My lecturer told me to do a study to finish the task that she gave us yesterday but the thing is there is no specific explaination on how to solve the question. Through the task, she gave us only this information. I went through youtubes in case there'll be explaination on those but so far i didnt find anything. The task is due in the next 4 days.

I don't need answer, i just need to know how it works and so on and i'll do the calculation.

[UPDATE:] Here is my calculation. So the answer for H(k) will be in vector right? If it is, i proceed with the second question but only 1/2 were multiply to the original formula for F(k) right? What can i conclude for the comparisons of both signal? Please correct me if i'm wrong.

• Where are you stuck? You have the definition of the DCT and a a bunch of numbers. Why don't you just stick the numbers in the definition and see what you get ? – Hilmar Jan 30 at 15:16
• @Hilmar For computing the DCT in (i) i just have to do the calculation like the DFT right? I get confused because the x(n) given is like in matrix form or was i wrong about this? – NURA Jan 30 at 15:21
• I don't understand what you mean by "like the DFT". You have a formula and an input. Apply the formula to the input. The input is given as a vector. Why do you think, it's a matrix ? – Hilmar Jan 30 at 15:24
• @Hilmar what about the w(k) I dont understand how to apply that. Let's say i apply the formula to the input, so the answer then will be in vector? How can i show you my calculation so far – NURA Jan 30 at 15:31
• If you want to show your work, add it to the question. w(k) just means that for the IDCT you need to multiply the first term of the sum by $1/2$ – Hilmar Jan 30 at 16:38

I can't recall which type of DCT your formula refers to, but assuming the formula is right, then the summation in the first equation computes $$N$$ coefficients of the DCT sequence $$F[k]$$ of the $$N$$-point input sequence $$x[n]$$. A similar interpretation applies to the inverse formula.

The following Matlab/Octave code implements the first formula:

N = 6;              % length of input sequence x[n], and output sequence F[k]
x = [1,0,2,5,3,7];  % the input

F = zeros(1,N);     % the output: DCT coeffs

for k = 0 :N-1
csum = 0;
for n = 0: N-1
csum = csum + 2*x(n+1)*cos((pi/(2*N))*k*(2*n+1));
end
F(k+1) = csum;
end

• You mean the N=8 right? By the way thank you for reaching out – NURA Jan 31 at 3:04
• @NURA No, N=6 is used in the example code, but you can modify it for N = 8. By the way, your added solution is wrong... Neither the forward nor the inverse transform is calculated right. Specifically, in the forward calculation F(2), F(4), and F(6) should result in being 0. And in the inverse DCT, you should be using only the first 4 coefficients F(0),F(1),F(2),F(3) in the conputation (that's what I understand from 50%), and assume remaning F(4), F(5), F(6), F(7) as zero, and you should be running the outer summation for $n$ of $x[n]$, not for $k$ of $F[k]$... – Fat32 Jan 31 at 14:22
• Can you show me one example for calculation for F(0)/ F(1)/ F(2) or any of it? Because i can't understand what you meant – NURA Jan 31 at 14:56
• Of course; given the formula $$F(k) = \sum_{n=0}^{N-1} 2 ~ x[n] ~ \cos(\frac{\pi}{2N} (2n+1) k )$$ and for the given $x[n] = [2,4,6,8,10,12,14,16]$, F(1) is calculated as : $$F(1) = 2 \times [ 2 \cos(\frac{\pi}{16})+4 \cos(\frac{\pi}{16} 3)+6 \cos(\frac{\pi}{16} 5)+8 \cos(\frac{\pi}{16} 7)+10 \cos(\frac{\pi}{16} 9)+12 \cos(\frac{\pi}{16} 11)+14 \cos(\frac{\pi}{16} 13)+16 \cos(\frac{\pi}{16} 15) ] = -51.53$$ – Fat32 Jan 31 at 19:06