1.0.3 • Published 2 years ago

webfft v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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

2 years ago

1.0.3

2 years ago

1.0.1

2 years ago

1.0.0

3 years ago

0.0.34

3 years ago

0.0.33

3 years ago

0.0.32

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.28

3 years ago

0.0.27

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.23

3 years ago

0.0.22

3 years ago

0.0.21

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.17

3 years ago

0.0.16

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.13

3 years ago

0.0.12

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago