Table of Contents
Name | Direction | Type | Default | Description |
---|---|---|---|---|
InputWorkspace | Input | MatrixWorkspace | Mandatory | The name of the input workspace. |
OutputWorkspace | Output | MatrixWorkspace | Mandatory | The name of the output workspace. |
InputImagWorkspace | Input | MatrixWorkspace | The name of the input workspace for the imaginary part. Leave blank if same as InputWorkspace | |
Real | Input | number | 0 | Spectrum number to use as real part for transform |
Imaginary | Input | number | Optional | Spectrum number to use as imaginary part for transform |
Transform | Input | string | Forward | Direction of the transform: forward or backward. Allowed values: [‘Forward’, ‘Backward’] |
Shift | Input | number | 0 | Apply an extra phase equal to this quantity times 2*pi to the transform |
AutoShift | Input | boolean | False | Automatically calculate and apply phase shift. Zero on the X axis is assumed to be in the centre - if it is not, setting this property will automatically correct for this. |
AcceptXRoundingErrors | Input | boolean | False | Continue to process the data even if X values are not evenly spaced |
The FFT algorithm performs discrete Fourier transform of complex data using the Fast Fourier Transform algorithm. It uses the GSL Fourier transform functions to do the calculations. Due to the nature of the fast fourier transform the input spectra must have linear x axes. If the imaginary part is not set the data is considered real. The “Transform” property defines the direction of the transform: direct (“Forward”) or inverse (“Backward”).
Note that it is assumed that the input data has the x origin in the
middle of the x-value range. It means that for the data defined on
an interval [A,B] the output must be multiplied by
, where
and
is the frequency. This can be achieved by using the
input parameter Shift, which applies a phase shift to the transform,
or by setting AutoShift on to do this automatically.
The Fourier transform of a complex function is defined by
equation:
For discrete data with equally spaced and only non-zero on
an interval
the integral can be approximated by a sum:
Here is the bin width,
. If we
are looking for values of the transformed function
at discrete
frequencies
with
the equation can be rewritten:
Here and
. The formula
is the Discrete Fourier Transform (DFT) and can be efficiently evaluated
using the Fast Fourier Transform algorithm. The DFT formula calculates
the Fourier transform of data on the interval . It should
be noted that it is periodic in
with period
. If we
also assume that
is also periodic with period
the
DFT can be used to transform data on the interval
. To
do this we swap the two halves of the data array
. If we
denote the modified array as
, its transform will be
The Mantid FFT algorithm returns the complex array as
Y values of two spectra in the output workspace, one for the real and
the other for the imaginary part of the transform. The X values are set
to the transform frequencies and have the range approximately equal to
. The actual limits depend slightly on whether
is even or odd and whether the input spectra are histograms or
point data. The variations are of the order of
. The
zero frequency is always in the bin with index
.
The X values of the input data must be evenly spaced for the FFT algorithm to work (all bin widths must be the same). If they contain small rounding errors, this requirement can be relaxed by setting the AcceptXRoundingErrors property, which will continue to process the data even if the spacings between different X values are unequal. Large differences in the bin widths will still produce a warning.
If the X values are not centred on zero, the calculated phase will be wrong. The Shift property can be used to correct this - the value supplied is the value that should be added to the X values to centre the X axis. Setting the AutoShift property will automatically apply the correct shift (overriding any manually supplied Shift).
In this example the input data were calculated using function
in the range [-5,5].
Gaussian
FFT of a Gaussian
Because the is in the middle of the data array the transform
shown is the exact DFT of the input data.
In this example the input data were calculated using function
in the range [-6,4].
Gaussian
FFT of a Gaussian
Because the is not in the middle of the data array the
transform shown includes a shifting factor of
.
To remove it the output must be multiplied by
.
The corrected transform will be:
FFT of a Gaussian
It should be noted that in a case like this, i.e. when the input is a
real positive even function, the correction can be done by finding the
transform’s modulus . The output workspace
includes the modulus of the transform.
The output workspace for a direct (“Forward”) transform contains either
three or six spectra, depending on whether the input function is complex
or purely real. If the input function has an imaginary part, the
transform is written to three spectra with indexes 0, 1, and 2. Indexes
0 and 1 are the real and imaginary parts, while index 2 contains the
modulus . If the input function does not contain
an spectrum for the imaginary part (purely real function), the actual
transform is written to spectra with indexes 3 and 4 which are the real
and imaginary parts, respectively. The last spectrum (index 5) has the
modulus of the transform. The spectra from 0 to 2 repeat these results
for positive frequencies only.
Output for the case of input function containing imaginary part:
Workspace index | Description |
---|---|
0 | Complete real part |
1 | Complete imaginary part |
2 | Complete transform modulus |
Output for the case of input function containing no imaginary part:
Workspace index | Description |
---|---|
0 | Real part, positive frequencies |
1 | Imaginary part, positive frequencies |
2 | Modulus, positive frequencies |
3 | Complete real part |
4 | Complete imaginary part |
5 | Complete transform modulus |
The output workspace for an inverse (“Backward”) transform has 3 spectra for the real (0), imaginary (1) parts, and the modulus (2).
Workspace index | Description |
---|---|
0 | Real part |
1 | Imaginary part |
2 | Modulus |
Example: Applying FFT algorithm
#Create Sample Workspace
ws = CreateSampleWorkspace(WorkspaceType = 'Event', NumBanks = 1, Function = 'Exp Decay', BankPixelWidth = 1, NumEvents = 100)
#apply the FFT algorithm
outworkspace = FFT(InputWorkspace = ws, Transform = 'Backward')
#print statements
print "DataX(0)[0] equals DataX(0)[100]? : " + str((round(abs(outworkspace.dataX(0)[0]), 3)) == (round(outworkspace.dataX(0)[100], 3)))
print "DataX(0)[10] equals DataX(0)[90]? : " + str((round(abs(outworkspace.dataX(0)[10]), 3)) == (round(outworkspace.dataX(0)[90], 3)))
print "DataX((0)[50] equals 0? : " + str((round(abs(outworkspace.dataX(0)[50]), 3)) == 0)
print "DataY(0)[40] equals DataY(0)[60]? : " + str((round(abs(outworkspace.dataY(0)[40]), 5)) == (round(outworkspace.dataY(0)[60], 5)))
Output:
DataX(0)[0] equals DataX(0)[100]? : True
DataX(0)[10] equals DataX(0)[90]? : True
DataX((0)[50] equals 0? : True
DataY(0)[40] equals DataY(0)[60]? : True
Categories: Algorithms | Arithmetic\FFT