Fft

A class for calculating discrete fourier transforms using fast fourier transform. This class mimics std.numeric.Fft, but works a bit differently internally. The Fft in phobos does all the initialization when the constructor is called. Because pfft uses different tables for each combination of type and size, it can't do all the initialization up front. Instead, it calculates a table for a combination of type T and size n the first time the fft method is called with a template parameter T and a parameter of size n and then stores this table for later use.

Constructors

this
this(size_t nmax = size_t.init)

Fft constructor. nmax is there just for compatibility with std.numeric.Fft.

Members

Functions

fft
Complex!(T)[] fft(R r)

Computes the discrete fourier transform of data in r and returns it. Data in r isn't changed. R must be a forward range or a range with a length property. It must have complex or floating point elements. Here a complex type is a type with assignable floating point properties re and im. The number of elements in r must be a power of two. T must be a floating point type. The length of the returned array is the same as the number of elements in r.

fft
void fft(R r, Ret ret)

Computes the discrete fourier transform of data in r and stores the result in the user provided buffer ret. Data in r isn't changed. R must be a forward range or a range with a length property. It must have complex or floating point elements. Here a complex type is a type with assignable floating point properties re and im. Ret must be an input range with complex elements. r and ret must have the same number of elements and that number must be a power of two.

inverseFft
Complex!(T)[] inverseFft(R r)

Computes the inverse discrete fourier transform of data in r and returns it. Data in r isn't changed. R must be a forward range or a range with a length property. It must have complex or floating point elements. Here a complex type is a type with assignable floating point properties re and im. The number of elements in r must be a power of two. T must be a floating point type. The length of the returned array is the same as the number of elements in r.

inverseFft
void inverseFft(R r, Ret ret)

Computes the inverse discrete fourier transform of data in r and stores the result in the user provided buffer ret. Data in r isn't changed. R must be a forward range with complex or floating point elements.Here a complex type is a type with assignable properties re and im. Ret must be an input range with complex elements. r and ret must have the same number of elements and that number must be a power of two.

Static functions

allocate
T[] allocate(size_t n)

Allocates an array of size n aligned appropriately for use as parameters to fft methods. Both fft methods will still work correctly even if the parameters are not propperly aligned (or even if they aren't arrays at all), they will just be a bit slower.

Examples

1 import std.stdio, std.conv, std.exception, std.complex;
2 import pfft.stdapi;
3 
4 void main(string[] args)
5 {
6     auto n = to!int(args[1]);
7     
8     enforce((n & (n-1)) == 0, "N must be a power of two.");
9 
10     auto f = new Fft(n);
11     auto data = Fft.allocate!(double)(n);
12 
13     foreach(ref e; data)
14         readf("%s %s\n", &e.re, &e.im);
15     
16     auto ft = f.fft!double(data);
17 
18     foreach(e; ft)
19         writefln("%s %s", e.re, e.im);
20 }

Meta