On Fri, May 11, 2012 at 11:45 AM,  <m...@hushmail.com> wrote:
> This is really not a problem in Octave or its packages, but rather me trying
> to get help from the devs here to modify my implementation in such a way
> that I get consistent results.
>
> The challenge I am facing right now is implementing a DCT/IDCT in C that its
> output matches that of Octave.
>
> My testing input matrix (x):
>    1   1   1
>    2   2   2
>    3   3   3
>
> Octave's DCT function results in (dct2(x)):
>    3.46410   3.46410   3.46410
>   -1.41421  -1.41421  -1.41421
>    0.00000   0.00000   0.00000
>
> Octave's IDCT function results in (idct2(x)):
>    1   1   1
>    2   2   2
>    3   3   3
>
> So far so good?

I don't have access to Octave-Forge or ML dct2 at the moment, but can
you confirm whether you were using dct/idct or dct2/idct2?  You can
see that the columns are the same at all of your stages, which
indicates that you are doing a 1D DCT over each column independently.
If you were using dct2 and idct2 this might be a bug, I have not
looked at the OF code yet.

> Below is my implementation in C via FFTW3 (which gives diff.
> results). My C code is pasted here: http://codepad.org/cHErvFMn
>
> My DCT (via FFTW3) results are different:
> 72.00 0.00 0.00
> -20.78 0.00 0.00
> 0.00 0.00 0.00
>
> My IDCT is correct but scalled (if I divide them all by 36, it gets OK):
> 36.00 36.00 36.00
> 72.00 72.00 72.00
> 108.00 108.00 108.00
>
> Any idea how to alter my code in such a way to get results identical to that
> of Octave?

I altered your code to do a 1D DCT on a single 3-element array, one of
the columns above, added in the normalizing factors that were
mentioned in your links, and got the following output which matches
your Octave output:

enter a 3 by 1 matrix separated by space and/or new line
1 2 3
1.00 2.00 3.00
dct:
3.46 -1.41 0.00
idct:
1.00 2.00 3.00

> Links that I found so far:
> * this guy seems to have explained it (but didn't fully get it):
> http://www.dsprelated.com/showmessage/93988/1.php
> * FFTW3's page on DCT/IDCT
> http://www.fftw.org/doc/1d-Real_002deven-DFTs-_0028DCTs_0029.html
> * Matlab's page on DCT/IDCT (which should match Octave's imp.)
> http://www.mathworks.com/help/toolbox/signal/ref/dct.html
> * Wiki's page on
> DCT/IDCThttp://en.wikipedia.org/wiki/Discrete_cosine_transform#DCT-II
>
> To me, all of the links are presenting different equations. Which makes me
> wonder what is really going on.

So yes, they are all essentially the same transform with slightly
different normalizing factors.

This part is OT, you can contact me off-list if you want more
information on what I did with your FFTW code.

-- 
mike

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to