Calculation of complex numbers for fft


since the available fft-node isn't working, i want to code my own fft. I did it before with matlab and now i want to try it as a function in javascript.
how can I include complex numbers in my calculation? I did a lot of research but couldn't find the right answer yet.

Thanks in advance!

There are a number of JavaScript libraries available for handling complex numbers. Not had a need to use any of them myself:

complex numbers - npm search (

Equally, there are a number of libraries for doing FFT:

fft - npm search (

Most of those should work in a function node now that loading of external libraries is directly supported.

My problem is that I'm using the Flow Creator from Siemens Industrial Edge, which is basically a Node Red. But I don't think I have the possibility to import javaScript libraries here...

Ah. Do you have access to the settings.js file? You could load one the older way if so.

If not, is Python accessible?

Alternatively, do you have an external system you can run the calculations on? You could potentially send the data to another instance of Node-RED on a different device by creating a REST API there using an http-in/-out flow. The output of that flow would be the answer which would return to the Siemens device.

One approach is to represent complex numbers as pairs of values, either in arrays, classes, structures or some other form. Most languages don't have explicit complex number representation, so it's necessary to either write your own or use libraries which look after them for you (usually using something like the methods mentioned above).

It's been quite a while since I wrote FFT and digital filter code, but I did it in C, and used structure types for complex numbers and wrote functions to handle operations on them.

There's a lot of FFT source code available in various languages, so it might be worth taking a look to see how they implement complex types, and use something which is closest to your needs.