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

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

For a given natural number $$N$$ operator $$\mathrm{DCTIII}_N$$ converts any array $$F$$ of length $$N$$ to the array with elements


 * $$ \!\!\!\!\!\!\!\!\!\!\!\!\!\! (1) ~ ~ ~ ~ \displaystyle

(\mathrm{DCTIII}_N ~F) _k = \sum_{n=0}^{N-1} ~ F_n~ \cos \left(\frac{\pi}{N} \left(k\!+\!\frac{1}{2}\right) n \right) ~ ~ ~$$ $$~ ~ ~ k = 0, \dots, N\!-\!1$$

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.

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


 * $$ \!\!\!\!\!\!\!\!\!\!\!\!\!\! (2) ~ ~ ~ ~ \displaystyle (\mathrm{DCTIII}_N ~F)_k = \sum_{n=0}^{N-1} ~ F_n~ \cos \left(\frac{\pi}{N} \left(n\!+\!\frac{1}{2}\right) k \right) ~ ~ ~$$ ~ ~ ~ k = 0, \dots, N\!-\!1

as
 * $$\!\!\!\!\!\!\!\!\!\!\!\!\!\! (3) ~ ~ ~ ~ \displaystyle

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

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


 * $$\!\!\!\!\!\!\!\!\!\!\!\!\!\! (4) ~ ~ ~ ~ \displaystyle A(x)= \sum_{n=0}^\infty ~a_n~ \cos\left( \left(n+\frac{1}{2} \right) x \right)$$

Then at points x_m=\pi m/N the field can be approximated with
 * $$\!\!\!\!\!\!\!\!\!\!\!\!\!\! (5) ~ ~ ~ ~ \displaystyle A(x_m)=A_m= (\mathrm{DCTIII}_N~ a)_m$$

where a is array of coefficients above.

The inverse operation, id est, calculation of the Fourier coefficients for the symmetric field known at porints $$x_m$$, $$m=0..N-1$$ can be performed with DCTII as follows:


 * $$\!\!\!\!\!\!\!\!\!\!\!\!\!\! (6) ~ ~ ~ ~ \displaystyle

a_m= \frac{2}{N} (\mathrm{DCTII}_N~ A)_m$$

These coefficients correspond to the expansion of the filed with symmetric modes of cavity of width \pi. 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 $$A(x)=\cos(x)+.1 \cos(3 x) + .01 \cos(5 x) + .001 \cos(7x)$$ is evaluated in the points with coordinates $$0$$ $$\pi/16$$ $$2\pi/16$$ $$3\pi/16$$ $$4\pi/16$$ $$5\pi/16$$ $$6\pi/16$$ $$7\pi/16$$. This field corresponds to the cavity of length $$\pi$$; the modes become zero at $$x=\pm \pi$$; the only symmetric modes are considered. Wave–numbers of symmetric modes are $$k=1$$, $$k=3$$, $$k=5$$, $$k=7$$; only 4 symmetric modes are excited in the example; the field $$A$$ is constructed with explicit expression above, and the coefficients are calculated (recovered) confirming the routine DCTII. Then, the field $$A$$ is reconstructed from the Fourier-coefficients with routine DCTII.


 * 1) includeq for N=2^q 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 $$N=2^q$$; where $$q$$ is assumed to be real number. The last argument should be $$-1$$ for evaluation of DCTIII and $$1$$ 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 $$-1$$ 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 $$\sqrt{2/N}$$ 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 $$\mathrm{DCTIII}_N^{-1}=\frac{2}{N}\mathrm{DCTII}_N$$ and $$\mathrm{DCTII}_N^{-1}=\frac{2}{N}\mathrm{DCTIII}_N$$.

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.

Keywords
CosFourier, Fourier, DCT, DCTI, DCTII, DCTIII