#fft #correlation #convolution #signal-processing

fftconvolve

The fast fourier transform convolution and correlation algorithm for Rust

2 releases

0.1.1 Nov 26, 2022
0.1.0 Nov 26, 2022

#1754 in Math

Download history 15/week @ 2024-09-25 8/week @ 2024-10-02 16/week @ 2024-10-09 40/week @ 2024-10-16 18/week @ 2024-10-23 17/week @ 2024-10-30 3/week @ 2024-11-06 7/week @ 2024-11-13 12/week @ 2024-11-20 31/week @ 2024-11-27 21/week @ 2024-12-04 47/week @ 2024-12-11 108/week @ 2024-12-18 8/week @ 2024-12-25 113/week @ 2025-01-01 392/week @ 2025-01-08

624 downloads per month
Used in ndarray-conv

Custom license

18KB
386 lines

fftconvolve

Rust implementations of Fast Fourier Transform convolution and correlation for n-dimensional arrays

Examples

1-dimensional

use fftconvolve::{fftconvolve, Mode}

let in1 = Array1::range(1.0, 4.0, 1.0);
let in2 = Array1::range(6.0, 3.0, -1.0);
let out = fftconvolve(&in1, &in2, Mode::Full).unwrap();
let expected = Array1::<f64>::from_vec(vec![6., 17., 32., 23., 12.]);
out.iter().zip(expected.iter()).for_each(|(a, b)| assert_aclose!(*a, *b, 1e-6));

2-dimensional

use fftconvolve::{fftconvolve, Mode}

let mat = Array2::from_shape_vec((3, 3), 
    vec![
        0.0, 0.0, 0.0,
        0.0, 1.0, 0.0,
        0.0, 0.0, 0.0,
    ]).unwrap();
let kernel = Array2::from_shape_vec((2, 3), 
    vec![
        1., 2., 3., 
        4., 5., 6.,
    ]).unwrap();
let output = fftconvolve(&mat, &kernel, Mode::Full).unwrap();
let expected = Array2::from_shape_vec((4, 5), 
    vec![
        0., 0., 0., 0., 0., 
        0., 1., 2., 3., 0., 
        0., 4., 5., 6., 0.,
        0., 0., 0., 0., 0.,  
    ]).unwrap();
output.iter().zip(expected.iter()).for_each(|(a, b)| assert_aclose!(*a, *b, 1e-6));

Dependencies

~67MB
~882K SLoC