DCTIII

DCTIII 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 DCTIII is chosen in analogy with the Wikipedia article [1] and notations by the Numerical recipes in C [2]. Other realizations of the DCT are called DCTI, DCTII, 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.

Inverse operator

Inverse of DCTIII can be easily expressed through the DCTII defined with

, 

as



Applications

DCTIII can be used for the assembling of a symmetric field in a cavity of length  with given coefficients  in the series below. Let



Then at points [/itex]x_m=\pi m/N[/itex] the field can be approximated with



where [/itex]a[/itex] is array of coefficients above.

The inverse operation, id est, calculation of the Fourier coefficients for the symmetric field known at porints ,  can be performed with DCTII as follows:



These coefficients correspond to the expansion of the filed with symmetric modes of cavity of width [/itex]\pi[/itex]. Similar expansion using the only antisimmetric modes can be performed with the DST (Discrete sine transform).

Numerical implementation and example

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

In the example below, the field  is evaluated in the points with coordinates        . This field corresponds to the cavity of length ; the modes become zero at ; the only symmetric modes are considered. Wave–numbers of symmetric modes are , , , ; only 4 symmetric modes are excited in the example; the field  is constructed with explicit expression above, and the coefficients are calculated (recovered) confirming the routine DCTII. Then, the field  is reconstructed from the Fourier-coefficients with routine DCTII.

#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; double x; 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++) {x=.5*M_PI/N*j; a[j]=b[j]=cos(x)+.1*cos(3*x) + .01*cos(5*x) + .001*cos(7*x);}
zcosft2(a-1,N,-1);
for(j=0;j<N;j++){a[j]*=2./N; c[j]=a[j];}
printf("back..\n");
zcosft2(a-1,N,1);
for(j=0;j<N;j++) printf("%12.8f%12.8f%12.8f%12.8f\n",(j+.5)*M_PI/N,b[j], c[j], a[j]);
free(a);
free(b);
free(c);
}


The output is copypasted below:

0.19634954  1.11100000  1.00000000  1.11100000
0.58904862  1.06968303  0.10000000  1.06968303
0.98174770  0.95739716  0.01000000  0.95739716
1.37444679  0.80159716  0.00100000  0.80159716
1.76714587  0.63003214  0.00000000  0.63003214
2.15984495  0.46027408  0.00000000  0.46027408
2.55254403  0.29915159  0.00000000  0.29915159
2.94524311  0.14686721  0.00000000  0.14686721


The 0th column shows the coordinates of nodes, at which the field is evaluated;

The first column shows the filed  evaluated with the explicit formula above.

The second column shows the Fourier–coefficients: 1, 0.1, 0.01, 0.001 .

The last column shows that the field can be reconsructed with these coefficients with routine DCTIII.

While only few modes are excited, there is no need to use the special algorithm; the explicit formula is also fast. However, at large [/itex]q[/itex] for [/itex]N=2^q[/itex] components, the routine above is significantly faster than the explicit summation of harmonics.

For simulation of propagation of symmetric field, expanding it by harmonics, the Fourier coefficients should be complex; and the field is complex too. For this reason, the first argument of routine zcosft2 is z_type array, and z_type should be defined as Complex(double). The second argument is unsigned integer, that indicates value ; where  is assumed to be real number. The last argument should be  for evaluation of DCTIII and  for evaluation of DCTII. The result is placed at the same array. In order to begin numeration of elements of array with zero, two characters  should be added to the name of the array at the call.

Shoise of the nodes

The discrete realizations of the CosTransform differ with positions of nodes for the initial functions and for its transform. In the cases DCTI and DCTIV, the nodes of the original coincide with the node of the transform. Each of them can be normalized with factor  and then, the square of the transform (second iteration) is just identity operator.

In the cases of DCTII and DCTIII, the nodes of the transform are displaced for half of the step with respect of the nodes of the original; so  and .

In the case of DCTI, both, the mesh for the original and the mesh for the output include the coordinate zero.

In the case of DCTII, the mesh for the original does not include zero, but mesh for the output does.

In the case of DCTIII, the mesh for the original includes zero, but mesh for the output does not.

In the case of DCTIV, the mesh for the original and the output coincide and do not include zero.

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.