#fft #dft #discrete #fourier #transform


Real-to-complex FFT and complex-to-real iFFT for Rust

4 releases (2 breaking)

0.3.0 Oct 10, 2020
0.2.1 Jul 22, 2020
0.2.0 Jun 25, 2020
0.1.0 Jun 17, 2020

#11 in Encoding

Download history 97/week @ 2020-08-15 17/week @ 2020-08-22 47/week @ 2020-08-29 63/week @ 2020-09-05 66/week @ 2020-09-12 119/week @ 2020-09-19 51/week @ 2020-09-26 87/week @ 2020-10-03 89/week @ 2020-10-10 143/week @ 2020-10-17 153/week @ 2020-10-24 195/week @ 2020-10-31 204/week @ 2020-11-07 157/week @ 2020-11-14 96/week @ 2020-11-21 152/week @ 2020-11-28

266 downloads per month
Used in 4 crates (via rubato)

MIT license

294 lines


Real-to-complex FFT and complex-to-real iFFT based on RustFFT

This library is a wrapper for RustFFT that enables faster computations when the input data is real. It packs a 2N long real vector into an N long complex vector, which is transformed using a standard FFT. It then post-processes the result to give only the first half of the complex spectrum, as an N+1 long complex vector.

The iFFT goes through the same steps backwards, to transform an N+1 long complex spectrum to a 2N long real result.

The speed increase compared to just converting the input to a 2N long complex vector and using a 2N long FFT depends on the length f the input data. The largest improvements are for long FFTs and for lengths over around 1000 elements there is an improvement of about a factor 2. The difference shrinks for shorter lengths, and around 100 elements there is no longer any difference.


The full documentation can be generated by rustdoc. To generate and view it run:

cargo doc --open


To run a set of benchmarks comparing real-to-complex FFT with standard complex-to-complex, type:

cargo bench

The results are printed while running, and are compiled into an html report containing much more details. To view, open target/criterion/report/index.html in a browser.


Transform a vector, and then inverse transform the result.

use realfft::{ComplexToReal, RealToComplex};
use rustfft::num_complex::Complex;
use rustfft::num_traits::Zero;

// make dummy input vector, spectrum and output vectors
let mut indata = vec![0.0f64; 256];
let mut spectrum: Vec<Complex<f64>> = vec![Complex::zero(); 129];
let mut outdata: Vec<f64> = vec![0.0; 256];

//create an FFT and forward transform the input data
let mut r2c = RealToComplex::<f64>::new(256).unwrap();
r2c.process(&mut indata, &mut spectrum).unwrap();

// create an iFFT and inverse transform the spectum
let mut c2r = ComplexToReal::<f64>::new(256).unwrap();
c2r.process(&spectrum, &mut outdata).unwrap();


The realfft crate requires rustc version 1.34 or newer.

License: MIT