20 releases

Uses new Rust 2024

0.2.7 Dec 20, 2025
0.2.6 Dec 14, 2025
0.2.1 Nov 27, 2025
0.1.11 Nov 19, 2025
0.1.7 Oct 29, 2025

#494 in Algorithms

Download history 154/week @ 2025-10-12 330/week @ 2025-10-19 336/week @ 2025-10-26 101/week @ 2025-11-02 14/week @ 2025-11-09 4/week @ 2025-11-16 124/week @ 2025-11-23 141/week @ 2025-11-30 69/week @ 2025-12-07 232/week @ 2025-12-14 67/week @ 2025-12-21 3/week @ 2025-12-28 20/week @ 2026-01-04 176/week @ 2026-01-11

270 downloads per month
Used in 4 crates

BSD-3-Clause OR Apache-2.0

5.5MB
106K SLoC

Zaft FFT Example

This example demonstrates how to perform real-to-complex (R2C) and complex-to-real (C2R) FFTs, as well as standard complex-to-complex forward and inverse FFTs using Zaft.

Real-to-Complex (R2C) and Complex-to-Real (C2R)

use zaft::Zaft;
use num_complex::Complex;

fn main() -> Result<(), zaft::ZaftError> {
    // Example real input data
    let mut real_data: Vec<f32> = vec![0.0; 1024];

    // Create R2C and C2R FFT executors
    let forward_r2c = Zaft::make_r2c_fft_f32(real_data.len())?;
    let inverse_r2c = Zaft::make_c2r_fft_f32(real_data.len())?;

    // Prepare buffer for complex output
    let mut complex_data = vec![Complex::<f32>::default(); real_data.len() / 2 + 1];

    // Perform forward R2C FFT
    forward_r2c.execute(&real_data, &mut complex_data)?;

    // Perform inverse C2R FFT
    inverse_r2c.execute(&complex_data, &mut real_data)?;

    Ok(())
}

Note: After the round-trip, real_data will approximately equal its original values (within floating-point precision).

Complex-to-Complex FFT

use zaft::Zaft;
use num_complex::Complex;

fn main() -> Result<(), zaft::ZaftError> {
    // Example complex input
    let mut data: Vec<Complex<f32>> = vec![Complex::new(0.0, 0.0); 1024];

    // Create forward and inverse complex FFT executors
    let forward = Zaft::make_forward_fft_f32(data.len())?;
    let inverse = Zaft::make_inverse_fft_f32(data.len())?;

    // Perform forward FFT
    forward.execute(&mut data)?;

    // Perform inverse FFT
    inverse.execute(&mut data)?;

    Ok(())
}

Notes

R2C FFTs only store the non-redundant half of the spectrum: the length of the complex buffer is (real_len / 2 + 1).

C2R FFTs require the same shape of complex input and reconstruct the full real output.

Complex-to-complex FFTs operate in-place and maintain the full length of the data.


This project is licensed under either of

  • BSD-3-Clause License (see LICENSE)
  • Apache License, Version 2.0 (see LICENSE)

at your option.

Dependencies

~4.5MB
~86K SLoC