This is a `playground`

to test code. It runs a full `Node.js`

environment and already has all of `npm`

’s 400,000 packages pre-installed, including `fft`

with all `npm`

packages installed. **Try it out**:

var fft = require("fft")

- all documents on RunKit are public
`require()`

any package directly from npm- use arrow functions, classes, template strings, and most of ES6
`await`

any promise instead of using callbacks (example)- create your own embedded
**node.js**snippets

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

FFT in JavaScript, it works, I think.

No promises, but I tested it against Wolfram Alpha once, and it was reasonably accurate.

There are optimized kernels for prime factors, 2, 3, 4, so if you want high performance, use lengths that are a factor of those.

Notice that the DFT is not normalized, so `ifft(fft(x)) / n ~= x`

```
/* Create a new FFT object */
var fft = new FFT.complex(n, inverse)
/* Output and input should be float arrays (of the right length), type is either 'complex' (default) or 'real' */
fft.process(output, outputOffset, outputStride, input, inputOffset, inputStride, type)
/* Or the simplified interface, which just sets the offsets to 0, and the strides to 1 */
fft.simple(output, input, type)
```

You can also install via npm, the name is `fft`

in the registy.

I was too lazy to calculate the butterflies myself, so they are inspired by kissfft, which is a small library for doing discrete fourier transforms.

- package on npmhttps://npmjs.com/package/fft

RunKit is a free, in-browser JavaScript dev environment for prototyping **Node.js** code, with every **npm** package installed. Sign up to share your code.

Sign Up for Free