npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@johnhenry/math-plus-signal

v0.0.5

Published

convolve/stft/istft/findPeaks/sosFilter/butter/resamplePoly for math-plus (issue #44) — v2/v3 SciPy-equivalent bundle, the signal-processing slice

Readme

@johnhenry/math-plus-signal

npm version license

A SciPy-equivalent signal-processing slice for the math-plus tensor family: convolve/correlate, stft/istft/welch, findPeaks, Butterworth filter design (butter) + sosFilter/freqz, and resamplePoly. Pure JS, Tensor in / Tensor out, differential-tested against a real SciPy oracle.

Install

npm install @johnhenry/math-plus-signal

Quick start

import { Tensor } from "@johnhenry/math-plus-tensor-core";
import { butter, sosFilter, convolve1D, findPeaks } from "@johnhenry/math-plus-signal";

// Convolution, NumPy modes
const a = new Float64Array([1, 2, 3, 4]);
const b = new Float64Array([1, 1, 1]);
convolve1D(a, b, "full");  // [1, 3, 6, 9, 7, 4]
convolve1D(a, b, "same");  // [3, 6, 9, 7]
convolve1D(a, b, "valid"); // [6, 9]

// Filter design + zero-state filtering (scipy argument order: sos first)
const sos = butter(4, 0.2, { btype: "lowpass" }); // wn normalized to Nyquist=1
const out = sosFilter(sos, Tensor.from(noisy, { dtype: "f64" }));

// Peak finding
const x = [0, 5, 0, 8, 0, 3, 0, 0, 0, 6, 0];
findPeaks(Tensor.from(x, { dtype: "f64" }), { distance: 4 });
// { indices: [3, 9], heights: [8, 6], prominences: [...] }

API surface

| Group | Exports | |---|---| | Convolution | convolve, convolve1D, correlate, correlate1D, correlate2D (true 2-D, FFT-based, "full" only), applyTimeDomainOp | | Spectral | stft, istft, welch, hannWindow, hammingWindow | | Filters | butter (lowpass/highpass/bandpass/bandstop, SOS output only), sosFilter, freqz | | Peaks | findPeaks (height/distance/prominence options, scipy semantics) | | Resampling | resamplePoly(signal, up, down) — positional integer args, GCD-reduced |

Traps

  • Argument order: sosFilter(sos, signal) — filter first, matching scipy.
  • stft's nperseg must be a power of two, and the default is min(256, signal.length) — a 100-sample signal's default throws. Default window is periodic Hann with 50% overlap (COLA); stft returns the full nperseg bins per frame, not nperseg/2+1. No boundary padding: samples past the last full frame are lost, and istft reconstruction is least accurate in the first/last half-window.
  • welch returns the TWO-sided PSD (return_onesided=False), fs fixed at 1.0; frequency labels follow fftfreq wraparound (Nyquist bin is -0.5).
  • butter's wn is normalized to Nyquist = 1, strictly 0 < wn < 1. SOS section coefficients are deliberately not byte-comparable to scipy's (scipy's own pole/zero-to-section grouping isn't fixed either); end-to-end filter behavior matches to 1e-6.
  • resamplePoly is not bit-compatible with scipy — Hamming-windowed sinc (not Kaiser β=5.0), direct upsample-then-convolve rather than a true polyphase decomposition. A performance gap, not a correctness one.
  • Everything emits f64 regardless of input dtype — pass { dtype: "f64" } to Tensor.from when building inputs.
  • findPeaks never reports endpoints as peaks; filter order is height → prominence → distance (distance ties keep the taller, earliest-discarded).

Tests

npm test. SciPy differential tests skip (not fail) unless a Python with SciPy is found (MATH_PLUS_SCIPY_ORACLE_PYTHON / MATH_PLUS_ORACLE_PYTHON). findPeaks' distance filter carries a regression perf test from issue #101 (was O(n²): 4594 ms at 40,000 candidate peaks; now near-linear).

Provenance

Built across issues #44 (core slice), #70 (correlate/freqz/welch), #84 (correlate2D), and #90 (bandpass/bandstop). Part of the math-plus monorepo; family docs at https://opensource.johnhenry.me/math/.