DCTII

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 $$\displaystyle (\mathrm{CosFourier}~F)(x)= \sqrt{\frac{2}{\pi}} \int_0^\infty \cos(xy)~ F(y) \mathrm d y $$

The name DCTII is chosen in analogy with the Wikipedia article and notations by the Numerical recipes in C .

Explicit definition of DCTII
For a given natural number $$N converts any array F of length N 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, N=2^q for some natural number q. 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 x_n=d n for d=\pi/(2N) ; this corresponds to superopsition of three symmetric modes of a cavity of width \pi with boundary condition F(\pi/2)=0. In the example, N=8.


 * 1) include

The 1st column shows values F_n=F(x_n)

The 2d column shows the

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

Approximation of CosFourier
Let F be smooth even function quickly decaying at infinity; let N be large natural number.

Let ;

Let  for integer values n, and Let x_n= n d~.

Then, in the definition of the CosFourier transform, the integral can be replaced with sum, giving where F_n=F(y_n).

For x=x_k, the CosFourier transform of F evaluated at x can be approximated as follows:

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

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:
 * $$ \displaystyle

(\mathrm {DCTII}_N ~ \mathrm {DCTIII}_N ~F)_n= (\mathrm {DCTIII}_N ~ \mathrm {DCTII}_N ~F)_n= \frac{N}{2} F_n$$