Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save corbanbrook/469c325734e458ba1415509f52d9c096 to your computer and use it in GitHub Desktop.
Save corbanbrook/469c325734e458ba1415509f52d9c096 to your computer and use it in GitHub Desktop.
dsp.js FFT without generateSpectrum
===== transform size=2048 =====
fft.js x 18,146 ops/sec ±0.91% (88 runs sampled)
jensnockert x 3,728 ops/sec ±1.48% (87 runs sampled)
dsp.js x 27,406 ops/sec ±0.91% (89 runs sampled)
drom x 11,199 ops/sec ±0.88% (89 runs sampled)
Fastest is dsp.js
===== transform size=4096 =====
fft.js x 9,057 ops/sec ±0.97% (85 runs sampled)
jensnockert x 2,937 ops/sec ±1.03% (89 runs sampled)
dsp.js x 12,709 ops/sec ±0.89% (89 runs sampled)
drom x 5,202 ops/sec ±0.92% (87 runs sampled)
Fastest is dsp.js
===== transform size=8192 =====
fft.js x 3,808 ops/sec ±1.01% (86 runs sampled)
jensnockert x 878 ops/sec ±1.19% (87 runs sampled)
dsp.js x 5,016 ops/sec ±0.86% (89 runs sampled)
drom x 2,372 ops/sec ±0.96% (88 runs sampled)
Fastest is dsp.js
===== transform size=16384 =====
fft.js x 1,822 ops/sec ±1.24% (86 runs sampled)
jensnockert x 638 ops/sec ±1.20% (86 runs sampled)
dsp.js x 2,106 ops/sec ±0.89% (88 runs sampled)
drom x 1,111 ops/sec ±0.92% (87 runs sampled)
Fastest is dsp.js
@corbanbrook
Copy link
Author

corbanbrook commented Mar 6, 2017

This is the additional work that DSP js forward transform does each iteration. Many sqrt calls.

  this.calculateSpectrum = function() {
    var spectrum  = this.spectrum,
        real      = this.real,
        imag      = this.imag,
        bSi       = 2 / this.bufferSize,
        sqrt      = Math.sqrt,
        rval, 
        ival,
        mag;

    for (var i = 0, N = bufferSize/2; i < N; i++) {
      rval = real[i];
      ival = imag[i];
      mag = bSi * sqrt(rval * rval + ival * ival);

      if (mag > this.peak) {
        this.peakBand = i;
        this.peak = mag;
      }

      spectrum[i] = mag;
    }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment