/******* * dct_transform.c * * Looking at the discrete cosine transform * *******/ #include #include // Number of points. JPEG's typically used 8x8 2-dim DCT's. #define N 8 // ------------------------------------------------------ // Define the 64 terms in the DCT and DCT_inverse matrix. void defineDCT(double dct[N][N]){ double pi = 4.0*atan(1.0); // typical way to get pi, using tan(pi/4)=1 double piOver2N = pi/(2*N); double invSqrt2 = 1.0/sqrt(2.0); double sqrt2overN = sqrt(2.0/N); double C; int u,x; for (u=0; u S matrixTimesVector(dctInv, S, ff); // inverse transform S -> ff printf("# Here's an array and its discrete cosine transform. \n"); printf("# Using N=%d.\n",N); printf("#\n"); printf("# f[x] original, S[u] transform, ff[x] restored original \n"); for (i=0; i