#fft #ndarray #rustfft #realfft #rustdct

ndrustfft

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

4 releases (2 breaking)

0.3.0 Feb 16, 2022
0.2.1 Sep 1, 2021
0.2.0 Aug 12, 2021
0.1.6 Aug 7, 2021
0.1.4 Jul 30, 2021

#443 in Math

Download history 27/week @ 2022-08-10 24/week @ 2022-08-17 18/week @ 2022-08-24 34/week @ 2022-08-31 48/week @ 2022-09-07 21/week @ 2022-09-14 12/week @ 2022-09-21 37/week @ 2022-09-28 82/week @ 2022-10-05 70/week @ 2022-10-12 31/week @ 2022-10-19 35/week @ 2022-10-26 115/week @ 2022-11-02 167/week @ 2022-11-09 70/week @ 2022-11-16 10/week @ 2022-11-23

364 downloads per month

MIT license

36KB
605 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

  • fft : [ndfft], [ndfft_par]
  • ifft: [ndifft],[ndifft_par]

Real-to-complex

  • fft_r2c : [ndfft_r2c], [ndfft_r2c_par],

Complex-to-real

  • ifft_r2c: [ndifft_r2c],[ndifft_r2c_par]

Real-to-real

  • dct1: [nddct1],[nddct1_par]
  • dct2: [nddct2],[nddct2_par]
  • dct3: [nddct3],[nddct3_par]
  • dct4: [nddct4],[nddct4_par]

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,
);

Versions

  • v0.3.0: Upgrade RealFft to 3.0.0 and RustDCT to 0.7
  • >= v0.2.2:

The first and last elements of real-to-complex transforms are per definition purely real. This is now enforced actively, by setting the complex part to zero - similar to numpys rfft.

License: MIT

Dependencies

~3.5MB
~67K SLoC