Install Asset
Install via Godot
To maintain one source of truth, Godot Asset Library is just a mirror of the old asset library so you can download directly on Godot via the integrated asset library browser
Quick Information
Fast Fourier Transform in GDScript
Table of Contents
Fast Fourier Transform in GDScript
Mostly modified from The javascript FFT on rosetta code.
Installation
- Install addon
- Enable plugin from the project-settings
The singleton FFT
is autoloaded at your project start, so you can simply call the static functionality as shown below.
var result = FFT.fft([1, 1, 1, 1, 0, 0, 0, 0])
result = FFT.fft(result)
for item in result:
item.log()
Notes
This is an in-place modification for speed, so if you want to ensure functional purity you can duplicate your data array before passing it into the fft
or ifft
functionality. The data array is also returned.
var my_arr = [1, 1, 1, 1, 0, 0, 0, 0]
var result = FFT.fft(my_arr.duplicate(true))
# my_arr remains unchanged
Reference
Public methods
FFT.fft(data: Array<float>) -> Array<Complex>
Forward transformation from data-space into fourier-space.
FFT.ifft(data: Array<Complex>) -> Array<Complex>
Reverse transformation from fourier-space into data-space.
FFT.reals(data: Array<Complex>) -> Array<float>
Returns the real part of each data point.
FFT.imags(data: Array<Complex>) -> Array<float>
Returns the imaginary part of each data point.
FFT.ensure_complex(data: Array<MaybeComplex>) -> Array<Complex>
Ensure that all data items in the array are Complex numbers.
Internal methods
FFT.conjugate(amplitudes: Array<Complex>) -> Array<Complex>
Flips the sign of each amplitude
FFT.keyed(data: Array<Dictionary>, key: String) -> Data<Any>
Returns data[idx][key] for each index.
Fast Fourier Transform in GDScript
Reviews
Quick Information
Fast Fourier Transform in GDScript