FFTs with multidimensional data

When passing multidimensional data to the Scilab FFT functions with minimal arguments, a multidimensional FFT is performed. However, if one wishes to perform a single-dimensional FFT on a multidimensional dataset additional arguments must be passed.

Consider a two-dimensional data array, a, in which each column represents a separate vector of data that should be Fourier transformed. The following code performs such an FFT:

A = fft(a, -1, size(a, 1), 1);

The third argument indicates the length of the vectors (in this case the number of rows in a). The fourth argument indicates the distance in linear format between successive elements of a vector. Because Scilab stores arrays in column major format, the elements of a column are adjacent (i.e. a separation of 1) in linear format.

If however, the vectors to be transformed correspond to rows of the array then the single-dimensional transform would be performed as

A = fft(a, -1, size(a, 2), size(a, 1));

In this case, the length of the vectors is the number of columns in a. Because of the column major formatting, successive elements in a row are separated by the number of elements in a column.

Higher-dimensional arrays

The Scilab FFT functions only accept vectors and two-dimensional arrays. In order to transform higher-dimensional arrays, one must first reshape the array to a vector or two-dimensional array. The following example performs an FFT along the third dimension of a three-dimensional array.

// Create a three-dimensional array of size (3, 4, 5).
a = rand(3, 4, 5);

// Reshape the array to a vector.
a = matrix(a, 60, 1);

// Perform the single-dimensional FFT.
A = fft(a, -1, 5, 12);

// Reshape the array.
A = matrix(A, 3, 4, 5);

The following code performs a single-dimensional FFT along the nth dimension of multi-dimensional array.

function [A] = fftn(a, p, n)

  // Store the dimensions of the array.
  s = size(a);

  // Convert the array to a vector.
  b = matrix(a, prod(s), 1);

  // Perform the transform along the nth dimension.
  B = fft(b, p, s(n), prod(s(1:(n - 1))));

  // Convert the vector back to an array.
  A = matrix(B, s);


public: howto/FFTMultidimensionalData (last edited 2011-03-30 16:17:56 by localhost)