#fft #ndarray #rustfft #realfft #rustdct

ndrustfft

N-dimensional FFT, real-to-complex FFT and real-to-real DCT

10 releases

0.5.0 Aug 18, 2024
0.4.5 Jun 27, 2024
0.4.4 Apr 17, 2024
0.4.2 Oct 28, 2023
0.1.4 Jul 30, 2021

#46 in Math

Download history 380/week @ 2024-07-24 570/week @ 2024-07-31 3783/week @ 2024-08-07 2912/week @ 2024-08-14 2605/week @ 2024-08-21 1958/week @ 2024-08-28 1462/week @ 2024-09-04 1224/week @ 2024-09-11 463/week @ 2024-09-18 803/week @ 2024-09-25 4030/week @ 2024-10-02 3586/week @ 2024-10-09 3297/week @ 2024-10-16 3305/week @ 2024-10-23 3616/week @ 2024-10-30 1807/week @ 2024-11-06

12,705 downloads per month
Used in 11 crates (5 directly)

MIT license

52KB
905 lines

ndrustfft

ndrustfft: n-dimensional complex-to-complex FFT, real-to-complex FFT and real-to-real DCT

This library is a wrapper for RustFFT, RustDCT and RealFft that enables performing FFTs and DCTs of complex- and real-valued data on n-dimensional arrays (ndarray).

ndrustfft provides Handler structs for FFT's and DCTs, which must be provided alongside with the arrays to the respective functions (see below) . The Handlers implement a process function, which is a wrapper around Rustfft's process. Transforms along the outermost axis are in general the fastest, while transforms along other axis' will temporarily create copies of the input array.

Parallel

The library ships all functions with a parallel version which leverages the parallel iterators of the ndarray crate.

Available transforms

Complex-to-complex

Real-to-complex

Complex-to-real

Real-to-real

Example

2-Dimensional real-to-complex fft along first axis

use ndarray::{Array2, Dim, Ix};
use ndrustfft::{ndfft_r2c, Complex, R2cFftHandler};

let (nx, ny) = (6, 4);
let mut data = Array2::<f64>::zeros((nx, ny));
let mut vhat = Array2::<Complex<f64>>::zeros((nx / 2 + 1, ny));
for (i, v) in data.iter_mut().enumerate() {
    *v = i as f64;
}
let mut fft_handler = R2cFftHandler::<f64>::new(nx);
ndfft_r2c(
    &data.view(),
    &mut vhat.view_mut(),
    &mut fft_handler,
    0,
);

Normalization

RustFFT, RustDCT and RealFft do not normalise, while this library applies normalization as scipy by default. This means, inverse ffts are divided by a factor of data.len(), and dcts are multiplied by two. It is possible to switch from the default normalization to no normalization, or to apply a custom normalization by using the normalization builder.

See: examples/fft_norm

Features

  • parallel: Enables parallel transform using ndarrays + rayon (enabled by default)
  • avx: Enables rustfft's avx feature (enabled by default)
  • sse: Enables rustfft's sse feature (enabled by default)
  • neon: Enables rustfft's neon feature (enabled by default)

Documentation

docs.rs

Versions

Changelog

License: MIT

Dependencies

~4.5MB
~88K SLoC