fixed-dsp is a Rust fixed-point DSP library focused on Q15/Q31 algorithms with behavior close to CMSIS-DSP. It also supports differential testing (difftest) against CMSIS C reference implementations.
#![no_std]friendly for embedded targets- Q15/Q31 implementations (
i16/i32) - Modular structure: basic ops, matrix, statistics, complex math, transforms, MFCC
- Optional
difftestfeature: when enabled, compiles selected CMSIS-DSP C sources for differential validation
Located in src/basic.
- Trigonometric functions:
sin_i16/sin_i32,cos_i16/cos_i32 - Multiply and vector ops:
mul_i16/mul_i32,dot_i16/dot_i32 - Scale and shift:
scale_i16/scale_i32,shift_i16/shift_i32 - Offset and log:
offset_i16/offset_i32,vlog_i16/vlog_i32 - Sqrt and division:
sqrt_i16/sqrt_i32,div_i16/div_i32
Located in src/matrix.
Matrix<T>view structmat_add_i16/mat_add_i32mat_mul_i16/mat_mul_i32mat_vec_mul_i16/mat_vec_mul_i32
Located in src/statistics.
absmax_i16/absmax_i32
Located in src/complex.
cmplx_mag_i16/cmplx_mag_i32
Located in src/transform.
- Bit-reversal:
bitreversal_i16/bitreversal_i32 - CFFT:
CfftI16/CfftI32 - RFFT:
RfftI16/RfftI32 - Radix-4 butterfly: forward/inverse Q15/Q31 kernels
- MFCC:
MfccI16/MfccI32
For local workspace development, use a path dependency:
[dependencies]
fixed-dsp = "0.2"use fixed_dsp::basic::sin_i16;
fn main() {
// In Q15, 0x4000 is approximately pi/2.
let x: i16 = 0x4000;
let y = sin_i16(x);
println!("sin_q15 = {}", y);
}use fixed_dsp::transform::CfftI16;
fn main() {
let fft = CfftI16::new(16, false, true);
// Interleaved complex format: [re0, im0, re1, im1, ...]
let mut data = [0i16; 32];
data[0] = 0x4000; // simple impulse
fft.run(&mut data);
}With the difftest feature enabled, build.rs compiles referenced C files under CMSIS-DSP/Source and links them into tests.
cargo test --lib --tests --features difftestNotes:
- Requires a working host C compiler (
cc/clang) - Requires a complete CMSIS-DSP directory
- Without
difftest, integration tests that rely on CMSIS extern symbols are expected to fail at link time
- Provide readable and maintainable fixed-point DSP implementations in Rust
- Continuously validate numerical behavior against CMSIS-DSP through difftest
- Serve as a stable base for embedded deployment and algorithm iteration