10 FFTW 3.1.2
2.5.1 The Halfcomplex-for mat DFT
An r2r kind of FFTW_R2HC (r2hc) corresponds to an r2c DFT (see Section 2.3
[One-Dimensional DFTs of Real Data], page 6) but with “halfcomplex” format output,
and may sometimes be faste r and/or more convenient than the latter. The inverse hc2r
transform is of kind FFTW_HC2R. This consists of the non-redundant half of the complex
output for a 1d real-input DFT of size n, stored as a sequence of n real numbers (double)
in the format:
r
0
, r
1
, r
2
, . . . , r
n/2
, i
(n+1)/2−1
, . . . , i
2
, i
1
Here, r
k
is the real part of the kth output, and i
k
is the imaginary part. (Division by 2
is rounded down.) For a halfcomplex array hc[n], the kth component thus has its real
part in hc[k] and its imaginary part in hc[n-k], with the exception of k == 0 or n/2 (the
latter only if n is even)—in these two cases, the imaginary part is zero due to symmetries
of the real-input DFT, and is not stored. Thus, the r2hc transform of n real values is a
halfcomplex array of length n, and vice versa for hc2r.
Aside from the differing format, the output of FFTW_R2HC/FFTW_HC2R is otherwise exactly
the same as for the corresponding 1d r2c/c2r transform (i.e. FFTW_FORWARD/FFTW_BACKWARD
transforms, respectively). Recall that these transforms are unnormalized, so r2hc followed
by hc2r will result in the original data multiplied by n. Furthermore, like the c2r transform,
an out-of-place hc2r transform will destroy its input array.
Although these halfcomplex transforms can be used with the multi-dimensional r2r interface,
the interpretation of such a separable product of transforms along each dimension is prob-
lematic. For example, consider a two-dimensional nx by ny, r2hc by r2hc transform planned
by fftw_plan_r2r_2d(nx, ny, in, out, FFTW_R2HC, FFTW_R2HC, FFTW_MEASURE). Con-
ceptually, FFTW first transforms the rows (of size ny) to produce halfcomplex rows, and
then transforms the columns (of siz e nx). Half of these column transforms, however, are
of imaginary parts, and should therefore be multiplied by i and combined with the r2hc
transforms of the real columns to produce the 2d DFT amplitudes; FFTW’s r2r transform
does not perform this combination for you. Thus, if a multi-dimensional real-input/output
DFT is required, we recommend using the ordinary r2c/c2r interface (see Section 2.4 [Multi-
Dimensional DFTs of Real Data], page 7).
2.5.2 Real even/odd DFTs (cosine/sine transforms)
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: only the non-redundant (first) half of the array need b e stored. 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.)