Skip to main content

embedded_dsp/
lib.rs

1#![no_std]
2#![allow(missing_docs)]
3
4//! # embedded-dsp
5//!
6//! A `#![no_std]` Rust digital signal processing library for microcontrollers, embedded systems, and real-time signal processing applications.
7//!
8//! Algorithm modules are Cargo-feature gated (all enabled by the `full` feature, which is
9//! in `default`). `types` and `math` are always available. See the crate's `[features]`
10//! table for the per-module flags.
11//!
12//! ## Overview
13//!
14//! `embedded-dsp` provides zero-allocation digital signal processing algorithms:
15//!
16//! - **Basic Math**: Elementwise addition, subtraction, multiplication, dot product, scale, shift, clip, logic ops.
17//! - **Complex Math**: Complex vector addition, multiplication, magnitude, magnitude squared, conjugate, dot product.
18//! - **Fast Math**: Trigonometric (sin, cos, atan2), square root, division, log, exp.
19//! - **Fixed-Point (Q16.16)**: Saturating Q16.16 arithmetic and scanline interpolation (`fixed-point` feature).
20//! - **LUT trigonometry**: Compile-time 256-entry sin/cos tables (`lut` feature).
21//! - **Statistics**: Mean, variance, standard deviation, RMS, power, min/max, entropy, Kullback-Leibler, LogSumExp.
22//! - **Support**: Vector copy, fill, type conversions (Q7, Q15, Q31, F32), sort, barycenter, weighted sum.
23//! - **Matrix**: Matrix addition, subtraction, multiplication, scale, transpose, Gauss-Jordan inverse.
24//! - **Filtering**: FIR, Biquad IIR Direct Form I and transposed DF-II (f32/q15/q31), LMS / leaky LMS / NLMS, Convolution, Correlation, single-pole recursive filters (f32/q15), Q15 DC blocker, O(1) recursive moving average, and a double-sampled State Variable Filter (simultaneous LP/HP/BP/notch/peak, sweepable cutoff/resonance).
25//! - **Filter Design**: Biquad Lowpass, Highpass, Bandpass, Notch, Peaking EQ, Allpass, Butterworth, Chebyshev, and arbitrary-response (frequency-sampling) design.
26//! - **Filter Analysis**: Frequency response (DTFT) evaluation for FIR/biquad filters, FIR group delay, and pole-based IIR stability checks.
27//! - **Resampling & Multi-rate**: CIC Decimator & Interpolator, linear fractional resampler.
28//! - **Kalman Filtering**: 1D/2D helpers, const-generic linear `KalmanFilter<N, M>`, and trait-based `ExtendedKalmanFilter` (EKF).
29//! - **Const Generics**: Compile-time fixed-size `FirFilter<N>`, `FirFilterQ15<N>`, `BiquadCascade<N>`, `BiquadCascadeQ15`, and `Matrix<R, C>`.
30//! - **Transform**: In-place Complex FFT (CFFT), packed Real FFT / inverse (`rfft_q15`/`irfft_q15`), DCT-IV, Bit reversal, Fixed-point FFT (Q15/Q31), Haar transform, Hartley transform, and a generalized wavelet transform (Daubechies-4).
31//! - **Companding**: ยต-law and A-law curves plus ITU-T G.711 `u8` encode/decode.
32//! - **Audio**: Goertzel single-frequency detector (f32/q15), peak/RMS envelope followers (f32/q15), Mel filterbank, and MFCC feature extraction.
33//! - **Spectral Analysis & PSD**: Welch's method power spectral density estimation (averaged periodograms), single-segment periodograms in linear and dB scale.
34//! - **Spatial & 2D Signal Processing**: 2D DCT/IDCT, 2D Convolution, 2D Non-linear Filtering (Min/Max/Median), Sobel edge detection, 2D Histogram, MSE, PSNR.
35//! - **Controller**: PID motor controller, Clarke/Park (f32 and q15).
36//! - **Interpolation**: Linear, Bilinear, Cubic spline interpolation.
37//! - **Quaternion**: Norm, normalization, product, conjugate, inverse, rotation matrix conversion, and `nalgebra` interop (`nalgebra` feature).
38//! - **Window**: Hanning, Hamming, Blackman, Blackman-Harris, Bartlett, Welch, Flat-top generators (f32), plus Q15 Hanning/Hamming/Blackman/Bartlett.
39//! - **Distance**: Euclidean, Cosine, Chebyshev, Manhattan, Minkowski, Jaccard, Hamming, Canberra, Bray-Curtis.
40
41#[cfg(feature = "std")]
42extern crate std;
43
44macro_rules! gated_mod {
45    ($feature:literal, $module:ident) => {
46        #[cfg(feature = $feature)]
47        pub mod $module;
48        #[cfg(feature = $feature)]
49        pub use $module::*;
50    };
51    (math $feature:literal, $module:ident) => {
52        #[cfg(all(feature = $feature, any(feature = "std", feature = "libm")))]
53        pub mod $module;
54        #[cfg(all(feature = $feature, any(feature = "std", feature = "libm")))]
55        pub use $module::*;
56    };
57}
58
59gated_mod!(math "audio", audio);
60gated_mod!("basic-math", basic_math);
61gated_mod!(math "beamforming", beamforming);
62gated_mod!("companding", companding);
63gated_mod!("complex-math", complex_math);
64gated_mod!("const-generics", const_generics);
65gated_mod!("controller", controller);
66gated_mod!("cordic", cordic);
67gated_mod!("distance", distance);
68gated_mod!(math "dynamics", dynamics);
69gated_mod!("fast-math", fast_math);
70gated_mod!(math "filter-analysis", filter_analysis);
71gated_mod!(math "filter-design", filter_design);
72gated_mod!("filtering", filtering);
73gated_mod!("fixed-point", fixed_point);
74gated_mod!("interpolation", interpolation);
75gated_mod!("kalman", kalman);
76gated_mod!("lut", lut);
77pub mod math;
78gated_mod!("matrix", matrix);
79gated_mod!("nalgebra", nalgebra_interop);
80gated_mod!("pipeline", pipeline);
81gated_mod!(math "pll", pll);
82gated_mod!("psd", psd);
83gated_mod!("quaternion", quaternion);
84gated_mod!("resampling", resampling);
85gated_mod!("spatial", spatial);
86gated_mod!("statistics", statistics);
87gated_mod!(math "filtering", svf);
88gated_mod!("support", support);
89gated_mod!("transform", transform);
90pub mod intrinsics;
91pub mod types;
92gated_mod!("window", window);
93
94pub use intrinsics::*;
95pub use math::*;
96pub use types::*;