FFT.js
Implementation of Radix-4 FFT.
Usage
const FFT = require('fft.js');
const f = new FFT(4096);
const input = new Array(4096);
input.fill(0);
const out = f.createComplexArray();
If data
has just real numbers as is the case when toComplexArray
is
used - real FFT may be run to compute it 25% faster:
const realInput = new Array(f.size);
f.realTransform(out, realInput);
realTransform
fills just the left half of the out
, so if the full
spectrum is needed (which is symmetric):
f.completeSpectrum(out);
If data
on other hand is a complex array:
const data = f.toComplexArray(input);
f.transform(out, data);
Inverse fourier transform:
f.inverseTransform(data, out);
Benchmark
$ npm run bench
===== table construction =====
fft.js x 1,426 ops/sec ±0.70% (93 runs sampled)
Fastest is fft.js
===== transform size=2048 =====
fft.js x 35,153 ops/sec ±0.83% (94 runs sampled)
jensnockert x 5,037 ops/sec ±0.98% (91 runs sampled)
dsp.js x 23,143 ops/sec ±0.64% (96 runs sampled)
drom x 14,372 ops/sec ±0.76% (92 runs sampled)
Fastest is fft.js
===== transform size=4096 =====
fft.js x 15,676 ops/sec ±0.76% (94 runs sampled)
jensnockert x 3,864 ops/sec ±1.02% (93 runs sampled)
dsp.js x 7,905 ops/sec ±0.50% (97 runs sampled)
drom x 6,718 ops/sec ±0.78% (96 runs sampled)
Fastest is fft.js
===== transform size=8192 =====
fft.js x 6,896 ops/sec ±0.79% (96 runs sampled)
jensnockert x 1,193 ops/sec ±0.73% (94 runs sampled)
dsp.js x 2,300 ops/sec ±0.74% (95 runs sampled)
drom x 3,164 ops/sec ±0.67% (95 runs sampled)
Fastest is fft.js
===== transform size=16384 =====
fft.js x 3,123 ops/sec ±0.84% (95 runs sampled)
jensnockert x 855 ops/sec ±1.02% (92 runs sampled)
dsp.js x 948 ops/sec ±0.70% (94 runs sampled)
drom x 1,428 ops/sec ±0.56% (93 runs sampled)
Fastest is fft.js
===== realTransform size=2048 =====
fft.js x 44,447 ops/sec ±0.64% (91 runs sampled)
fourier-transform x 30,558 ops/sec ±0.82% (92 runs sampled)
Fastest is fft.js
===== realTransform size=4096 =====
fft.js x 19,363 ops/sec ±0.71% (95 runs sampled)
fourier-transform x 14,290 ops/sec ±0.75% (94 runs sampled)
Fastest is fft.js
===== realTransform size=8192 =====
fft.js x 9,240 ops/sec ±0.77% (95 runs sampled)
fourier-transform x 5,922 ops/sec ±0.65% (94 runs sampled)
Fastest is fft.js
===== realTransform size=16384 =====
fft.js x 3,809 ops/sec ±1.91% (91 runs sampled)
fourier-transform x 2,536 ops/sec ±0.65% (94 runs sampled)
Fastest is fft.js
LICENSE
This software is licensed under the MIT License.
Copyright Fedor Indutny, 2017.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.