The FFT command computes the Fast Fourier Transform of its inputs in rectangular coordinate form. The input vector lengths must be a power of 2. Both input vectors must be the same length. inputRe contains the real parts of all the data points. inputIm contains the imaginary parts of all the data points. outputRe will contain the real parts of the transformed data. outputIm will contain the imaginary parts of the transformed data. The following related subroutines are included in the Statistics101 subroutine library (See the table below):
Implementation note: The implementation of the FFT command uses a non-recursive version of the Cooley-Tukey FFT. It runs in O(n log(n)) time, where n is the length of the input vectors. Source for the algorithm is: https://introcs.cs.princeton.edu/java/97data/InplaceFFT.java
|
Copy the following program, paste it
into the Statistics101 editor
window and run it. It demonstrates the results of the forward and
inverse FFT. 'Create a sine wave input: nPoints = 1024 'Must be a power of 2 angle = 1,nPoints angleRad = TORAD(angle) y = sin(angleRad) XYGRAPH angle y 'Take FFT of the sine wave: zeroVec = nPoints#0 FFT y zeroVec outRe outIm XYGRAPH angle outRe XYGRAPH angle outIm 'Take the inverse FFT of the above output: IFFT outRe outIm y2Re y2Im XYGRAPH angle y2Re XYGRAPH angle y2Im The following program is the same as that above except that it uses COMPLEX rectangular coordinate vectors (i.e., a single vector containing both re and im parts) with the "convenience routines" (see table below) for those vectors. The "convenience" routines in this example program are really not convenient because we had to force the data into the proper format using other COMPLEX_* subroutines. But if you were manipulating most of your data in the complex rectangular coordinate form, they might save a few programming steps. 'Create a sine wave input: nPoints = 1024 'Must be a power of 2 angle = 1,nPoints angleRad = TORAD(angle) y = sin(angleRad) XYGRAPH angle y 'Take FFT of the sine wave: zeroVec = nPoints#0 COMPLEX y zeroVec zRectIn COMPLEX_FFT zRectIn zRectOut COMPLEX_RE zRectOut outRe COMPLEX_IM zRectOut outIm XYGRAPH angle outRe XYGRAPH angle outIm 'Take the inverse FFT of the above output: COMPLEX_IFFT zRectOut zOut COMPLEX_RE zOut outRe COMPLEX_IM zOut outIm XYGRAPH angle outRe XYGRAPH angle outIm |
Arguments: | Re,
Im |
Rho,
Theta |
Z
(Rectangular) |
Z
(Polar) |
Forward
Transform: |
FFT |
- |
COMPLEX_FFT |
COMPLEX_FFTZ |
Inverse
Transform: |
IFFT |
- |
COMPLEX_IFFT |
COMPLEX_IFFTZ |