ncigt-fil
Functions
Fourier Transform Functions

An FFT resource manager and associated functions. More...

Functions

int fft1d (void *args)
 
int fft_mngr_alloc_2dfft (fil_fft_mngr *mngr, int M, int N, char direction)
 
int fft_mngr_alloc_fft (fil_fft_mngr *mngr, int N, char direction)
 
int fft_mngr_init (fil_fft_mngr *mngr)
 
int fft_mngr_quit (fil_fft_mngr *mngr)
 
void fft_t (short ncoils, short nf, short nz, short ny, short nx, char direction, fil_fft_mngr *mngr, short center, COMPLEX *data_in, COMPLEX *data_out)
 
void fftx (short ncoils, short Nf, int Nyz, short Nx, char dir, fil_fft_mngr *mngr, short center, COMPLEX *data)
 
void ffty (short ncoils, short nf, short nz, short ny, short nx, char direction, fil_fft_mngr *mngr, short center, COMPLEX *data)
 
void fftz (short ncoils, short nf, short nz, short ny, short nx, char direction, fil_fft_mngr *mngr, short center, COMPLEX *data_in, COMPLEX *data_out)
 
int fil_2dfft (fil_fft_mngr *mngr, int M, int N, COMPLEX *data, char dir)
 
int fil_fft (fil_fft_mngr *mngr, int N, COMPLEX *data, char dir, int unused)
 
void fil_fft_shift (COMPLEX *data, int Nx, int Ny)
 

Detailed Description

An FFT resource manager and associated functions.

This suite of functions provides a resource manager for Fast Fourier Transforms, in order to alleviate memory management bookkeeping.

The use of NC-IGT Fast Imaging Library (FIL) FFT manager facilitates reuse of scratch buffers needed by the FFT functions. Scratch buffers can be allocated at the start of a program, and used by multiple functions afterwards. Calling an FFT function with an initialized manager will create scratch space if there is none pre-allocated. Furthermore, if the FFT engine changes in the future, these fil_fft calls will remain backwards compatible.

Usage:

#include "fil_fft.h"

fil_fft_mngr mngr;
COMPLEX *data;

fft_mngr_init( &mngr );

data = (COMPLEX *) malloc( 256 * sizeof(COMPLEX) );

...

fil_fft( &mngr, 256, data, 'f', 1 );

...

fft_mngr_quit( &mngr );

Each manager allocates space for upto 512 different length-plus-f/b combinations. If your program needs more than 512 different FFTs, then use additional managers.

Function Documentation

int fft1d ( void *  args)

Computes a 1D FFT

To call this function, first declare a variable to hold the function arguments:

fft1d_args args;

Then, populate the variable,

args.direction = 'f';    // FFT direction: 'f' or 'b'
args.data   = in;        // pointer to COMPLEX data to be transformed
args.n      = N;         // length of data buffer
args.buf    = buf;       // pointer to temporary COMPLEX buffer
args.center = 0;         // k-space center is in the middle of the data
args.mngr   = mngr;      // a pointer to an FFT manager

Then call the function:

fft1d( (void *) &args );

This structure allows calls to fft1d to be multi-threaded.

Inverse FFTs are scaled by the length of the data vector, so that a 'round trip' of and FFT followed by an IFFT will leave the data at the same amplitude.

Parameters
argsa pointer to an fft1d_args variable
int fft_mngr_alloc_2dfft ( fil_fft_mngr *  mngr,
int  M,
int  N,
char  direction 
)

Allocate an manager object for 2D FFTs.

Parameters
mngran fil_fft manager
Mlength of dim 1
Nlength of dim 2
direction'f':forward FFT :: 'b':inverse FFT
int fft_mngr_alloc_fft ( fil_fft_mngr *  mngr,
int  N,
char  direction 
)

Allocate an manager object for 1D FFTs.

Parameters
mngran fil_fft manager
Nlength of requested fft
direction'f':forward :: 'b':inverse
int fft_mngr_init ( fil_fft_mngr *  mngr)

Initialize the FFT manager.

The number of different FFT sizes needs to be declared before calling this initialization function.

Usage:

fil_fft_mngr mngr;
fft_mngr_init( &mngr );
Parameters
mngra pointer to a FFT manager
int fft_mngr_quit ( fil_fft_mngr *  mngr)

Free all FFT-related memory allocations, and release the manager.

Parameters
mngran FFT manager
void fft_t ( short  ncoils,
short  nf,
short  nz,
short  ny,
short  nx,
char  direction,
fil_fft_mngr *  mngr,
short  center,
COMPLEX *  data_in,
COMPLEX *  data_out 
)

