cannam@95: cannam@95: cannam@95: One-Dimensional DFTs of Real Data - FFTW 3.3.3 cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95: cannam@95:
cannam@95: cannam@95: cannam@95:

cannam@95: Next: , cannam@95: Previous: Complex Multi-Dimensional DFTs, cannam@95: Up: Tutorial cannam@95:


cannam@95:
cannam@95: cannam@95:

2.3 One-Dimensional DFTs of Real Data

cannam@95: cannam@95:

In many practical applications, the input data in[i] are purely cannam@95: real numbers, in which case the DFT output satisfies the “Hermitian” cannam@95: redundancy: out[i] is the conjugate of out[n-i]. It is cannam@95: possible to take advantage of these circumstances in order to achieve cannam@95: roughly a factor of two improvement in both speed and memory usage. cannam@95: cannam@95:

In exchange for these speed and space advantages, the user sacrifices cannam@95: some of the simplicity of FFTW's complex transforms. First of all, the cannam@95: input and output arrays are of different sizes and types: the cannam@95: input is n real numbers, while the output is n/2+1 cannam@95: complex numbers (the non-redundant outputs); this also requires slight cannam@95: “padding” of the input array for cannam@95: in-place transforms. Second, the inverse transform (complex to real) cannam@95: has the side-effect of overwriting its input array, by default. cannam@95: Neither of these inconveniences should pose a serious problem for cannam@95: users, but it is important to be aware of them. cannam@95: cannam@95:

The routines to perform real-data transforms are almost the same as cannam@95: those for complex transforms: you allocate arrays of double cannam@95: and/or fftw_complex (preferably using fftw_malloc or cannam@95: fftw_alloc_complex), create an fftw_plan, execute it as cannam@95: many times as you want with fftw_execute(plan), and clean up cannam@95: with fftw_destroy_plan(plan) (and fftw_free). The only cannam@95: differences are that the input (or output) is of type double cannam@95: and there are new routines to create the plan. In one dimension: cannam@95: cannam@95:

     fftw_plan fftw_plan_dft_r2c_1d(int n, double *in, fftw_complex *out,
cannam@95:                                     unsigned flags);
cannam@95:      fftw_plan fftw_plan_dft_c2r_1d(int n, fftw_complex *in, double *out,
cannam@95:                                     unsigned flags);
cannam@95: 
cannam@95:

cannam@95: for the real input to complex-Hermitian output (r2c) and cannam@95: complex-Hermitian input to real output (c2r) transforms. cannam@95: Unlike the complex DFT planner, there is no sign argument. cannam@95: Instead, r2c DFTs are always FFTW_FORWARD and c2r DFTs are cannam@95: always FFTW_BACKWARD. cannam@95: (For single/long-double precision cannam@95: fftwf and fftwl, double should be replaced by cannam@95: float and long double, respectively.) cannam@95: cannam@95: cannam@95:

Here, n is the “logical” size of the DFT, not necessarily the cannam@95: physical size of the array. In particular, the real (double) cannam@95: array has n elements, while the complex (fftw_complex) cannam@95: array has n/2+1 elements (where the division is rounded down). cannam@95: For an in-place transform, cannam@95: in and out are aliased to the same array, which must be cannam@95: big enough to hold both; so, the real array would actually have cannam@95: 2*(n/2+1) elements, where the elements beyond the first cannam@95: n are unused padding. (Note that this is very different from cannam@95: the concept of “zero-padding” a transform to a larger length, which cannam@95: changes the logical size of the DFT by actually adding new input cannam@95: data.) The kth element of the complex array is exactly the cannam@95: same as the kth element of the corresponding complex DFT. All cannam@95: positive n are supported; products of small factors are most cannam@95: efficient, but an O(n log n) algorithm is used even for prime sizes. cannam@95: cannam@95:

As noted above, the c2r transform destroys its input array even for cannam@95: out-of-place transforms. This can be prevented, if necessary, by cannam@95: including FFTW_PRESERVE_INPUT in the flags, with cannam@95: unfortunately some sacrifice in performance. cannam@95: This flag is also not currently supported for multi-dimensional real cannam@95: DFTs (next section). cannam@95: cannam@95:

Readers familiar with DFTs of real data will recall that the 0th (the cannam@95: “DC”) and n/2-th (the “Nyquist” frequency, when n is cannam@95: even) elements of the complex output are purely real. Some cannam@95: implementations therefore store the Nyquist element where the DC cannam@95: imaginary part would go, in order to make the input and output arrays cannam@95: the same size. Such packing, however, does not generalize well to cannam@95: multi-dimensional transforms, and the space savings are miniscule in cannam@95: any case; FFTW does not support it. cannam@95: cannam@95:

An alternative interface for one-dimensional r2c and c2r DFTs can be cannam@95: found in the ‘r2r’ interface (see The Halfcomplex-format DFT), with “halfcomplex”-format output that is the same size cannam@95: (and type) as the input array. cannam@95: That interface, although it is not very useful for multi-dimensional cannam@95: transforms, may sometimes yield better performance. cannam@95: cannam@95: cannam@95: cannam@95: