nufft_type2

Function nufft_type2 

Source
pub fn nufft_type2(
    spectrum: &[Complex64],
    x: &[f64],
    interp_type: InterpolationType,
    epsilon: f64,
) -> FFTResult<Vec<Complex64>>
Expand description

Performs Non-Uniform Fast Fourier Transform (NUFFT) Type 2.

This function computes the FFT from a uniform grid to non-uniform frequencies. NUFFT Type 2 is essentially the adjoint of Type 1.

§Arguments

  • spectrum - Input spectrum on a uniform grid
  • x - Non-uniform frequency points where output is desired (must be in [-π, π])
  • interp_type - Interpolation type to use
  • epsilon - Desired precision (typically 1e-6 to 1e-12)

§Returns

  • A complex-valued array containing the NUFFT at the specified non-uniform points

§Errors

Returns an error if the computation fails or inputs are invalid.

§Examples

use scirs2_fft::nufft::{nufft_type2, InterpolationType};
use scirs2_core::numeric::Complex64;
use std::f64::consts::PI;

// Create a spectrum on a uniform grid
let m = 128;
let spectrum: Vec<Complex64> = (0..m)
    .map(|i| {
        // Simple Gaussian in frequency domain
        let f = i as f64 - m as f64 / 2.0;
        let val = (-f * f / (2.0 * 10.0)).exp();
        Complex64::new(val, 0.0)
    })
    .collect();

// Define non-uniform points where we want to evaluate the transform
// Ensure all points are in the range [-π, π]
let n = 100;
let x: Vec<f64> = (0..n).map(|i| -PI + 1.99 * PI * i as f64 / (n as f64 - 1.0)).collect();

// Compute NUFFT Type 2
let result = nufft_type2(&spectrum, &x, InterpolationType::Gaussian, 1e-6).unwrap();

// The output should have the same length as the non-uniform points
assert_eq!(result.len(), x.len());

§Notes

This is a basic implementation. For performance-critical applications, consider using a more optimized NUFFT library.