A #![no_std] Rust Digital Signal Processing library designed for microcontrollers (Cortex-M, RISC-V, AVR, Xtensa), embedded systems, and real-time digital signal processing applications.
#![no_std]First: Purecorecompatibility for bare-metal targets with zero dynamic allocation required.libmIntegration: UnifiedFloatMathtrait providing floating-point math routines in#![no_std]environments vialibm.- Fixed-Point & Floating-Point: Complete support for
f32,f64,q31,q15,q7, andq63saturating arithmetic. - 16 Core DSP Modules:
- Basic Math: Elementwise
add,sub,mult,negate,offset,scale,shift,dot_prod,clip, bitwise operations. - Complex Math: Complex vector addition, multiplication, magnitude, conjugate, dot product.
- Fast Math: Trigonometric
sin,cos,sin_cos,sqrt,vsqrt,divide,log,exp,atan2. - Filtering: FIR filters, Biquad IIR cascade, LMS adaptive filters, 1D convolution & correlation.
- Transforms: In-place Complex FFT (
cfft), Real FFT (rfft), Discrete Cosine Transform (dct4). - Matrix Operations: Matrix addition, subtraction, multiplication, scaling, transpose, Gauss-Jordan inversion.
- Controller: PID motor controller, Clarke and Park transforms.
- Statistics: Mean, variance, standard deviation, RMS, power, min/max, entropy, KL divergence, logsumexp.
- Support & Conversions: Array copy/fill, zero-allocation sorting (
sort_f32), format conversions (q15↔f32↔q31). - Interpolation: Linear, Bilinear, and Cubic Spline interpolation.
- Quaternions: Norm, normalization, quaternion product, conjugate, inverse, rotation matrix conversion.
- Window Functions: Hanning, Hamming, Blackman, Bartlett, Welch, Flat-top generators.
- Distance Metrics: Euclidean, Cosine, Chebyshev, Manhattan, Minkowski, Jaccard, Hamming, Canberra, Bray-Curtis.
- Machine Learning: Support Vector Machine (
SvmInstanceF32) and Gaussian Naive Bayes (GaussianNaiveBayesInstanceF32).
- Basic Math: Elementwise
Add embedded-dsp to your Cargo.toml:
[dependencies]
# For bare-metal #![no_std] environments with libm
embedded-dsp = { version = "0.1", default-features = false, features = ["libm"] }
# For standard std environments
embedded-dsp = "0.1"use embedded_dsp::*;
fn main() {
// 1. Vector Operations
let a = [1.0f32, 2.0, 3.0, 4.0];
let b = [10.0f32, 20.0, 30.0, 40.0];
let mut vec_out = [0.0f32; 4];
add_f32(&a, &b, &mut vec_out);
// 2. Q15 Fixed-Point Saturating Addition
let q15_a = [20000i16, 25000];
let q15_b = [15000i16, 10000];
let mut q15_out = [0i16; 2];
add_q15(&q15_a, &q15_b, &mut q15_out); // Output: [32767, 32767] (clamped at i16::MAX)
// 3. 64-Point Complex FFT
let mut fft_data = [0.0f32; 128]; // 64 complex pairs [re, im, ...]
cfft_f32(&mut fft_data, 64, 0, 1);
}# Run basic usage example
cargo run --example basic_usage
# Run performance comparison benchmark (libm vs embedded-dsp)
cargo run --release --example perf_comparisonThe contents of this repository are dual-licensed under the MIT OR Apache 2.0
License. That means you can choose either the MIT license or the Apache 2.0
license when you re-use this code. See LICENSE, LICENSE-MIT, or
LICENSE-APACHE for more information on each specific
license.