百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

spectrum-analyzer

> 编程语言
开源

一个易于使用且快速的 `no_std` 库 (带有 `alloc`),用于使用 FFT 来获取数字信号 (例如音频) 的频率频谱。

174 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个易于使用且快速的 `no_std` 库 (带有 `alloc`),用于使用 FFT 来获取数字信号 (例如音频) 的频率频谱。

Rust: library for frequency spectrum analysis using FFT

An easy to use and fast no_std library (with alloc) to get the frequency spectrum of a digital signal (e.g. audio) using FFT.

Supported Platforms

The base library supports all standard and non-standard targets: Linux, macOS, and Windows, but also embedded systems running custom software.

I want to understand how FFT can be used to get a spectrum

Please see file /EDUCATIONAL.md.

How to use (including no_std-contexts)

The crate is no_std and only needs alloc, so there is no feature to enable and nothing to turn off. The most basic usage looks like this:

Cargo.toml

toml
[dependencies]
spectrum-analyzer = ""

your_binary.rs

…

Which settings should I use?

The example above is a good default: a Hann window, divide_by_N, and a block of 2048 samples. Which window and which scaling function to pick, how many samples to use, and what the resulting values mean is documented in the crate documentation, including the windows and scaling modules.

Performance

I've tested multiple FFT implementations and settled on microfft::real. It was not only the fastest, but is also the only one that works in no_std contexts.

Run cargo bench for numbers on your machine.

Example Visualizations

In the following examples you can see a basic visualization of the spectrum from 0 to 4000Hz for a layered signal of sine waves of 50, 1000, and 3777Hz @ 44100Hz sampling rate. The peaks for the given frequencies are clearly visible. Each calculation was done with 2048 samples, i.e. ≈46ms of audio signal.

Spectrum without window function on samples

Peaks (50, 1000, 3777 Hz) are clearly visible but also some noise. are clearly visible but also some noise.")

Spectrum with Hann window function on samples before FFT

Peaks (50, 1000, 3777 Hz) are clearly visible and Hann window reduces noise a little. Because this example has little noise, you don't see much difference. are clearly visible and Hann window reduces noise a little bit. Because this example has few noise, you don't see much difference.")

Live Audio + Spectrum Visualization

Execute example $ cargo run --release --example live-visualization. It will show you how you can visualize audio data in realtime + the current spectrum.

Building and Executing Tests

Tests and examples pull in audio-visualizer, which needs native libraries for audio input and for the window of the live example. On Ubuntu/Debian these are libasound2-dev, libgl1-mesa-dev, libx11-dev, libxcursor-dev, libxi-dev, libxkbcommon-dev, libxrandr-dev, and libwayland-dev. The flake.nix in this repository provides the same set.

Note that not all tests are "automatic unit tests" but also tests that you need to check visually, by looking at the generated diagram of the spectrum.

MSRV

The MSRV (minimum supported Rust version) of the library is 1.85.1. To run benchmarks, tests, and examples you may need a more recent version.

Trivia / FAQ

Why f32 and not f64?

I tested f64 but the additional accuracy doesn't pay out the ~40% calculation overhead (on x86_64).

What can I do against the noise?

Apply a window function. The windows module documents which one to pick.

Good resources with more information

  • Interpreting FFT Results:
  • FFT basic concepts:
  • „The Fundamentals of FFT-Based Signal Analysis and Measurement“
  • Fast Fourier Transforms (FFTs) and Windowing:

Also check out my blog post.

License

MIT, see LICENSE.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言