2D Fourier Transform

Overview

This program will perform a 2D Fourier transform to each section in the input with the option to process the data beforehand to remove trends and smooth discontinuities at the edges.

The controls in the user interface include a standard set of controls for selecting the input file, output file, and region of interest and for starting and interrupting processing. The other controls are organized as follows:

Because of the nature of the Fourier transform, the handling of the data header is different than most other Priism applications:

The Fourier transforms calculated have these properties:

Topics

Overview | Region processing | Shift | Preprocessing | Window/taper | Edge handling | Output size | Command line

Related Priism Topics

Priism | 3D Fourier Transform


Shift

The Shift field specifies a translation, measured in pixels, that is applied in conjunction with the transform. The translation is circular in the sense that something which is pushed off one side wraps around to the opposite side.

When a forward transform is performed, a shift of (x, y) moves pixel (x, y) to the origin, (0,0). For a reverse transform, the same shift will place what would appear at the origin, (0,0), at pixel (x, y).

Topics

Overview | Region processing | Shift | Preprocessing | Window/taper | Edge handling | Output size | Command line


Preprocessing

The input region can be processed to remove an offset or trend before the data is tapered, padded, and transformed. To display the controls for this processing, press the button labelled Set preprocessing in the main dialog. There are five types of processing that can be done; select one by pressing the appropriate toggle in the dialog. The processing options are:

None
The input is not modified before padding and transforming the data.
Subtract offset
The specified value is subtracted from all the input values.
Subtract mean
For each 2D (xy) input region, the mean of the region is subtracted from all values in the region.
Remove linear trend
An average slope for each 2D (xy) input region is estimated by averaging values from the first and last third of each dimension; the linear trend corresponding to that average slope and the mean of the region is subtracted from the input data. The algorithm used is the average slope method extended to two dimensions (Digital data analysis procedures, Bendat and Piersol, 1st Edition, 1971, page 288).
Remove trends up to order
A polynomial of the given order is fit to each 2D (xy) input region. That polynomial evaluated at each input point is then subtracted from the input before padding and transforming the data.

If you are intending to taper the data and the data does not already have a zero mean, you should consider using the mean subtraction, linear trend removal, or polynomial fit options.

Topics

Overview | Region processing | Shift | Preprocessing | Window/taper | Edge handling | Output size | Command line


Window/taper

Applying a windowing function, also called tapering, multiplies the data by a function which goes to zero (or near zero) at the edges of the data. This is done before the forward transform to remove discontinuities at the edges which can complicate the interpretation of frequency spectra; the disadvantage of applying a window is that it essentially throws away parts of the input and it broadens features in the spectra.

The windowing functions used are separable, i.e, the windowing function, W(x,y), can be written as the product of WX(x) and WY(y). WX and WY are calculated from the same formula but with different inputs for the number of pixels, n, and the fraction, f, of the dimension that is attenuated by the windowing function. The two values in the Coverage field are the values of f divided by two for the x and y directions respectively. Commonly used values for the coverage are 0.5 (a "full taper") and 0.1 (a 10% taper). The power, x, is used by half-sine windowing function.

The functions used to calculate the windowing functions are shown below. i is the pixel index and runs from 0 to n minus 1, and e is given by

      { floor(0.5 + f / 2.0 * n)          n even
  e = {
      { floor(0.5 + f / 2.0 * (n - 1))    n odd

Rectangular

         { 0     i < e
  w(i) = { 1     e <= i <= n - e
         { 0     i > n - e

Because of the sharp cutoffs of the rectangular window, it is not particularly useful; it's provided for completeness.

Triangular

         { i / e           i < e
  w(i) = { 1               e <= i <= n - e
         { (n - i) / e     i > n - e

Half-sine^power

         { (sin(pi * i / (2 * e)))^x           i < e
  w(i) = { 1                                   e <= i <= n - e
         { (sin(pi * (n - i) / (2 * e)))^x     i > n - e

Hamming

         { 0.54 - 0.46 * cos(pi * i / e)           i < e
  w(i) = { 1                                       e <= i <= n - e
         { 0.5f - 0.46 * cos(pi * (n - i) / e)     i > n - e

Blackman

         { cos(pi * i / e)           i < e
  a(i) = { -1                        e <= i <= n - e
         { cos(pi * (n - i) / e)     i > n - e

  w(i) = 0.34 - a(i) * (0.5 - a(i) * 0.16)

Topics

Overview | Region processing | Shift | Preprocessing | Window/taper | Edge handling | Output size | Command line


Edge handling

The dimensions of the input region can be extended by adding elements at the end of each dimension. This is typically done for two reasons:

To display the controls for the amount of padding and the values of the elements added, press the button labelled Set edge handling in the main dialog. For each dimension the Width field sets the number of elements that will be added. When the toggle labelled Use default width is on, the Width field will automatically be set so the padded size can be efficiently handled. There are three ways in which the values of the added elements are set. These are:

Pad with value
Use the given value for all the elements added to a dimension. The imaginary component of the value is only used if the input data is complex.
Pad with mean
Use the mean of the 2D (xy) input region being processed when padding the dimension.
Pad with linear ramp
For each line in x (or column for y) the padding elements added to the line (or column) are a linear combination of the first and last element of that input line (or column).

If a forward transform is being done and the data was tapered, than padding with zeroes is the best choice. Padding with zeroes is also appropriate if a reverse transform is being done and you want the grid sampled on a finer grid using Fourier interpolation.

Topics

Overview | Region processing | Shift | Preprocessing | Window/taper | Edge handling | Output size | Command line


Output size

When a reverse transform is performed, the size of the region written to the output file may be smaller than that of the straight Fourier transform of the input after padding. Press the button labelled Set output size to open a dialog with controls for trimming the data. For each dimension, there is a display of the size of the transformed data. The amount of trimming for each dimension is listed in an editable field.

Topics

Overview | Region processing | Shift | Preprocessing | Window/taper | Edge handling | Output size | Command line


Command line

FTransform2D accepts the command-line arguments described in Region.html. In addition, FTransform2D accepts the options shown below (optional parts are shown in brackets). If mutually exclusive options (i.e. for selection of the transform direction or windowing function), the last option that appears on the command line takes precedence. The exception to this is if you specify both a transform type and an output pixel format: then, if the output pixel format is inconsistent with the transform type, the transform type takes precedence and the output pixel format will be the default for that transform type. The defaults for real-valued data are to compute a forward transform where the negative x frequencies are not retained, no preprocessing or windowing is done, the data is padded with zeros to an efficient size, and the output pixel format is complex stored as floating-point. The defaults for complex-valued data are to compute a reverse complex-to-real transform with a result whose x size is even before trimming, no padding before the transform or trimming after the transform is done, and the output pixel format is floating-point.

-complex_forward
Causes a forward transform of complex data to be computed. The default output pixel format is the same as the input pixel format.
-real_complex
Causes a forward transform of real-valued data to be computed; the negative x frequencies (redundant because of conjugate symmetry) are not retained. The default output pixel format is complex stored as floating-point.
-real_complex_full
Causes a forward transform of real-valued data to be computed; the negative x frequencies are retained. The default output pixel format is complex stored as floating point.
-complex_reverse
Causes a reverse transform of complex data to be computed. The default output pixel format is the same as the input pixel format.
-complex_real
Causes a reverse complex-to-real reverse transform to be computed. Assumes that the padded size for the forward transform was even. The default output pixel format is floating-point.
-complex_real_odd
Causes a reverse complex-to-real reverse transform to be computed. Assumes that the padded size for the forward transform was odd. The default output pixel format is floating-point.
-center_zero
Specifies that the zero frequency is at (0, (ny - 1) / 2) for real to complex or complex to real transforms and at ((nx - 1) / 2, (ny - 1) / 2) for complex to complex transforms. If not present on the command line, the zero frequency is at (0,0).
-same_units
If specified, the pixel spacing units are preserved and the origin and start indices are modified only for region selection during forward transforms. Otherwise, the x and y pixel spacing units are converted (to frequency units during a forward transform and to spatial units during a reverse transform), the x and y components of the origin are expressed in the same units, and the x and y start indices are set to zero.
-shift=x_shift:y_shift
Specifies that, in conjunction with the transform, the data should be shifted by x_shift pixels in x and y_shift pixels in y. For a forward transform, a positive shift, s, moves pixel s to the origin. For a reverse transform, a positive shift, s, moves the origin to pixel s. The default shift values are zero pixels in all directions.
-subtract=value or -subtract=mean
Specifies that the input data should be preprocessed by subtracting value or the mean. This option is ignored for reverse transforms.
-linear_detrend
Specifies that the input data should be preprocessed by subtracting the linear trend which corresponds to the estimated average slope. This option is ignored for reverse transforms.
-polyfit=n
Specifies that the input data should be preprocessed by subtracting the least-squares fit polynomial of order n. Valid values of n range from one to 10. This option is ignored for reverse transforms.
-rectangular=x_coverage:y_coverage
Selects a rectangular windowing function that attenuates 200 times x_coverage percent of the data in x and 200 times y_coverage percent of the data in y. Valid values for x_coverage and y_coverage are between 0 and 0.5.
-triangular=x_coverage:y_coverage
Selects a triangular windowing function that attenuates 200 times x_coverage percent of the data in x and 200 times y_coverage percent of the data in y. Valid values for x_coverage and y_coverage are between 0 and 0.5.
-halfsine=x_coverage:y_coverage
Selects a half-sine windowing function (consult the Window/taper topic for details) that attenuates 200 times x_coverage percent of the data in x and 200 times y_coverage percent of the data in y. Valid values for x_coverage and y_coverage are between 0 and 0.5. Use -halfsine_power to set the exponent, which controls the sharpness of the window edges.
-halfsine_power=p
Sets the exponent for the half-sine windowing function. This option is ignored when other windowing functions are used. If this option is not explicitly specified when the half-sine windowing function is used, the exponent used is one.
-hamming=x_coverage:y_coverage
Selects a Hamming window function (consult the Window/taper topic for details) that attenuates 200 times x_coverage percent of the data in x and 200 times y_coverage percent of the data in y. Valid values for x_coverage and y_coverage are between 0 and 0.5.
-blackman=x_coverage:y_coverage
Selects a Blackman window function (consult the Window/taper topic for details) that attenuates 200 times x_coverage percent of the data in x and 200 times y_coverage percent of the data in y. Valid values for x_coverage and y_coverage are between 0 and 0.5.
-xpad=default or -xpad=n
Specifies that the x dimension should be padded by the default amount or by n pixels, where n is a non-negative integer.
-xpad_value=mean or -xpad_value=ramp or -xpad_value=rv[:iv]
Specifies what values to use when padding the x dimension. -xpad_value=mean causes the data to be padded with the mean value. -xpad_value=ramp causes the data to be padded with values which range linearly from the value at one boundary to the value at the other boundary. The last form causes the data to be padded with a constant value whose real component is rv and whose imaginary component is iv. If the imaginary component is omitted, it is assumed to be zero.
-ypad=default or -ypad=n
Is similar to -xpad but specifies the amount of padding in the y dimension.
-ypad_value=mean or -ypad_value=ramp or -ypad_value=rv[:iv]
Is similar to -xpad_value but specifies the padding values for the y dimension.
-xtrim=n
Trims n pixels from the x dimension before output; n must be a non-negative integer. Trimming is only done on reverse transforms, and is ignored for forward transforms.
-ytrim=n
Is similar to -xtrim but controls the amount trimmed from the y dimension before output.

As an example, if in.dat is real-valued, then

    FTransform2D in.dat fft.dat -subtract=500 -halfsine=.1

subtracts a background value (500 in this case), uses a half-sine windowing function to taper the edges of the data, and writes the result of the forward Fourier transform in fft.dat.

Topics

Overview | Region processing | Shift | Preprocessing | Window/taper | Edge handling | Output size | Command line