View Raw SPL
/*****************************************************************************
* *
* FFT2.SPL Copyright (C) 1998-2000 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Performs 2D FFT of an input array *
* *
* Revisions: 12 Mar 1998 RRR Creation *
* 13 Oct 1999 RRR 1D case *
* 19 May 2000 RRR optional lengths *
* *
*****************************************************************************/
#if @HELP_FFT2
FFT2
Purpose: Calculates the 2D FFT of an array
Syntax: FFT2(array, rowlen, collen)
array - a multi-column series
rowlen - optional intger, FFT row size, defaults to
numrows(a)
collen - optional integer, FFT column size, defaults to
numcols(a)
Returns: A complex array
Example:
Fft2({{1, 2}, {3, 4}})
returns the complex array {{10+0i, -2+0i},
{-4+0i, 0+0i}}
Remarks:
FFT2 is often used in image processing applications.
Use FFTSHIFT to flip the output so the 0 frequency is in
the center of the plot.
If the input data is a series (i.e. a single column), a 1D FFT
is performed.
See Also
FFT
IFFT2
#endif
/* 2D FFT */
fft2(a, rowlen, collen)
{
if (argc < 3)
{
if (argc < 2)
{
if (argc < 1) error("fft2 - input array required");
rowlen = numrows(a);
collen = numcols(a);
}
else
{
collen = numcols(a);
}
}
if (numcols(a) > 1)
{
/* amazingly simple one liner */
return(transpose(fft(transpose(fft(a, rowlen)), collen)));
}
else
{
return(fft(a, rowlen));
}
}