Minimalistic and efficient FFT implementation for 2n-size inputs. Includes regular and asm.js versions.
var ft = require('fourier-transform')
var db = require('decibels')
var sine = require('audio-oscillator/sin')
// generate sine wave 440 Hz
var waveform = sine(1024, 440)
//get normalized magnitudes for frequencies from 0 to 22050 with interval 44100/1024 ≈ 43Hz
var spectrum = ft(waveform)
//convert to decibels
var decibels = spectrum.map((value) => db.fromGain(value))
To use asm.js version, require as require('fourier-transform/asm')
. That is ~35% faster.
To all the existing fft packages, without them this one would not be possible. Special thanks to @corbanbrook for the most efficient implementation in dsp.js. This package is based on dsp.js RFFT, which is based on RealFFT.
If you find it slow, difficult or broken, please post an issue. If you have ideas or know-hows for better implementation - PR’s are welcome.
- fourier transforms benchmark.
- ndarray-fft FFT for ndarrays, allowing not-power-of-two inputs.
- gl-fourier WebGL fourier transform implementations.
- gl-spectrum render spectrum in 2d/3d canvas.