4
$\begingroup$

0

I have a vector x of length N x 1, I need to perform the iDCT operation for it using MATALB. I performed that using the below method:

x = [1+i;1-i;-1+i;1+i];    %Assume N = 4
y = sqrt(4)*idct(x); 

Then I performed it using the other way such that:

x = [1+i;1-i;-1+i;1+i];    %Assume N = 4
D= dctmtx(4)/sqrt(4); 
y = D'*x;

I don't find the value of y equals in the two ways ?? However for the case of of FFT operations, that gives the same results!

Is there a special case for DCT operation?

$\endgroup$

1 Answer 1

1
$\begingroup$

Pay attention that by default MATLAB use DCT Type II hence the inverse is basically DCT Type III:

vX = [1 + 1i; 1 - 1i; -1 + 1i; 1 + 1i];    %Assume N = 4
vY = dct(vX); 
mD = dctmtx(length(vX));
vYY = mD * vX;

vYY ./ vY
max(abs(vY - vYY))

vY = idct(vX);
vYY = mD.' * vX;

vYY ./ vY
max(abs(vY - vYY))

The result:

ans =

   1.0000 + 0.0000i
   1.0000 + 0.0000i
   1.0000 - 0.0000i
   1.0000 + 0.0000i


ans =

   4.9651e-16


ans =

   1.0000 - 0.0000i
   1.0000 - 0.0000i
   1.0000 + 0.0000i
   1.0000 + 0.0000i


ans =

   4.5776e-16

So everything works as expected.

Pay attention that in your code using the transform you multiply by factor sqrt(4) and for the matrix form you divide by this factor.

So:

vY = sqrt(4) * idct(vX);
vYY = (mD' / sqrt(4)) * vX;

vY ./ vYY

ans =

   4.0000 + 0.0000i
   4.0000 + 0.0000i
   4.0000 + 0.0000i
   4.0000 - 0.0000i

So just don't divide and use the same factor and all is good.

$\endgroup$
2
  • $\begingroup$ You mean when performing the idct in MATLAB, It should be directly, idct(x); I shouldn't multiply by sqrt(length(x)), right? Is that applicable for ifft? because in all cases of ifft operations, we usually multiply by sqrt(length(x)). $\endgroup$ Commented Sep 14, 2020 at 4:16
  • $\begingroup$ You can multiply by any factor. But you must multiply the matrix in the same factor as well. The problem in your code is you multiply the idct() while you divide the matrix. $\endgroup$
    – Royi
    Commented Sep 14, 2020 at 5:41

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.