#dsp #signal

cross_correlate

Signal cross-correlation

7 releases

Uses new Rust 2024

0.2.0 Nov 27, 2025
0.1.5 Nov 6, 2025
0.1.4 Oct 14, 2025
0.1.3 Sep 29, 2025

#1261 in Algorithms

BSD-3-Clause OR Apache-2.0

130KB
2K SLoC

A Rust library for computing cross-correlation of signals using FFT. This crate is useful in signal processing, pattern matching, and time-series analysis where cross-correlation is a common operation.

It supports multiple correlation modes (Full, Same, Valid) and allows different FFT backends.

Performance Uses FFT-based convolution for O(n log n) performance. Reuses FFT plans to avoid repeated allocations and planning overhead. SIMD-friendly design (with optional optimizations for AVX2/NEON).

 let mut src = vec![
        5.12f32, 6.2136, 7.2387, 1.52312, 2.52313, 3.52313, 4.52313, 5.23871,
];
let dst = vec![0.31421, 0.421, 0.653, 0.121];

let mode = CrossCorrelationMode::Full;

// determine FFT size.
let fft_size = mode.fft_size(&src, &dst);

let mut planner = FftPlanner::<f32>::new();
let fft_forward = planner.plan_fft_forward(fft_size);
let fft_inverse = planner.plan_fft_inverse(fft_size);

struct FftCorrelate {
    executor: Arc<dyn Fft<f32>>,
}

impl FftExecutor<f32> for FftCorrelate {
    fn process(&self, in_out: &mut [Complex<f32>]) -> Result<(), CrossCorrelateError> {
        self.executor.process(in_out);
        Ok(())
    }

    fn length(&self) -> usize {
        self.executor.len()
    }
}

// create correlation executor
let correlation = Correlate::create_real_f32(
    mode,
    Box::new(FftCorrelate {
        executor: fft_forward,
    }),
    Box::new(FftCorrelate {
        executor: fft_inverse,
    }),
)
.unwrap();
let corr = correlation.correlate_managed(&src, &dst).unwrap();

This project is licensed under either of

  • BSD-3-Clause License (see LICENSE)
  • Apache License, Version 2.0 (see LICENSE)

at your option.

Dependencies

~190–260KB