title: Trying to implement The inverse of a dct 8*8 matrix
body: <p>I have managed to calculate the dct of an 8*8 matrix and I am having trouble doing the inverse. Can anyone have a look at this code and tell me what I am doing now. I should be getting the exact same values as before but im getting different values. I am reading in the input from a csv file and out putting it to anther csv file. Its programmed in c</p>
  
  <pre><code>void idct_func(float inMatrix[8][8]){
  
  double idct,
  Cu,
  sum,
  Cv;
  
  int i,
  j,
  u,
  v;
  
  
  float idctMatrix[8][8],
  greyLevel;
  
  FILE * fp = fopen("mydata.csv", "r");
  FILE * wp = fopen("idct.csv", "w");
  fprintf(fp, "\n Inverse DCT");                     
  
  for (i = 0; i &lt; 8; ++i) {
      for (j = 0; j &lt; 8; ++j) { 
          sum = 0.0;  
          for (u = 0; u &lt; 8; u++) {
              for (v = 0; v &lt; 8; v++) {
              if (u == 0)
                  Cu = 1.0 / sqrt(2.0);
              else
                  Cu = 1.0;
              if (v == 0)
                  Cv = 1.0 / sqrt(2.0);
              else
                  Cv = (1.0);
              // Level around 0
              greyLevel = idctMatrix[u][v];
              idct = (greyLevel * cos((2 * i + 1) * u * M_PI / 16.0) *
                      cos((2 * j + 1) * v * M_PI / 16.0));
              sum += idct;
              }               
          }
  
          idctMatrix[i][j] = 0.25 * Cu * Cv * sum;
          fprintf(wp, "\n %f", idctMatrix[i][j]);         
      }
      fprintf(wp, "\n");
  }
  </code></pre>
  
  <p>the original matrix is:</p>
  
  <pre><code>{255, 255, 255, 255, 255, 255, 255, 255},
  {255, 255, 255, 255, 255, 255, 255, 255},
  {255, 255, 255, 255, 255, 255, 255, 255},
  {255, 255, 255, 255, 255, 255, 255, 255},
  {255, 255, 255, 255, 255, 255, 255, 255},
  {255, 255, 255, 255, 255, 255, 255, 255},
  {255, 255, 255, 255, 255, 255, 255, 255},
  {255, 255, 255, 255, 255, 255, 255, 255}};
  </code></pre>
  
  <p>the dct is :</p>
  
  <pre><code>2040   0  -0   0   0   0  -0  -0
     0   0   0   0  -0   0  -0   0
    -0   0  -0   0   0   0   0   0
     0  -0  -0  -0   0  -0  -0   0
     0   0  -0   0  -0  -0  -0   0
     0  -0  -0  -0  -0   0  -0  -0
    -0  -0  -0   0   0   0   0  -0
    -0   0   0   0  -0   0  -0   0
  </code></pre>
  
  <p>the idct calculated should be the same as the original</p>