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. It contains three spectra: the real, the imaginary parts of the transform and their modulus. |
WorkspaceIndex | Input | number | 0 | The index of the spectrum in the input workspace to transform. |
Transform | Input | string | Forward | The direction of the transform: “Forward” or “Backward”. Allowed values: [‘Forward’, ‘Backward’] |
IgnoreXBins | Input | boolean | False | Ignores the requirement that X bins be linear and of the same size. Set this to true if you are using log binning. FFT result will not be valid for the X axis, and should be ignored. |
This is an algorithm for Fourier transfom of real data. It uses the GSL routines gsl_fft_real_transform and gsl_fft_halfcomplex_inverse. The result of a forward transform is a three-spectra workspace with the real and imaginary parts of the transform in position 0 and 1 correspondingly. The third spectrum has the modulus of the transform (). Only positive frequencies are given and as a result the output spectra are twice as short as the input one.
An input workspace for backward transform must have the form of the output workspace of the forward algorithm, i.e. its first two spectra must have the real part and the imaginary parts. The output workspace contains a single spectrum with the real inverse transform.
The forward transform doesn’t use the absolute values of the X axis but rather assumes that the data starts at X = 0 and ends at X = XMax - XMin, where XMin and XMax are the lower and the upper limits on the X axis. As a result the output is a transform of the input spectrum shifted along the X axis so that the first bin is centered at 0.
The output of the backward transform always starts at X = 0.
import numpy as np
# Create a workspace with a Gaussian peak in the centre.
ws = CreateSampleWorkspace(Function='User Defined',UserDefinedFunction='name=Gaussian,Height=1,PeakCentre=0,Sigma=1',XMin=-10,XMax=10,BinWidth=0.1)
# Forward transform its 11-th spectrum
transform = RealFFT( ws, 10, "Forward")
# Backward transform must look like the original spectrum only shifted along the X axis
ws_back = RealFFT(transform, Transform="Backward")
# Check the outputs
# Check the sizes
print 'Number of bins in the input workspace ',ws.blocksize()
print 'Number of bins in the forward transform ',transform.blocksize()
print 'Number of bins in the backward transform',ws_back.blocksize()
# Check the X axes
print 'Input starts at',ws.readX(10)[0],', ends at',ws.readX(10)[-1],', the width is',ws.readX(10)[-1] - ws.readX(10)[0]
print 'Forward starts at ',transform.readX(0)[0],', ends at',transform.readX(0)[-1],', the width is',transform.readX(0)[-1] - transform.readX(0)[0]
print 'Backward starts at',ws_back.readX(0)[0],', ends at',ws_back.readX(0)[-1],', the width is',ws_back.readX(0)[-1] - ws_back.readX(0)[0]
# Check that the backward transform restores the original data.
# The input spetrum values
y10 = ws.readY(10)
# The spectrum returned from the backward RealFFT
y_back = ws_back.readY(0)
# Check that they are almost equal.
# Using numpy array calculations show that all elements of arrays y_back and y10 are very close
print np.all( np.abs(y_back - y10) < 1e-15 )
# but not equal
print np.all( y_back == y10 )
Number of bins in the input workspace 200
Number of bins in the forward transform 101
Number of bins in the backward transform 200
Input starts at -10.0 , ends at 10.0 , the width is 20.0
Forward starts at 0.0 , ends at 5.05 , the width is 5.05
Backward starts at 0.0 , ends at 20.0 , the width is 20.0
True
False
Categories: Algorithms | Arithmetic\FFT