HW 2, EECS 207A. Fall 2004. UCI.
First problem.

by Nasser Abbasi

Problem

The following  table displays the pixel intensity values of a macro block of a 1-dimensional image
   60, 75, 86, 200, 235, 255, 46, 34
a) compute the DCT coefficients of this function.
b) compute the original function from the DCT using the IDCT algorithm
c)Ignore the last 4 bytes and recompute the original function, how much error is introduced?

extra work: I also did an edditional analysis on this problem. I showed how the error in data changes as a function of number of terms dropped from the DCT table

Part(a)


Define the DCT and IDCT functions

In[923]:=

Clear["Global`*"] ;  buildDCT[i_, data_, c_] := Module[{L = Length[data]}, & ... 0, arg3] c〚n + 1〛 dct〚n + 1〛 Cos[((2i + 1) n π)/(2 L)] ]

Define the data and create  the C table

In[1005]:=

(*originalData = {128, 88, 40, 0, 0, 40, 88, 128} ; *)(*originalData = ... ength[originalData] ; c = Table[2/L^(1/2), {L}] ; c〚1〛 = 1/L^(1/2) ;

Create the DCT values, and print them

In[1009]:=

dct = Table[buildDCT[i, originalData, c], {i, 0, L - 1}] ; Print["DCT values = ", Ta ... e= ", TableForm[N[c], TableDirections-> {Row, Column}, TableSpacing-> {1, 6}]]

DCT values =  350.37141007793434`  -25.553247301809677` -199.61663785333434` 100.5791305626152`   23.68807716974934`   -38.03482396224932`  36.37922335799363`   -58.615034025083084`

Original data =  60  75  86  200 235 255 46  34

C constants table=      1     1         1         1         1         1         1      ...                            2 Sqrt[2] 2         2         2         2         2         2         2

Part(b)

Use IDCT to recompute the original data, i.e. use all DCT points.

In[1013]:=

endIndex = Length[dct] - 1 ; dataNew = Table[buildIDCT[i, dct, c, endIndex], {i, 0, L - 1}] ;  ... quot;, TableForm[Chop[N[dataNew]], TableDirections-> {Row, Column}, TableSpacing-> {1, 6}]]

data back from IDCT =  59.99999999999997`  75.00000000000003`  86.`                200.00000000000009` 235.`               254.99999999999994` 46.00000000000006`  33.999999999999936`

Part(c)

In[1016]:=

bytesToIgnore = 4 ; endIndex = Length[dct] - bytesToIgnore - 1 ; dataNewShort = Table[buildIDC ... eForm[ N[Abs[error]/dataNew 100] , TableDirections-> {Row, Column}, TableSpacing-> {1, 6}]]

data back from IDCT =  60.94725790654645`  65.24562813621868`  105.64841290072575` 185.6538819065822`  246.51784415483115` 218.4915672301674`  106.11439173288822` 2.381016032040236`

Absolut error       =  -0.9472579065464668` 9.75437 ... 346118093417878`  -11.517844154831145` 36.50843276983255`   -60.114391732888166` 31.6189839679597`

% error             =  ... 7.173059046708936`  4.9012102786515515` 14.317032458757868` 130.68346028888715` 92.99701167046987`

Extra work. Generate table showing how much error (in percentage) in the data recomputed as we drop more terms in the DCT. Try from 1 to 7 terms dropped.

In[1023]:=

 L = Length[dct] ; data = Table[i, {i, 1, L - 1}, {j, 1, L}] ; For[n = ... ll〛 = Table[buildIDCT[i, dct, c, endIndex], {i, 0, Length[dct] - 1 }] ; } ]

Data recomputed, each row shows the data based on dropping as many terms from DCT as the row number-1.
For example, the first row shows the data recomputed if we dropped ZERO terms from DCT.
The second row shows the data recomputed if dropped ONE term from DCT, etc...

In[1130]:=

Print["Original input data\n", TableForm[originalData, TableDirections-> {Row, Co ... es as more DCT terms are dropped\n"MatrixForm[Chop[N[data〚All, All〛]]]]

Original input data\n 60  75  86  200 235 255 46  34  \nTable showing the reco ... 437766609`   126.36759562233391`   130.97331177893696`   134.49837431355337`   136.40612441005925`

In[1144]:=

RowBox[{(* now compute the error in % *), , RowBox[{error = Table[i, {i, 1, L - 1}, {j ... ity}], ]}]}], ;}], , Show[{g1, g2}, DisplayFunction$DisplayFunction], }]}]

Table showing the % erorr in each data term as more DCT terms are dropped ( 0. ... 166954`    46.226555054326`       48.63791694943649`     192.38777024685513`    301.1944835589978`

Average error in data as more DCT terms are dropped       ] ...                                                                                100.01470799432798`

[Graphics:HTMLFiles/index_19.gif]

Out[1152]=

⁃Graphics⁃

[Graphics:HTMLFiles/index_21.gif]

Out[1155]=

⁃Graphics⁃

Conclusion

The Max error in the recomputed data array increases as more DCT terms are dropped. But that is not always true each time. In this example, as we dropped the 6th term in the DCT table, the max error was actually smaller, but we see that the average error in data is always increasing as expected. I am not sure now why the max error in data did not go down every time we dropped an additional term from the DCT. This needs more investigation. I have tried this on another data input and saw the same result.


Created by Mathematica  (October 21, 2004)