| Crates.io | cross_correlate |
| lib.rs | cross_correlate |
| version | 0.2.0 |
| created_at | 2025-09-26 09:50:13.595446+00 |
| updated_at | 2025-11-27 20:27:57.128056+00 |
| description | Signal cross-correlation |
| homepage | https://github.com/awxkee/cross-correlate |
| repository | https://github.com/awxkee/cross-correlate.git |
| max_upload_size | |
| id | 1855706 |
| size | 141,465 |
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
at your option.