DCTII

From Citizendium, the Citizens' Compendium
Jump to: navigation, search

DCTII is one of realizations of the DCT transform operator (Discrete Cosine transform); it is one of many discrete analogies of the integral operator CosFourier

The name DCTII is chosen in analogy with the Wikipedia article [1] and notations by the Numerical recipes in C [2]. Other realizations of DCT are called DCTI, DCTIII and DCTIV.

For a given natural number , operator converts any array of length to the array with elements

,

As in the case of other discrete Fourier transforms, the numeration of elements begins with zero. For the simple and efficient implementation, for some natural number . Note that the size of the arrays is for unity smaller than in the case of DCTI.

Numerical implementation and example

Numerilal implementation of the transform DCTII consists of 3 files: zfour1.cin, zrealft.cin, zcosft2.cin.

The example of the C++ call below calculates the expansion of function represented at the array with for  ; this corresponds to superopsition of three symmetric modes of a cavity of width with boundary condition . In the example, .

#include<math.h> 
#include<stdio.h>
#include <stdlib.h>
using namespace std;
#include <complex>
#define z_type double
#include"zfour1.cin"
#include"zrealft.cin"
#include"zcosft2.cin"
main(){ z_type *a, *b, *c; int j; unsigned long N=8;
a=(z_type *) malloc((size_t)((N)*sizeof(z_type)));
b=(z_type *) malloc((size_t)((N)*sizeof(z_type)));
c=(z_type *) malloc((size_t)((N)*sizeof(z_type)));
for(j=0;j<N;j++) a[j]=b[j]=cos( M_PI/N*.5*j);
zcosft2(a-1,N,-1);
for(j=0;j<N;j++) c[j]=a[j];
zcosft2(a-1,N,1);
for(j=0;j<N;j++) printf("%12.9f %12.9f %12.9f\n",b[j], c[j], a[j]);
free(a);
free(b);
free(c);
}

The example generates the following output:

 0.19634954  1.11000000  4.00000000  4.44000000
 0.58904862  1.06948794  0.40000000  4.27795178
 0.98174770  0.95832104  0.04000000  3.83328417
 1.37444679  0.80215273  0.00000000  3.20861091
 1.76714587  0.62932504  0.00000000  2.51730014
 2.15984495  0.45944261 -0.00000000  1.83777043
 2.55254403  0.29953427  0.00000000  1.19813710
 2.94524311  0.14784799  0.00000000  0.59139198

The 0th column repressents the chosen values of coordinate

The 1st column shows values

The 2d column shows the

The 3d (last) column shows array , which coincides with the initial array multiplied with factor 4; it confirms that the transform DTCIII can be used to invert DTCII.

Approximation of CosFourier

Let be smooth even function quickly decaying at infinity; let be large natural number.

Let ;

Let for integer values , and
Let .

Then, in the definition of the CosFourier transform, the integral can be replaced with sum, giving

where .

For , the CosFourier transform of evaluated at can be approximated as follows:

Note that DCTII approximation of CosFourier transform at points, displaced for half–step with respect to those at which the function is evaluated. This may be considered as explanation why the second iteration of operation DCTII does not give a factor of the Identity transform.

Note, that mode points for the initial function and those for the transform do not coincide, as it takes place in the case of DCTI.

Relation with other DCF

Inverse of DCTII can be easy expressed through DCTIII (Which is another discrete approximation of the CosFourier operator) and vice versa:

References

  1. http://en.wikipedia.org/wiki/Discrete_cosine_transform
  2. http://88.167.97.19/albums/files/TMTisFree/Documents/Physics/11%20-%20Fourier%20Transform%20Spectral%20Methods.pdf W.H.Press, B.P.Flannery, S.A.Teukolsky, W.T.Vetterling. Numerical Recipes in C. Fast Sine and Cosine transform.

The content of this article is adopted from http://tori.ils.uec.ac.jp/TORI/index.php/DCTII