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

@rfkit/spectrum-analyzer

v0.9.2

Published

A high-performance spectrum analyzer library for RF signal processing, supporting real-time spectrum analysis, waterfall display, and multi-segment frequency scanning

Readme

@rfkit/spectrum-analyzer

高性能 RF 频谱分析库,支持实时频谱分析、瀑布图显示和多段频率扫描。

提供 JS 版本 和 WASM 高性能版本 两种选择。

安装

pnpm add @rfkit/spectrum-analyzer

正式版本默认走 Release PR -> 合并 -> GitHub Actions 自动发布 npm。仓库里的 publish:npm / build:npm 只保留为调试或应急入口,不作为日常正式发版流程。

使用

JS 版本(默认)

import {
  ExtraDataMode,
  SpectrumAnalyzer,
  LevelStreamAnalyzer,
  type SpectrumConfig,
  type SpectrumOutputData,
} from '@rfkit/spectrum-analyzer';

const analyzer = new SpectrumAnalyzer({
  maxPoints: 2048,
  outputPoints: 1024,
  enableStatistics: true,
  onSpectrumUpdate: (data) => {
    console.log(data.realData);
  },
});

// 处理频谱数据
analyzer.process({ data: Float32Array, timestamp: Date.now() });

分段额外数据

setExtraData 默认保持完整数组设置语义。传入第三个参数后,每条额外数据会独立维护全长缓冲区,并按 segmentOffset + offset 局部写入;未写入的位置保留为 NaN。

analyzer.setExtraData(
  {
    traceA: traceAChunk,
    traceB: traceBChunk,
  },
  ExtraDataMode.MERGE,
  { segmentOffset: 1, offset: 200 },
);

天线因子补偿

setAntennaFactor 支持全长数组、分段/偏移局部写入与清空,JS 与 WASM 入口 API 一致:

// 1. 全长数组(支持正数、0、负数;长度需等于当前 maxPoints,不等时静默跳过)
analyzer.setAntennaFactor(new Float32Array(2048).fill(6.0));

// 2. 分段/偏移局部写入(复用 segmentOffset / offset 校验)
analyzer.setAntennaFactor(segmentFactorChunk, { segmentOffset: 1, offset: 0 });

// 3. 清空天线因子(归零)
analyzer.setAntennaFactor(); // 或传入空 Float32Array / []

// 4. 开关控制(开关开启时变更天线因子会立即重采样并触发 onSpectrumUpdate)
analyzer.setAntennaFactorSwitch(true);

数据与生命周期契约:

  • 有效数值:接受任意有限数值(正数、0、负数);数组中非有限值(NaN / ±Infinity)按单点回退为 0。全 0 因子与开关关闭时不产生补偿。
  • 点数计算:initializeSegments() 优先采用分段正整数 pointCount,否则按 Math.floor(((stopFrequency - startFrequency) * 1000) / stepFrequency + 1e-9) + 1 计算。
  • 生命周期:reset()、initializeSegments() 与非分段 process() 改变点数时会清空天线因子并保持 antennaFactorSwitch 不变;clearMetricsData()、updateSamplingRange()、updateProcessing() 保持当前天线因子不变。

WASM 高性能版本

SpectrumAnalyzer 和 LevelStreamAnalyzer 的 WASM API 与 JS 版本一致;WaterfallAnalyzer 和 SeriesManager 为纯 JS 实现,同样可从 /wasm 入口导入(重导出)。

import {
  initWasm,
  SpectrumAnalyzer,
  LevelStreamAnalyzer,
  WaterfallAnalyzer,
  SeriesManager,
} from '@rfkit/spectrum-analyzer/wasm';

// 应用启动时初始化(仅需一次)
await initWasm();

// 之后使用方式与 JS 版本完全一致
const analyzer = new SpectrumAnalyzer({
  maxPoints: 2048,
  outputPoints: 1024,
  enableStatistics: true,
  onSpectrumUpdate: (data) => {
    console.log(data.realData);
  },
});

analyzer.process({ data: Float32Array, timestamp: Date.now() });

核心组件

SpectrumAnalyzer

频谱分析器,支持:

  • 实时数据处理与重采样
  • 最大值/最小值/平均值统计
  • 瀑布图数据管理
  • 天线因子补偿
  • 模板超限检测
  • 多段频率扫描

WaterfallAnalyzer

独立瀑布图数据分析器,支持完整矩阵更新、增量帧,以及 X/Y 二维裁剪与降采样。采样范围使用原始矩阵索引的半开区间 [start, end):

import { WaterfallAnalyzer } from '@rfkit/spectrum-analyzer';

const analyzer = new WaterfallAnalyzer({
  onWaterfallUpdate: ({ data }) => {
    console.log(data);
  },
});

analyzer.setData(waterfallFrames);
analyzer.updateSamplingRange({
  x: [100, 900],
  y: [20, 120],
  outputWidth: 400,
  outputHeight: 100,
});

setData() 要求数据为非空等宽矩阵,传入空数组表示清空;appendFrame() 用于实时增量场景,应配置 maxFrames 避免缓存无限增长。采样范围会夹紧到矩阵边界,夹紧后为空的范围会报错。

WaterfallAnalyzer 为纯 JS 实现,可从默认入口或 /wasm 入口导入。

LevelStreamAnalyzer

电平流分析器,支持电平概率分布统计和时间/点数缓存。JS 和 WASM 入口用法相同。

import { LevelStreamAnalyzer } from '@rfkit/spectrum-analyzer';

const analyzer = new LevelStreamAnalyzer({
  cacheTime: 15000,
  granularity: 1,
  range: [-120, 0],
  onLevelStreamUpdate: ({ spectrumData, timestampData }) => {
    console.log(spectrumData, timestampData);
  }
});

const now = Date.now();
analyzer.processBatch(
  new Float32Array([-65.5, -63, -64.5]),
  new Float64Array([now - 2, now - 1, now])
);

processBatch(levels, timestamps) 将电平和毫秒时间戳按下标配对,按输入顺序逐点应用与 process() 相同的缓存和统计规则,处理完成后只调用一次 onLevelStreamUpdate。空批次不回调,数组长度不一致时抛出 RangeError 且不写入数据。单点仍可使用 process(level, timestamp)。

License

MIT