cross_correlate

Crates.iocross_correlate
lib.rscross_correlate
version0.2.0
created_at2025-09-26 09:50:13.595446+00
updated_at2025-11-27 20:27:57.128056+00
descriptionSignal cross-correlation
homepagehttps://github.com/awxkee/cross-correlate
repositoryhttps://github.com/awxkee/cross-correlate.git
max_upload_size
id1855706
size141,465
Radzivon Bartoshyk (awxkee)

documentation

https://github.com/awxkee/cross-correlate

README

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.

Commit count: 0

cargo fmt