Luau FFT | Calculate fast Fourier transforms on Roblox

Luau FFT

About

Luau FFT is a module which can be used to perform discrete Fourier transforms on Roblox.


Features

  • Bundled with an easy-to-use complex number module
  • Calculate fast Fourier transforms
  • Calculate discrete Fourier transforms

What is a Fourier transform?

In simple terms, a Fourier transform can be used to find out the intensity of sine waves of various frequencies that can be used to construct virtually any function. A common use for this is to calculate the frequency spectrum of a group of audio samples for audio visualization. I won’t get into the mathematical side of it here, but if you’re interested, you can check out the documentation of this module, Wikipedia or a bunch of other sources.


How to use

To get the discrete Fourier transform of a table of numbers, simply require the fourier module and call either the dft or fft function with the arguments (samples, nil, true). More advanced ways to use the module are in the documentation.


Example

An example of what this module could potentially be used for.


Limitations

The Roblox Luau VM cannot perform thousands of iterations of a loop quickly, so using large sample tables is not recommended for real-time applications. Using large amounts of samples will quickly increase the time it takes to calculate the DFT/FFT. As for audio visualizers, being able to only sample audio at 60 Hz (max framerate without an unlocker) means that the spectrum can only be calculated for frequencies up to 30 Hz per the Nyquist-Shannon sampling theorem.


Links


License

This resource is licensed under the Mozilla Public License Version 2.0.

13 Likes

FFT performance improvements

There were some performance issues with the FFT algorithm in the previous release. I have implemented the Cooley-Tukey FFT algorithm in release 1.0.1, which is now available on GitHub and Roblox. The improved FFT function is significantly faster than the old one, so using the newer version is recommended.

3 Likes

Cool module. I think this could be useful for development.