pfft.clib

Functions in this module can be used from both C and D. To use them from C, include pfft.h. Only the functions that operate on floats are listed here. To calculate fft of doubles or reals (long doubles in C), just replace the "_f" suffix on functions and "F" on types with "_d" or "_l" on functions and "D" or "L" on types.

Example of using this module from C:

1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <pfft.h>
4 
5 int main(int argc, char **argv)
6 {
7     int n = atoi(argv[1]);
8     PfftTableF tab = pfft_table_f(n, 0);
9     float *re = pfft_allocate_f(n);
10     float *im = pfft_allocate_f(n);
11     
12     int i;
13     for(i = 0; i < n; i++)
14         scanf("%f %f", re + i, im + i);
15 
16     pfft_fft_f(re, im, tab);
17        
18     for(i = 0; i < n; i++)
19         printf("%f %f\n", re[i], im[i]);
20 
21     pfft_free_f(re);
22     pfft_free_f(im);
23     pfft_table_free_f(tab);
24 }

Members

Functions

pfft_alignment_f
size_t pfft_alignment_f(size_t nbytes)

Returns appropriate alignment for use with functions in this module for a memory block of size nbytes.

pfft_allocate_f
float* pfft_allocate_f(size_t nelements)

Returns a pointer to an array of size nelements, aligned apropriately for use with functions in this module.

pfft_fft_f
void pfft_fft_f(float* re, float* im, PfftTableF table)

Computes discrete fourier transform. re should contain the real part of the input sequence and im the imaginary part of the sequence. The length of the input sequence should be equal to the number that was passed to pfft_table_f when creating table. The method operates in place - the result is saved back to re and im. Both arrays must be properly aligned. An easy way to obtain a properly aligned block of memory is to use pfft_allocate_f. If you want to take care of memory allocation in some other way, you should make sure that the addresses re and im are multiples of the number returned by pfft_alignment_f.

pfft_free_f
void pfft_free_f(float* p)

Frees memory allocated with pfft_allocate_f.

pfft_ifft_f
void pfft_ifft_f(float* re, float* im, PfftTableF table)

This function is an inverse of pfft_fft_f, scaled by n. See the description of pfft_fft_f.

pfft_irfft_f
void pfft_irfft_f(float* data, PfftRTableF table)

Calculates the inverse of pfft_rfft_f, scaled by n. Before the method is called, data should contain a complex sequence in the same format as the result of pfft_rfft_f. It is assumed that the input sequence is a discrete fourier transform of a real valued sequence, so the elements of the input sequence not stored in data can be calculated from DFT(f)i = DFT(f)[n - i]*. When the method completes, the array contains the real part of the inverse discrete fourier transform of the input sequence, scaled by n. The imaginary part is known to be equal to zero.

pfft_rfft_f
void pfft_rfft_f(float* data, PfftRTableF table)

Calculates discrete fourier transform of the real valued sequence in data. The method operates in place. When the method completes, data contains the result. First n / 2 + 1 elements contain the real part of the result and the rest contains the imaginary part. Imaginary parts at position 0 and n / 2 are known to be equal to 0 and are not stored, so the content of data looks like this:

pfft_rtable_f
PfftRTableF pfft_rtable_f(size_t n, void* mem)

This function is used in the same way as pfft_table_f, the only difference is that it returns an instance of struct PfftRTableF.

pfft_rtable_free_f
void pfft_rtable_free_f(PfftRTableF table)

This function is used in the same was as pfft_table_free_f, the only difference is that it takes an instance of struct PfftRTableF as a parameter.

pfft_rtable_size_bytes_f
size_t pfft_rtable_size_bytes_f(size_t n)

This function returns the size of a memory block needed by pfft_rtable_f. See the descriptions of pfft_rtable_f and pfft_table_f.

pfft_table_f
PfftTableF pfft_table_f(size_t n, void* mem)

Returns an instance PfftTableF suitable for computing discrete fourier transforms on input sequences of length n (I will also use the name n to refer to the length of the input sequence in the function descriptions below). If null is passed as mem, the function will alocate the needed memory. In this case you should call pfft_table_free_f on the returned instance of PfftTableF when you are done with it. If a value different from null is passed as mem, the function does not allocate and uses memory at mem instead. In this case there should be at least pfft_table_size_bytes_f bytes of memory available at mem and it should be properly aligned. To find out what the proper alignment is, use pfft_alignment_f.

pfft_table_free_f
void pfft_table_free_f(PfftTableF table)

Frees the memory used by a PfftTableF instance. If you passed a pointer different from null as a second parameter to pfft_table_f when creating the instance of PfftTableF, you should not call this function on it - you should take care of dealocating memory you used yoursef instead.

pfft_table_size_bytes_f
size_t pfft_table_size_bytes_f(size_t n)

This function returns the size of a memory block needed by pfft_table_f. See the description of pfft_table_f above.

Structs

PfftRTableF
struct PfftRTableF

A struct that contains precomputed tables used in pfft_rfft_f and pfft_irfft_f.

PfftTableF
struct PfftTableF

A struct that contains precomputed tables used in pfft_fft_f and pfft_ifft_f.

Meta