Fft

A class for calculating discrete fourier transform. The methods of this class use split format for complex data. This means that a complex data set is represented as two arrays - one for the real part and one for the imaginary part. An instance of this class can only be used for transforms of one particular size. The template parameter is the floating point type that the methods of the class will operate on.

Destructor

A destructor is present on this object, but not explicitly documented in the source.

Members

Functions

fft
void fft(T[] re, T[] im)

Calculates discrete fourier transform. re should contain the real part of the data and im the imaginary part of the data. The method operates in place - the result is saved back to re and im. Both arrays must be properly aligned - to obtain a properly aligned array you can use allocate.

ifft
void ifft(T[] re, T[] im)

Calculates inverse discrete fourier transform scaled by n. The arguments have the same role as they do in fft.

initialize
void initialize(size_t n)

The Fft constructor. The parameter is the size of data sets that fft and ifft will operate on. I will refer to this number as n in the rest of the documentation for this class.Tables used in fft and ifft are calculated in the constructor.

Static functions

alignment
size_t alignment(size_t n)

Returns requited alignment for use with fft, ifft and scale methods.

allocate
T[] allocate(size_t n)

Allocates an array that is aligned properly for use with fft, ifft and scale methods.

deallocate
void deallocate(T[] arr)

Deallocates an array allocated with allocate.

scale
void scale(T[] data, T k)

Scales an array data by factor k. The array must be properly aligned. To obtain a properly aligned array, use allocate.

Examples

1 import std.stdio, std.conv, std.exception;
2 import pfft.pfft;
3 
4 void main(string[] args)
5 {
6     auto n = to!int(args[1]);
7     enforce((n & (n-1)) == 0, "N must be a power of two.");
8 
9     alias Fft!float F;
10 
11     F f;
12     f.initialize(n);
13 
14     auto re = F.allocate(n);
15     auto im = F.allocate(n);
16 
17     foreach(i, _; re)
18         readf("%s %s\n", &re[i], &im[i]);
19 
20     f.fft(re, im);
21 
22     foreach(i, _; re)
23         writefln("%s\t%s", re[i], im[i]);
24 }

Meta