2
$\begingroup$

I'm trying to work out what the correct solution is for a DCT of a 4x4 checkerboard matrix (let's call it A) and for a matrix of ones (let's call it B). So A is:

   0   1   0   1
   1   0   1   0
   0   1   0   1
   1   0   1   0

And B is:

   1   1   1   1
   1   1   1   1
   1   1   1   1
   1   1   1   1

With Octave for dct(A) I get:

   1.00000   1.00000   1.00000   1.00000
  -0.38268   0.38268  -0.38268   0.38268
   0.00000   0.00000   0.00000   0.00000
  -0.92388   0.92388  -0.92388   0.92388

And for dctmtx(4) * A * transpose(dctmtx(4)) (which should be equivalent) I get:

   2.00000   0.00000  -0.00000  -0.00000
   0.00000  -0.29289  -0.00000  -0.70711
  -0.00000  -0.00000   0.00000  -0.00000
  -0.00000  -0.70711  -0.00000  -1.70711

And then dct(B):

   2   2   2   2
   0   0   0   0
   0   0   0   0
   0   0   0   0

And dctmtx(4) * B * transpose(dctmtx(4)):

   4   0   0   0
   0   0   0   0
   0   0   0   0
   0   0   0   0

What's going on? Which is correct?

$\endgroup$
3
$\begingroup$

As far as I can see, there are two little mistakes. First of all, you should use dct2() instead of dct(). And second, you shouldn't use the 'transpose' function because you want the DCT matrix not only transposed but also conjugated. So you should do the following: $$\tt{T=dctmtx(4); DCTB = T*B*T'}$$ And this should equal $\tt dct2(B)$.

EDIT: As correctly pointed out by Peter K., the DCT matrix is real-valued, so indeed the 'transpose' operation and the ' operation give the same result. So I only noticed ONE little mistake ...

| improve this answer | |
$\endgroup$
  • $\begingroup$ I think the DCT matrix should be real-valued... so conjugation doesn't matter, yes? $\endgroup$ – Peter K. Apr 25 '13 at 15:23
  • 1
    $\begingroup$ Oh, sure, you're right of course! For some reason I had the DFT matrix in my mind ... I'll correct it in my answer. $\endgroup$ – Matt L. Apr 25 '13 at 16:00

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.