You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
luafft is an easy to use Fast Fourier Transformation package in pure Lua. It is based on the FFT implementation of KissFFT by Mark Borgerding which is both easy to use and extremly fast. It also uses the complex number module from the Numeric Lua package.
Note: This is a very early version of the code. Although the algorithm has been thoroughly tested by Mark Borgerding, there may very well be bugs that have not been found yet. Please feel free to comment on any source code related problems.
Installation
LuaFFT is part of the LuaRocks repository where it can be easily installed by using:
luarocks install luafft
or simply use Git:
git clone git://github.com/vection/LuaFFT.git
Usage
LuaFFT is very easy to use. The following lines of code show, how to carry out a simple Fast Fourier Transformation. Keep in mind, that values have to be given as complex values, otherwise luafft returns an error.
luafft=require"luafft"locallist1= {}
localsize=2048--Populates a list with random real numbers in complex formatfunctionpopulate(list)
fori=1,sizedolist[i] =complex.new(math.random(), 0)
endend--displays a comparison of two lists with complex numbersfunctioncompare(one, two)
fori=1,#onedoprint(string.format("1: %s\t2: %s\n",
tostring(one[i]),tostring(two[i]))) endend--devide a list with a certain constant factorfunctiondevide(list, factor)
fori,vinipairs(list) dolist[i] =list[i] /factorendend--create a list with random real valuespopulate(list1)
--carry out fast fourier transformation and store result in "ret"ret=fft(list1, false)
--now carry out inverse fast fourier transformation and store result in "ret2"ret2=fft(ret, true)
--After retransformation, we need to devide by the data sizedevide(ret2, size)
--displays a comparison of the input and the output, the real part should be equal--the imaginary part is non zero (but fairly close) due to several calculations--that have been carried out in the FFTcompare(list2,ret)
Licence and Version
luafft is licensed under the same license as Lua -- the MIT license -- and so can be freely used for academic and commercial purposes.
About
Lua package that includes functions for Fast Fourier Transformations.