Node:Real even/odd DFTs (cosine/sine transforms), Next:The Discrete Hartley Transform, Previous:The Halfcomplex-format DFT, Up:More DFTs of Real Data
The Fourier transform of a real-even function f(-x) = f(x) is real-even, and i times the Fourier transform of a real-odd function f(-x) = -f(x) is real-odd. Similar results hold for a discrete Fourier transform, and thus for these symmetries the need for complex inputs/outputs is entirely eliminated. Moreover, one gains a factor of two in speed/space from the fact that the data are real, and an additional factor of two from the even/odd symmetry. The result is the real-even DFT (REDFT) and the real-odd DFT (RODFT), also known as the discrete cosine and sine transforms (DCT and DST), respectively.
(In this section, we describe the 1d transforms; multi-dimensional transforms are just a separable product of these transforms operating along each dimension.)
Because of the discrete sampling, one has an additional choice: is the data even/odd around a sampling point, or around the point halfway between two samples? The latter corresponds to shifting the samples by half an interval, and gives rise to several transform variants denoted by REDFTab and RODFTab: a and b are 0 or 1, and indicate whether the input (a) and/or output (b) are shifted by half a sample (1 means it is shifted). These are also known as types I-IV of the DCT and DST, and all four types are supported by FFTW's r2r interface.1
The r2r kinds for the various REDFT and RODFT types supported by FFTW,
along with the boundary conditions at both ends of the input
array (n
real numbers in[j=0..n-1]
), are:
FFTW_REDFT00
(DCT-I): even around j=0 and even around j=n-1.
FFTW_REDFT10
(DCT-II): even around j=-0.5 and even around j=n-0.5.
FFTW_REDFT01
(DCT-III): even around j=0 and odd around j=n.
FFTW_REDFT11
(DCT-IV): even around j=-0.5 and odd around j=n-0.5.
FFTW_RODFT00
(DST-I): odd around j=-1 and odd around j=n.
FFTW_RODFT10
(DST-II): odd around j=-0.5 and odd around j=n-0.5.
FFTW_RODFT01
(DST-III): odd around j=-1 and even around j=n-1.
FFTW_RODFT11
(DST-IV): odd around j=-0.5 and even around j=n-0.5.
All of these transforms are invertible. The inverse of R*DFT00 is R*DFT00; of R*DFT10 is R*DFT01 and vice versa; and of R*DFT11 is R*DFT11. However, the transforms computed by FFTW are unnormalized, exactly like the corresponding real and complex DFTs, so computing a transform followed by its inverse yields the original array scaled by N, where N is the logical DFT size. For REDFT00, N=2(n-1); for RODFT00, N=2(n+1); otherwise, N=2n.
Note that the boundary conditions of the transform output array are given by the input boundary conditions of the inverse transform. Thus, the above transforms are all inequivalent in terms of input/output boundary conditions, even neglecting the 0.5 shift difference.
FFTW is most efficient when N is a product of small factors; note
that this differs from the factorization of the physical size
n
for REDFT00 and RODFT00! There is another oddity: n=1
REDFT00 transforms correspond to N=0, and so are not
defined (the planner will return NULL
). Otherwise, any positive
n
is supported.
For the precise mathematical definitions of these transforms as used by FFTW, see What FFTW Really Computes. (For people accustomed to the DCT/DST, FFTW's definitions have a coefficient of 2 in front of the cos/sin functions so that they correspond precisely to an even/odd DFT of size N.)
There are also type V-VIII transforms, which
correspond to a logical DFT of odd size N, independent of
whether the physical size n
is odd, but we do not support these
variants.