FFT from time to frequency, or vice-versa. The input is a dataset ordered (nx -x- ny -x- nz -x- nf -x- ncoils), and the FFT is performed only in the temporal frequency direction (2nd dimension).

Parameters
ncoilsNumber of coils. (dim 5)
nfNumber of time frames. (dim 4)
nzSize along kz. (dim 3)
nySize along ky. (dim 2)
nxSize along x or kx. (dim 1)
direction'f' : forward FFT, or 'b' : inverse FFT
mngra pointer to an FFT manager
centeris center of k-space in the center of the data? set to 0 if DC is at 0, otherwise DC assumed to be at nf/2
data_inInput data
data_outOutput data. If it is the same as data_in, input data simply gets over-written.
void fftx ( short  ncoils,
short  Nf,
int  Nyz,
short  Nx,
char  dir,
fil_fft_mngr *  mngr,
short  center,
COMPLEX *  data 
)

FFT along x or kx. The input is a data-set ordered ( Nx -x- (Ny*Nz) -x- Nf -x- ncoils ), and an FFT is performed only in the x/kx direction.

Parameters
ncoilsnumber of coils
Nfsize in the temporal frame direction.
Nyzsize in the Nyz direction.
Nxsize in the x/kx direction.
dir'f' : forward FFT, or 'b' : inverse FFT
mngra pointer to an FFT manager
center0 if DC is at (0,0), otherwise DC assumed to be at (Nx/2,Nyz/2)
dataData to FFT. The input data gets overwritten by the output data.
void ffty ( short  ncoils,
short  nf,
short  nz,
short  ny,
short  nx,
char  direction,
fil_fft_mngr *  mngr,
short  center,
COMPLEX *  data 
)

FFT along y or ky. The input is a data-set ordered (nx -x- ny -x- nz -x- nf -x- ncoils), and an FFT is performed only in the y/ky direction.

Parameters
ncoilsNumber of coils. (dim 5)
nfNumber of time frames. (dim 4)
nzSize along kz. (dim 3)
nySize along ky. (dim 2)
nxSize along x or kx. (dim 1)
direction'f' : forward FFT, or 'b' : inverse FFT
mngra pointer to an FFT manager
center0 if DC is at (0,0), otherwise DC assumed to be at (Nx/2,Ny/2)
dataData to FFT. The input data gets overwritten by the output data.
void fftz ( short  ncoils,
short  nf,
short  nz,
short  ny,
short  nx,
char  direction,
fil_fft_mngr *  mngr,
short  center,
COMPLEX *  data_in,
COMPLEX *  data_out 
)

FFT along z or kz. The input is a data-set ordered as (nx -x- ny -x- nz -x- nf -x- ncoils), and an FFT is performed only in the z/kz direction.

Parameters
ncoilsNumber of coils. (dim 5)
nfNumber of time frames. (dim 4)
nzSize along kz. (dim 3)
nySize along ky. (dim 2)
nxSize along x or kx. (dim 1)
direction'f' : forward FFT, or 'b' : inverse FFT
mngra pointer to an FFT manager
center0 if DC is at (0,0), otherwise DC assumed to be at (Nx/2,Ny/2)
data_inInput data
data_outOutput data. If it is the same as data_in, input data simply gets over-written.
int fil_2dfft ( fil_fft_mngr *  mngr,
int  M,
int  N,
COMPLEX *  data,
char  dir 
)

Perform a 2D FFT on the data.

Note: to match Matlab's "ifft2", the output must be scaled by 1/(M*N).

Parameters
mngran FFT manager
Mdim-1 length of the data set
Ndim-2 length of the data set
dataa pointer to the data buffer to transform
dirFFT direction forward "f" or backward "b"
int fil_fft ( fil_fft_mngr *  mngr,
int  N,
COMPLEX *  data,
char  dir,
int  unused 
)

Perform a 1D FFT on the data.

Note: consistent with the underlying FFT engines used in this function, the inverse FFT (when dir = 'b';) is not scaled to unity.

Parameters
mngran FFT manager
Nthe length of the data set
dataa pointer to the data buffer to transform
dirFFT direction forward 'f' or backward 'b'
unused(unused)
void fil_fft_shift ( COMPLEX *  data,
int  Nx,
int  Ny 
)

Perform an FFT shift on the data, swapping the 1st/3rd and 2nd/4th quadrants of the data space.

Parameters
datapointer to the input data
Nxdim 1 of the data
Nydim 2 of the data