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

~this
~this()
Undocumented in 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.

Mixins

__anonymous
mixin Import!T
Undocumented in source.

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.

Variables

log2n
int log2n;
Undocumented in source.
table
impl.Table table;
Undocumented in source.

Examples

import std.stdio, std.conv, std.exception;
import pfft.pfft;

void main(string[] args)
{
    auto n = to!int(args[1]);
    enforce((n & (n-1)) == 0, "N must be a power of two.");

    alias Fft!float F;

    F f;
    f.initialize(n);

    auto re = F.allocate(n);
    auto im = F.allocate(n);

    foreach(i, _; re)
        readf("%s %s\n", &re[i], &im[i]);

    f.fft(re, im);

    foreach(i, _; re)
        writefln("%s\t%s", re[i], im[i]);
}

Meta