1.0.3 • Published 5 months ago

webfft v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

WebFFT

The Fastest Fourier Transform on the Web!

Try it out

Documentation

We welcome feedback via GitHub Issues and PRs!

Overview

WebFFT is a metalibrary containing many FFT libraries, both javascript and webassembly based. We'll refer to these as sub-libraries.

There is a default sub-library that is used, but if you run

import webfft from "webfft";
const fft = new webfft(1024);
fft.profile(); // optional arg sets number of seconds spent profiling

it will benchmark them all and use the best one for future calls.

As part of importing the library we will run a check to see if wasm is even supported, so the profiler and default can know which pool to pull from.

Basic Usage

const webfft = require('webfft');

// Instantiate
const fftsize = 1024; // must be power of 2
const fft = new webfft(fftsize);

// Profile
profileResults = fft.profile(); // results object can be used to make visualizations of the benchmarking results

// Create Input
const input = new Float32Array(2048); // interleaved complex array (IQIQIQIQ...), so it's twice the size
input.fill(0);

// Run FFT
const out = fft.fft(input); // out will be a Float32Array of size 2048
// or
const out = fft.fft(input, 'kissWasm');

fft.dispose(); // release Wasm memory

2D FFTs

WebFFT also supports 2D FFTs, using an array of arrays. The inner arrays should be length 2*size and the outter array length should be a power of 2 but does not need to match the inner.

import webfft from "webfft";

const fftsize = 1024;
const outterSize = 128;
const fft = new webfft(fftsize);
let inputArr = [];
for (let j = 0; j < outterSize; j++) {
  const subArray = new Float32Array(fftsize * 2);
  for (let i = 0; i < fftsize * 2; i++) {
    subArray[i] = i * j * 1.12312312; // Arbitrary
  }
  inputArr.push(subArray); // add inner array
}
const out = fft.fft2d(inputArr);

fft.dispose(); // cleanup wasm

Other Notes

Use fftr() for real-valued input, the output will still be complex but only the positive frequencies will be returned.

You don't have to pass fft/fftr/fft2d typed arrays, they can be regular javascript arrays.

Run unit tests with npm run test

1.0.2

5 months ago

1.0.3

5 months ago

1.0.1

6 months ago

1.0.0

8 months ago

0.0.34

8 months ago

0.0.33

8 months ago

0.0.32

8 months ago

0.0.31

8 months ago

0.0.30

8 months ago

0.0.29

8 months ago

0.0.28

8 months ago

0.0.27

8 months ago

0.0.26

8 months ago

0.0.25

8 months ago

0.0.23

8 months ago

0.0.22

8 months ago

0.0.21

8 months ago

0.0.20

8 months ago

0.0.19

8 months ago

0.0.18

8 months ago

0.0.17

8 months ago

0.0.16

8 months ago

0.0.15

8 months ago

0.0.14

8 months ago

0.0.13

8 months ago

0.0.12

8 months ago

0.0.11

8 months ago

0.0.10

8 months ago

0.0.9

8 months ago

0.0.8

8 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

8 months ago

0.0.3

8 months ago

0.0.2

8 months ago

0.0.1

8 months ago