Notices
Results 1 to 1 of 1

Thread: DCT/IDCT to calculate

  1. #1 DCT/IDCT to calculate 
    Forum Freshman
    Join Date
    Nov 2013
    Posts
    11
    Here is a simple C code for DCT/IDCT to calculate. main function relevant readily accessible.

    * First, the original signal is generated values​​, and print them:

    #define N 16
    double X[N];

    for (int i=0; i<N; i++)
    {
    double x=(double)i/(double)N;
    X[i] = 0.3*x*x*x*x - 0.5*x*x*x - 0.9*x*x - 0.1*x + 0.75;
    }

    for (int i=0; i<N; i++)
    printf("%.20f\n", X[i]);
    printf("\n\n");

    * Then the signal calculated for the coefficients in the function mkDCT. The soundness of coefficients is that they can be quantized and packed efficiently. For example, in GSM, the basic idea here.

    double Y[N];

    mkDCT(Y, X, N);

    for (int i=0; i<N; i++)
    printf("%.20f\n", Y[i]);
    printf("\n\n");

    * Finally, calculated on the original values ​​of the coefficients of the function mkIDCT:

    double Z[N];

    mkIDCT(Z, Y, N);

    for (int i=0; i<N; i++)
    printf("%.20f\n", Z[i]);
    printf("\n\n");

    Code:
    #include <math.h>
    #include <stdio.h>
    
    #define pi 3.14159265358979323846
    
    void mkDCT(double *dst, double *src, int N)
    {
       for (int k=0; k<N; k++)
       {
          dst[k]=0;
          for (int n=0; n<N; n++)
          {
             dst[k]+=src[n]*cos(pi*k/N*(n+0.5));
          }
       }
    }
    
    void mkIDCT(double *dst, double *src, int N)
    {
       for (int k=0; k<N; k++)
       {
          dst[k]=src[0]/2;
          for (int n=1; n<N; n++)
          {
             dst[k]+=src[n]*cos(pi*n/N*(k+0.5));
          }
          dst[k]=dst[k]*2/N;
       }
    }
    
    void main(void)
    {
       #define N 16
       double X[N];
    
       for (int i=0; i<N; i++)
       {
          double x=(double)i/(double)N;
          X[i] = 0.3*x*x*x*x - 0.5*x*x*x - 0.9*x*x - 0.1*x + 0.75;
       }
    
       for (int i=0; i<N; i++)
       printf("%.20f\n", X[i]);
       printf("\n\n");
    
       double Y[N];
    
       mkDCT(Y, X, N);
    
       for (int i=0; i<N; i++)
       printf("%.20f\n", Y[i]);
       printf("\n\n");
    
       double Z[N];
    
       mkIDCT(Z, Y, N);
    
       for (int i=0; i<N; i++)
       printf("%.20f\n", Z[i]);
       printf("\n\n");
    }


    Reply With Quote  
     

  2.  
     

Similar Threads

  1. Wavelength Calculate
    By NOF in forum Physics
    Replies: 4
    Last Post: March 20th, 2011, 07:25 AM
  2. How to Calculate This?
    By IAlexN in forum Mathematics
    Replies: 7
    Last Post: March 31st, 2010, 04:39 PM
  3. Can you calculate an EMP?
    By celtic_warrior in forum Physics
    Replies: 33
    Last Post: November 14th, 2008, 01:44 AM
  4. How to calculate the ZHR
    By ricci70 in forum Astronomy & Cosmology
    Replies: 0
    Last Post: September 5th, 2008, 04:07 AM
  5. Calculate the odds
    By Metatron in forum Mathematics
    Replies: 23
    Last Post: July 1st, 2006, 04:58 PM
Bookmarks
Bookmarks
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •