FFTPack.h

Classes

FFTPack -- C++ interface to the Fortran FFTPACK library (full description)

class FFTPack

Interface

Public Members
static void cffti(Int n, Float* wsave)
static void cffti(Int n, Double* wsave)
static void cfftf(Int n, Complex* c, Float* wsave)
static void cfftf(Int n, DComplex* c, Double* wsave)
static void cfftb(Int n, Complex* c, Float* wsave)
static void cfftb(Int n, DComplex* c, Double* wsave)
static void rffti(Int n, Float* wsave)
static void rffti(Int n, Double* wsave)
static void rfftf(Int n, Float* r, Float* wsave)
static void rfftf(Int n, Double* r, Double* wsave)
static void rfftb(Int n, Float* r, Float* wsave)
static void rfftb(Int n, Double* r, Double* wsave)
static void ezffti(Int n, Float* wsave)
static void ezfftf(Int n, Float* r, Float* azero, Float* a, Float* b, Float* wsave)
static void ezfftb(Int n, Float* r, Float* azero, Float* a, Float* b, Float* wsave)
static void sinti(Int n, Float* wsave)
static void sinti(Int n, Double* wsave)
static void sint(Int n, Float* x, Float* wsave)
static void sint(Int n, Double* x, Double* wsave)
static void costi(Int n, Float* wsave)
static void costi(Int n, Double* wsave)
static void cost(Int n, Float* x, Float* wsave)
static void cost(Int n, Double* x, Double* wsave)
static void sinqi(Int n, Float* wsave)
static void sinqi(Int n, Double* wsave)
static void sinqf(Int n, Float* x, Float* wsave)
static void sinqf(Int n, Double* x, Double* wsave)
static void sinqb(Int n, Float* x, Float* wsave)
static void sinqb(Int n, Double* x, Double* wsave)
static void cosqi(Int n, Float* wsave)
static void cosqi(Int n, Double* wsave)
static void cosqf(Int n, Float* x, Float* wsave)
static void cosqf(Int n, Double* x, Double* wsave)
static void cosqb(Int n, Float* x, Float* wsave)
static void cosqb(Int n, Double* x, Double* wsave)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

Synopsis

The static functions in this class are C++ wrappers to the Fortran FFTPACK library. This library contains functions that perform fast Fourier transforms (FFT's) and related transforms.

An additional purpose of these definitions is to overload the functions so that C++ users can access the functions in either fftpak (single precision) or dfftpack (double precision) with identical function names.

These routines only do one-dimensional transforms with the first element of the array being the "origin" of the transform. The FFTServer class uses some of these functions to implement multi-dimensional transforms with the origin of the transform either at the centre or the first element of the Array.

You must initialise the work array wsave before using the forward transform (function with a suffix of f) or the backward transform (with a suffix of b).

The transforms done by the functions in this class can be categorised as follows:

Warning These functions assume that it is possible to convert between AIPS++ numeric types and those used by Fortran. That it is possible to convert between Float & float, Double & double and Int & int.

Warning These function also assume that a Complex array is stored as pairs of floating point numbers, with no intervening gaps, and with the real component first ie., [re0,im0,re1,im1, ...] so that the following type casts work,
    Complex* complexPtr;
    Float* floatPtr = (Float* ) complexPtr;
    
and allow a Complex number to be accessed as a pair of real numbers. If this assumption is bad then float Arrays will have to generated by copying the complex ones. When compiled in debug mode mode the functions that require this assumption will throw an exception (AipsError) if this assumption is bad. Ultimately this assumption about Complex<->Float Array conversion should be put somewhere central like Array2Math.cc.

Member Description

static void cffti(Int n, Float* wsave)
static void cffti(Int n, Double* wsave)

cffti initializes the array wsave which is used in both cfftf and cfftb. The prime factorization of n together with a tabulation of the trigonometric functions are computed and stored in wsave.

Input parameter:

n
The length of the sequence to be transformed
Output parameter:
wsave
A work array which must be dimensioned at least 4*n+15 The same work array can be used for both cfftf and cfftb as long as n remains unchanged. Different wsave arrays are required for different values of n. The contents of wsave must not be changed between calls of cfftf or cfftb.

static void cfftf(Int n, Complex* c, Float* wsave)
static void cfftf(Int n, DComplex* c, Double* wsave)

cfftf computes the forward complex discrete Fourier transform (the Fourier analysis). Equivalently, cfftf computes the Fourier coefficients of a complex periodic sequence. the transform is defined below at output parameter c.

The transform is not normalized. To obtain a normalized transform the output must be divided by n. Otherwise a call of cfftf followed by a call of cfftb will multiply the sequence by n.

The array wsave which is used by cfftf must be initialized by calling cffti(n,wsave).

Input parameters:

n
The length of the complex sequence c. The method is more efficient when n is the product of small primes.
c
A complex array of length n which contains the sequence to be transformed.
wsave
A real work array which must be dimensioned at least 4n+15 by the program that calls cfftf. The wsave array must be initialized by calling cffti(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first. The same wsave array can be used by cfftf and cfftb.
Output parameters:
c
for j=1,...,n
c(j)=the sum from k=1,...,n of
c(k)*exp(-i*(j-1)*(k-1)*2*pi/n)
where i=sqrt(-1)
wsave
Contains initialization calculations which must not be destroyed between calls of cfftf or cfftb

static void cfftb(Int n, Complex* c, Float* wsave)
static void cfftb(Int n, DComplex* c, Double* wsave)

cfftb computes the backward complex discrete Fourier transform (the Fourier synthesis). Equivalently, cfftb computes a complex periodic sequence from its Fourier coefficients. The transform is defined below with output parameter c.

A call of cfftf followed by a call of cfftb will multiply the sequence by n.

The array wsave which is used by cfftb must be initialized by calling cffti(n,wsave).

Input parameters:

n
The length of the complex sequence c. The method is more efficient when n is the product of small primes.
c
A complex array of length n which contains the sequence to be transformed.
wsave
A real work array which must be dimensioned at least 4n+15 in the program that calls cfftb. The wsave array must be initialized by calling cffti(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first. The same wsave array can be used by cfftf and cfftb.
Output parameters:
c
for j=1,...,n
c(j)=the sum from k=1,...,n of
c(k)*exp(i*(j-1)*(k-1)*2*pi/n)

wsave
Contains initialization calculations which must not be destroyed between calls of cfftf or cfftb

static void rffti(Int n, Float* wsave)
static void rffti(Int n, Double* wsave)

rffti initializes the array wsave which is used in both rfftf and rfftb. The prime factorization of n together with a tabulation of the trigonometric functions are computed and stored in wsave.

Input parameter:

n
The length of the sequence to be transformed.
Output parameter:
wsave
A work array which must be dimensioned at least 2*n+15. The same work array can be used for both rfftf and rfftb as long as n remains unchanged. Different wsave arrays are required for different values of n. The contents of wsave must not be changed between calls of rfftf or rfftb.

static void rfftf(Int n, Float* r, Float* wsave)
static void rfftf(Int n, Double* r, Double* wsave)

rfftf computes the Fourier coefficients of a real perodic sequence (Fourier analysis). The transform is defined below at output parameter r.

Input parameters:

n
The length of the array r to be transformed. The method is most efficient when n is a product of small primes. n may change so long as different work arrays are provided
r
A real array of length n which contains the sequence to be transformed
wsave
A work array which must be dimensioned at least 2*n+15 in the program that calls rfftf. The wsave array must be initialized by calling rffti(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first. The same wsave array can be used by rfftf and rfftb.
output parameters
r
r(1) = the sum from i=1 to i=n of r(i)
if n is even set l = n/2 , if n is odd set l = (n+1)/2
then for k = 2,...,l
r(2*k-2) = the sum from i = 1 to i = n of
r(i)*cos((k-1)*(i-1)*2*pi/n)
r(2*k-1) = the sum from i = 1 to i = n of
-r(i)*sin((k-1)*(i-1)*2*pi/n)
if n is even
r(n) = the sum from i = 1 to i = n of
(-1)**(i-1)*r(i)

note: this transform is unnormalized since a call of rfftf followed by a call of rfftb will multiply the input sequence by n.

wsave
Contains results which must not be destroyed between calls of rfftf or rfftb.

static void rfftb(Int n, Float* r, Float* wsave)
static void rfftb(Int n, Double* r, Double* wsave)

rfftb computes the real perodic sequence from its Fourier coefficients (Fourier synthesis). The transform is defined below at output parameter r.

Input parameters:

n
The length of the array r to be transformed. The method is most efficient when n is a product of small primes. n may change so long as different work arrays are provided
r
A real array of length n which contains the sequence to be transformed
wsave
A work array which must be dimensioned at least 2*n+15 in the program that calls rfftb. The wsave array must be initialized by calling rffti(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first. The same wsave array can be used by rfftf and rfftb.
Output parameters:
r
for n even and for i = 1,...,n
r(i) = r(1)+(-1)**(i-1)*r(n)
plus the sum from k=2 to k=n/2 of
2.*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)
-2.*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)
for n odd and for i = 1,...,n
r(i) = r(1) plus the sum from k=2 to k=(n+1)/2 of
2.*r(2*k-2)*cos((k-1)*(i-1)*2*pi/n)
-2.*r(2*k-1)*sin((k-1)*(i-1)*2*pi/n)

note: this transform is unnormalized since a call of rfftf followed by a call of rfftb will multiply the input sequence by n.

wsave
Contains results which must not be destroyed between calls of rfftb or rfftf.

static void ezffti(Int n, Float* wsave)

ezffti initializes the array wsave which is used in both ezfftf and ezfftb. The prime factorization of n together with a tabulation of the trigonometric functions are computed and stored in wsave.

Input parameter:

n
The length of the sequence to be transformed.
Output parameter:
wsave
A work array which must be dimensioned at least 3*n+15. The same work array can be used for both ezfftf and ezfftb as long as n remains unchanged. Different wsave arrays are required for different values of n.

static void ezfftf(Int n, Float* r, Float* azero, Float* a, Float* b, Float* wsave)

ezfftf computes the Fourier coefficients of a real perodic sequence (Fourier analysis). The transform is defined below at output parameters azero, a and b. ezfftf is a simplified but slower version of rfftf.

Input parameters:

n
The length of the array r to be transformed. The method is most efficient when n is the product of small primes.
r
A real array of length n which contains the sequence to be transformed. r is not destroyed.
wsave
A work array which must be dimensioned at least 3*n+15 in the program that calls ezfftf. The wsave array must be initialized by calling ezffti(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first. The same wsave array can be used by ezfftf and ezfftb.
Output parameters:
azero
The sum from i=1 to i=n of r(i)/n
a,b
Real arrays of length n/2 (n even) or (n-1)/2 (n odd)
for n even
b(n/2)=0, and
a(n/2) is the sum from i=1 to i=n of (-1)**(i-1)*r(i)/n

for n even define kmax=n/2-1
for n odd define kmax=(n-1)/2
then for k=1,...,kmax
a(k) equals the sum from i=1 to i=n of
2./n*r(i)*cos(k*(i-1)*2*pi/n)
b(k) equals the sum from i=1 to i=n of
2./n*r(i)*sin(k*(i-1)*2*pi/n)

static void ezfftb(Int n, Float* r, Float* azero, Float* a, Float* b, Float* wsave)

ezfftb computes a real perodic sequence from its Fourier coefficients (Fourier synthesis). The transform is defined below at output parameter r. ezfftb is a simplified but slower version of rfftb.

Input parameters:

n
The length of the output array r. The method is most efficient when n is the product of small primes.
azero
The constant Fourier coefficient
a,b
Arrays which contain the remaining Fourier coefficients these arrays are not destroyed. The length of these arrays depends on whether n is even or odd. If n is even n/2 locations are required, if n is odd (n-1)/2 locations are required.
wsave
A work array which must be dimensioned at least 3*n+15. in the program that calls ezfftb. The wsave array must be initialized by calling ezffti(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first. The same wsave array can be used by ezfftf and ezfftb.
Output parameters:
r
if n is even define kmax=n/2
if n is odd define kmax=(n-1)/2
then for i=1,...,n
r(i)=azero plus the sum from k=1 to k=kmax of
a(k)*cos(k*(i-1)*2*pi/n)+b(k)*sin(k*(i-1)*2*pi/n)
where
c(k) = .5*cmplx(a(k),-b(k)) for k=1,...,kmax
c(-k) = conjg(c(k))
c(0) = azero
and i=sqrt(-1)

static void sinti(Int n, Float* wsave)
static void sinti(Int n, Double* wsave)

sinti initializes the array wsave which is used in sint. The prime factorization of n together with a tabulation of the trigonometric functions are computed and stored in wsave.

Input parameter:

n
The length of the sequence to be transformed. the method is most efficient when n+1 is a product of small primes.
Output parameter:
wsave
A work array with at least int(2.5*n+15) locations. Different wsave arrays are required for different values of n. The contents of wsave must not be changed between calls of sint.

static void sint(Int n, Float* x, Float* wsave)
static void sint(Int n, Double* x, Double* wsave)

sint computes the discrete Fourier sine transform of an odd sequence x(i). The transform is defined below at output parameter x. sint is the unnormalized inverse of itself since a call of sint followed by another call of sint will multiply the input sequence x by 2*(n+1). The array wsave which is used by sint must be initialized by calling sinti(n,wsave).

Input parameters:

n
The length of the sequence to be transformed. The method is most efficient when n+1 is the product of small primes.
x
An array which contains the sequence to be transformed
wsave
A work array with dimension at least int(2.5*n+15) in the program that calls sint. The wsave array must be initialized by calling sinti(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first.
Output parameters:
x
for i=1,...,n
x(i) = the sum from k=1 to k=n
2*x(k)*sin(k*i*pi/(n+1))

a call of sint followed by another call of sint will multiply the sequence x by 2*(n+1). Hence sint is the unnormalized inverse of itself.

wsave
Contains initialization calculations which must not be destroyed between calls of sint.

static void costi(Int n, Float* wsave)
static void costi(Int n, Double* wsave)

costi initializes the array wsave which is used in cost. The prime factorization of n together with a tabulation of the trigonometric functions are computed and stored in wsave.

Input parameter:

n
The length of the sequence to be transformed. The method is most efficient when n-1 is a product of small primes.
Output parameter:
wsave
A work array which must be dimensioned at least 3*n+15. Different wsave arrays are required for different values of n. The contents of wsave must not be changed between calls of cost.

static void cost(Int n, Float* x, Float* wsave)
static void cost(Int n, Double* x, Double* wsave)

cost computes the discrete Fourier cosine transform of an even sequence x(i). The transform is defined below at output parameter x. cost is the unnormalized inverse of itself since a call of cost followed by another call of cost will multiply the input sequence x by 2*(n-1). The transform is defined below at output parameter x. The array wsave which is used by cost must be initialized by calling costi(n,wsave).

Input parameters:

n
The length of the sequence x. n must be greater than 1. The method is most efficient when n-1 is a product of small primes.
x
An array which contains the sequence to be transformed
wsave
A work array which must be dimensioned at least 3*n+15 in the program that calls cost. The wsave array must be initialized by calling costi(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first.
Output parameters:
x
for i=1,...,n
x(i) = x(1)+(-1)**(i-1)*x(n)
+ the sum from k=2 to k=n-1
2*x(k)*cos((k-1)*(i-1)*pi/(n-1))

a call of cost followed by another call of cost will multiply the sequence x by 2*(n-1) hence cost is the unnormalized inverse of itself.

wsave
Contains initialization calculations which must not be destroyed between calls of cost.

static void sinqi(Int n, Float* wsave)
static void sinqi(Int n, Double* wsave)

sinqi initializes the array wsave which is used in both sinqf and sinqb. The prime factorization of n together with a tabulation of the trigonometric functions are computed and stored in wsave.

Input parameter:

n
The length of the sequence to be transformed. The method is most efficient when n is a product of small primes.
Output parameter:
wsave
A work array which must be dimensioned at least 3*n+15. The same work array can be used for both sinqf and sinqb as long as n remains unchanged. Different wsave arrays are required for different values of n. The contents of wsave must not be changed between calls of sinqf or sinqb.

static void sinqf(Int n, Float* x, Float* wsave)
static void sinqf(Int n, Double* x, Double* wsave)

sinqf computes the fast Fourier transform of quarter wave data. That is, sinqf computes the coefficients in a sine series representation with only odd wave numbers. The transform is defined below at output parameter x.

sinqb is the unnormalized inverse of sinqf since a call of sinqf followed by a call of sinqb will multiply the input sequence x by 4*n.

The array wsave which is used by sinqf must be initialized by calling sinqi(n,wsave).

Input parameters:

n
The length of the array x to be transformed. The method is most efficient when n is a product of small primes.
x
An array which contains the sequence to be transformed
wsave A work array which must be dimensioned at least 3*n+15. in the program that calls sinqf. The wsave array must be initialized by calling sinqi(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first.
Output parameters:
x
for i=1,...,n
x(i) = (-1)**(i-1)*x(n)
+ the sum from k=1 to k=n-1 of
2*x(k)*sin((2*i-1)*k*pi/(2*n))

a call of sinqf followed by a call of sinqb will multiply the sequence x by 4*n. therefore sinqb is the unnormalized inverse of sinqf.

wsave
Contains initialization calculations which must not be destroyed between calls of sinqf or sinqb.

static void sinqb(Int n, Float* x, Float* wsave)
static void sinqb(Int n, Double* x, Double* wsave)

sinqb computes the fast Fourier transform of quarter wave data. that is, sinqb computes a sequence from its representation in terms of a sine series with odd wave numbers. the transform is defined below at output parameter x.

sinqf is the unnormalized inverse of sinqb since a call of sinqb followed by a call of sinqf will multiply the input sequence x by 4*n.

The array wsave which is used by sinqb must be initialized by calling sinqi(n,wsave).

Input parameters:

n
The length of the array x to be transformed. The method is most efficient when n is a product of small primes.
x
An array which contains the sequence to be transformed
wsave A work array which must be dimensioned at least 3*n+15. in the program that calls sinqb. The wsave array must be initialized by calling sinqi(n,wsave) and a different wsave array must be used for each different value of n. This initialization does not have to be repeated so long as n remains unchanged thus subsequent transforms can be obtained faster than the first.
Output parameters:
x
for i=1,...,n
x(i)= the sum from k=1 to k=n of
4*x(k)*sin((2k-1)*i*pi/(2*n))

a call of sinqb followed by a call of sinqf will multiply the sequence x by 4*n. Therefore sinqf is the unnormalized inverse of sinqb.

wsave
Contains initialization calculations which must not be destroyed between calls of sinqb or sinqf.

static void cosqi(Int n, Float* wsave)
static void cosqi(Int n, Double* wsave)

static void cosqf(Int n, Float* x, Float* wsave)
static void cosqf(Int n, Double* x, Double* wsave)

static void cosqb(Int n, Float* x, Float* wsave)
static void cosqb(Int n, Double* x, Double* wsave)