dsp

    A lightweight digital signal processing and spectrum analysis library for MoonBit

    dsp
    fft
    filter
    signal-processing
    embedded
    Download zip
    Author
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    45

    No dependencies

    #MoonBit DSP

    MoonBit-native digital signal processing for sensor, audio, control, and embedded/Wasm-oriented workloads. The library provides reusable numerical building blocks, streaming filters, spectral analysis, and domain-focused diagnostics without requiring a foreign runtime.

    #What it provides

    • Complex numbers, matrices, polynomials, Q15/Q31 fixed-point helpers, and special functions.
    • Radix-2/Radix-4 FFT, Bluestein FFT, RFFT, DCT, CZT, STFT, 2D FFT, and spectrum metrics.
    • Window functions with coherent-gain and ENBW helpers.
    • IIR and FIR design/runtime filters, including Butterworth, Chebyshev, Bessel, biquad, Hilbert, and Remez components.
    • Adaptive filters and trackers: LMS/NLMS, RLS, Kalman, EKF, UKF, particle filtering, and alpha-beta variants.
    • Signal utilities such as correlation, resampling, wavelets, pitch, DTMF, peak detection, envelope extraction, Welch PSD, and zero-crossing analysis.
    • Domain packages for audio, speech, image, radar, sonar, spatial audio, telecom, power, biomedical, vibration, and control processing.
    • Fixed-capacity streaming primitives and a frame analyzer that reports RMS, peak, dominant frequency, and spectral centroid.

    The implementation is intentionally split into focused packages so applications can depend on only the algorithms they use.

    #Repository layout

    moonbit-dsp/ ├── moon.mod ├── LICENSE ├── README.md / README_CN.md ├── .github/workflows/test.yml ├── docs/benchmarks.md ├── examples/ └── src/ ├── math/ window/ fft/ ├── filter/{iir,iir_advanced,fir,adaptive,statistical}/ ├── signal/ signal_ext/ spectral_estimation/ ├── dsp_core/ dsp_utils/ streaming/ ├── matrix_ext/ modal_analysis/ quantization/ ├── audio_dsp/ bio_dsp/ control_dsp/ image_dsp/ ├── power_dsp/ radar_dsp/ sonar_dsp/ spatial_audio/ ├── speech_dsp/ telecom_dsp/ vibration_dsp/ └── dsp_bench/ dsp_benchmark/

    #Installation

    The module name is hwlxmm/dsp. Add the packages you need to your consumer package's moon.pkg:

    import {
    "hwlxmm/dsp/src/filter/iir" @iir,
    "hwlxmm/dsp/src/fft" @fft,
    "hwlxmm/dsp/src/window" @window,
    }

    moon.mod declares module metadata and external dependencies; package imports belong in moon.pkg.

    #Minimal example

    fn main {
    let sample_rate = 1000.0
    let cutoff = 50.0
    let coeffs = @iir.butterworth_biquad_lowpass(cutoff, sample_rate)
    let filter = @iir.BiquadCascade::new([coeffs])
    let filtered = filter.process_sample(1.25)
    println("filtered sample = \{filtered}")
    }

    For spectral analysis, use @fft.rfft with a power-of-two input and a window generated by @window.WindowType.

    #Examples

    Run examples with the native backend:

    moon run --target native examples/sensor_filter_demo moon run --target native examples/fft_spectrum_demo moon run --target native examples/kalman_tracker_demo moon run --target native examples/spectrogram_demo moon run --target native examples/ukf_tracker_demo moon run --target native examples/vibration_monitor_demo moon run --target native --release examples/benchmark_demo

    The vibration demo combines time-domain indicators, an envelope spectrum, and the streaming frame analyzer. Benchmark methodology and measured local data are documented in docs/benchmarks.md.

    #Quality checks

    The repository CI checks all supported MoonBit targets on Linux, macOS, and Windows, and runs a native test job. The same checks can be run locally:

    moon version --all moon update moon fmt --check moon check --deny-warn moon check --target all moon test --deny-warn moon test --deny-warn --target all moon test --deny-warn --target native moon info

    moon info generates the package interface summaries (pkg.generated.mbti). Review those files when public APIs change; do not edit them by hand.

    #Compatibility and scope

    The primary development and verification backend is native. The library is also checked for MoonBit's wasm, wasm-gc, and js targets where the selected APIs support them. Native-only runtime behavior should be kept in executable examples or explicitly target-restricted packages.

    Streaming APIs use fixed-capacity buffers for sample ingestion. Frame-level analysis creates owned arrays when a complete frame is emitted; this is distinct from claiming that every frame calculation is allocation-free.

    #License

    MoonBit DSP is distributed under the Apache License 2.0.