fft.js icon indicating copy to clipboard operation
fft.js copied to clipboard

2D FFT

Open Bobingstern opened this issue 2 years ago • 2 comments

What is the most efficient way to perform a 2D FFT using this library?

Bobingstern avatar Feb 14 '23 14:02 Bobingstern

Certainly not the most efficient way, but you do know that 2D FFT is just a FFT over all the rows and of this intermediate result all the cols? (or the other way around, doesn't matter)?

So in that case make an Array of Arrays, perform a 1D FFT and then rearrange the contents so the array goes over cols/rows and perform the FFT another time.

If you want a more performant solution I suggest altering the library with variants with an offset and a step paramter to the core functions. Which this you can have a data array of the size rows*cols. Then call it row times with increasing i*rowlength offset, then call it another time of col times with i offset and i*rowlength as step parameter into the data. As far I remember this is how KISS did it. (It didn't need an offset parameter tough, due to C pointer arithmetic).

PS: Which brings me to, @maintainer, have you tried to use typed arrays? like Float64Array? IMO this could possible improve perfmance, @Bobingstern I think this would a way to get good perfomance without changing the library, instead of having it constructing the ComplexArrays itself, just hand it TypedArrays of Float64Array, I think it shouldn't notice, and with these basing on a Buffer you can modify offset and spread aka stepwith.. I doubt you get better performance than that.

axkibe avatar Jul 07 '23 15:07 axkibe

FYI: I experimented a little with typed arrays. fft.js gets ~25% slower simply from using them as dropin replacement for plain Arrays. (node v18.14.0). I don't understand why, has to do with some nifty js optimizations I guess.

axkibe avatar Jul 19 '23 10:07 axkibe