FFT and IFFT algorithm Comparison
(Prepared by: Ingrid Narvaez) Objective
To compare and contrast three different approaches of implementing Fast Fourier Transforms.
Content
Note: These classes deal only with one dimensional arrays. This issue will be addressed later for two dimensional inputs.
In this document three different algorithms were investigated with the help of student Mark Gill and a reference from the TA Rui Guo. Please be aware that only the source code of the actual class was shared. The android implementation and display was done by the author of this write up.
The following are the copyright notices for each of the classes presented here and a link to get the necessary files to run the implementations.
First implemented algorithm (Mark’s contribution) /*
* Copyright 2006-2007 Columbia University.
*
* This file is part of MEAPsoft.
*
* MEAPsoft is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation.
*
* MEAPsoft is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details.
*
* You should have received a copy of the GNU General Public License * along with MEAPsoft; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA
*
* See the file "COPYING" for the text of the license.
*/
Source code
http://www.ee.columbia.edu/~ronw/code/MEAPsoft/doc/html/FFT_8java-source.html
Second implemented algorithm (Rui’s Contribution)
/*************************************************************************
* Compilation: javac FFT.java * Execution: java FFT N * Dependencies: Complex.java *
* Compute the FFT and inverse FFT of a length N complex sequence.
* Bare bones implementation that runs in O(N log N) time. Our goal * is to optimize the clarity of the code, rather than performance.
*
* Limitations * ---
* - assumes N is a power of 2 *
* - not the most memory efficient algorithm (because it uses * an object type for representing complex numbers and because * it re-allocates memory for the subarray, instead of doing * in-place or reusing a single temporary array)
*
*************************************************************************/
Source code
http://introcs.cs.princeton.edu/java/97data/FFT.java.html http://introcs.cs.princeton.edu/java/97data/Complex.java.html.
Third implemented algorithm( Ingrid’ Contribution)
/*
* Free FFT and convolution (Java) * Copyright (c) 2012 Nayuki Minase
* http://nayuki.eigenstate.org/page/free-small-fft-in-multiple-languages *
* (MIT License)
* Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions:
* - The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software.
* - The Software is provided "as is", without warranty of any kind, express or * implied, including but not limited to the warranties of merchantability, * fitness for a particular purpose and noninfringement. In no event shall the * authors or copyright holders be liable for any claim, damages or other
* liability, whether in an action of contract, tort or otherwise, arising from, * out of or in connection with the Software or the use or other dealings in the * Software.
*/
Source code
http://nayuki.eigenstate.org/res/free-small-fft-in-multiple-languages/Fft.java
General Information Test Case:
An image of 256 X 256 with a white rectangle was created and passed to each implementation to compute its Fourier transform. A clock was placed above each result indicating how long the algorithm took to complete the transform.
Fourier Transform Emulator Results
Figure1. Emulator FFT Results with time
Fourier Transform Tablet Results
Figure2. Tablet FFT Results with time
Notes and comments:
I believe the fastest implementation for this test case is Mark’s algorithm found at http://www.ee.columbia.edu/~ronw/code/MEAPsoft/doc/html/FFT_8java-source.html. However this file only supports images if a power of two sizes. I have tested the algorithm with other conditions and the time is unstable. It is very fast but, is not versatile in terms of image size.
Rui’s algorithm is very slow, as seen in the pictures above, it takes about twenty seconds on thee emulator to compute the Fourier Transform. The author addresses this issue to the usage of memory to allocate an object per pixel of the image.
The algorithm I found is the faster than Rui’s but slower than Marks. The difference between this algorithm and the first one is the ability to handle non-power of two image sizes.
Inverse Fourier Transform Results:
Figure3. Emulator IFFT Results with time
Inverse Fourier Transform Tablet Results
Figure4. Tablet IFFT Results with time
Notes and comments:
For the Inverse Fourier Transform, again Mark’s algorithm proves to be the fastest.
Ruis algorithm introduces some error to the image. As seen in Figure2, the rectangle in the center of the image gets blurred.
The algorithm I found does a good job also but takes longer to compute.
Note that the difference in time between Mark’s and mine is only in the milliseconds range. Both algorithms are very stable.
My recommendation:
I believe we should go with the algorithm Mark found, If and only if all the images we will be dealing with are of power of two. However if this is not the case, I believe we should go with the one I found. I would definitely discourage the use of the algorithm found by Rui, as it takes longer for both cases and introduces error.
References
[1] “FFT.java Source File.” [Online]. Available:
http://www.ee.columbia.edu/~ronw/code/MEAPsoft/doc/html/FFT_8java-source.html.
[Accessed: 08-Apr-2013].
[2] “FFT.java.” [Online]. Available:
http://introcs.cs.princeton.edu/java/97data/FFT.java.html. [Accessed: 08-Apr-2013].
[3] “Complex.java.” [Online]. Available:
http://introcs.cs.princeton.edu/java/97data/Complex.java.html. [Accessed: 08-Apr- 2013].
[4] “Free small FFT in multiple languages.” [Online]. Available:
http://nayuki.eigenstate.org/page/free-small-fft-in-multiple-languages. [Accessed: 17- Mar-2013].