embedded-dsp
A #![no_std] Rust Digital Signal Processing library designed for microcontrollers (Cortex-M, RISC-V, AVR, Xtensa), embedded systems, real-time signal processing, and TinyML applications.
Features
#![no_std]First: Purecorecompatibility for bare-metal targets with zero dynamic allocation required.libm,defmt, &serdeIntegrations: Optional formatting logs viadefmt, model serialization viaserde, and floating-point math routines in#![no_std]environments vialibm.- Fixed-Point & Floating-Point: Complete support for
f32,f64,q31,q15,q7, andq63saturating arithmetic. - 23 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,tan,sin_cos,sqrt,vsqrt,divide,log,log10,exp,atan2. - Filtering: FIR filters, Biquad IIR cascade, LMS adaptive filters, 1D convolution & correlation, FFT fast convolution, 1D conditional/thresholded median filters (
f32,q15,q31), single-pole recursive low/high-pass filters (SinglePoleFilter), O(1) recursive moving average (RecursiveMovingAverage<N>), and const-generic real-timeCircularBuffer<T, N>. - Filter Design: Biquad Low-Pass, High-Pass, Band-Pass, Notch, Peaking EQ, All-Pass, multi-stage Butterworth design, multi-stage Chebyshev Low-Pass/High-Pass design, continuous-to-discrete Bilinear Transform with cutoff frequency pre-warping, Windowed-Sinc FIR design (Low-pass, High-pass, Band-pass, Band-stop), and arbitrary-response FIR design via frequency sampling (
fir_custom_frequency_sampling). - Audio & TinyML: Goertzel single-frequency detector (
GoertzelDetector), peak/RMS envelope followers (PeakEnvelopeFollower/RmsEnvelopeFollower), Mel filterbank (mel_filterbank_f32), and MFCC feature extraction (mfcc_f32). - Spectral Analysis & PSD: Welch's method power spectral density estimation (averaged periodograms), single-segment periodograms in linear and dB scale.
- Spatial & 2D Signal Processing: 2D DCT-II / IDCT-II, 2D spatial convolution with normalization, 2D non-linear filtering (Min/Max/Median), Sobel edge detection, 2D histogram binning, MSE, and PSNR.
- Resampling & Multi-rate: Cascaded Integrator-Comb (CIC) Decimator & Interpolator, linear fractional resampler, spectral 2:1 sinc zero-padding interpolation.
- Kalman Filtering: 1D/2D helpers, const-generic linear
KalmanFilter<N, M>, and trait-based Extended Kalman Filter (EkfModel), with_with_inputvariants for models driven by an exogenous input outside the state. - Const Generics: Compile-time fixed-size
FirFilter<N>,BiquadCascade<COEFFS, STATE>, andMatrix<R, C, N>. - Transforms: In-place Complex FFT (
cfft), Real FFT (rfft), Discrete Cosine Transform (dct4), Fast Walsh-Hadamard Transform (fwht_f32/fwht_i32), Fixed-Point FFT (cfft_q15/cfft_q31), Haar Transform (haar_transform_f32/haar_transform_i32), self-inverse Hartley Transform (hartley_transform_f32), and a generalized wavelet transform (wavelet_transform_f32with the built-in Daubechies-4 filter). - Matrix & Regression: Matrix addition, subtraction, multiplication, scaling, transpose, Gauss-Jordan inversion, and weighted polynomial least-squares curve fitting.
- Controller: PID motor controller, Clarke and Park transforms.
- Statistics: Mean, variance, standard deviation, RMS, power, min/max, entropy, KL divergence, logsumexp.
- Support, PRNG & Noise: Array copy/fill, zero-allocation sorting (
sort_f32), format conversions (q15↔f32↔q31), XorShift64 PRNG, uniform and Box-Muller Gaussian noise generators. - Interpolation: Linear, Bilinear, and Cubic Spline interpolation.
- Quaternions: Norm, normalization, quaternion product, conjugate, inverse, rotation matrix conversion.
- Window Functions: Hanning, Hamming, Blackman, 4-term Blackman-Harris, 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). - Filter Analysis: FIR/biquad-cascade frequency response (DTFT) evaluation, magnitude/phase/dB helpers, FIR group delay, and pole-based IIR stability checks.
- Companding: µ-law and "A"-law audio companding (
mu_law_compress_f32/mu_law_expand_f32,a_law_compress_f32/a_law_expand_f32), the ITU-T G.711-family nonlinear compression curves.
- Basic Math: Elementwise
Quick Start
Add embedded-dsp to your Cargo.toml:
[]
# For bare-metal #![no_std] environments with libm
= { = "0.3.0", = false, = ["libm"] }
# For standard std environments
= "0.3.0"
Basic Example
use *;
Running Included Examples
# Run basic usage example
# Run performance comparison benchmark (libm vs embedded-dsp)
License
The 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.