Skip to main content

rfft

Function rfft 

pub fn rfft<const D: usize>(
    signal: Tensor<D>,
    dim: impl AsIndex,
    n: Option<usize>,
) -> (Tensor<D>, Tensor<D>)
Expand description

Computes the 1-dimensional discrete Fourier Transform of real-valued input.

Since the input is real, the Hermitian symmetry is exploited, and only the first non-redundant values are returned ($N/2 + 1$). Autodiff is supported when the autodiff feature is enabled.

X[k] = Σ x[n] * exp(-i*2πkn/N)

§Arguments

  • signal - The input tensor containing the real-valued signal.
  • dim - The dimension along which to take the FFT. Negative dimensions are supported and count from the end.
  • n - Optional FFT length. When None, the signal must be a power of two along dim. When Some(n), n must also be a power of two; the signal is truncated or zero-padded to length n. Non-power-of-two n is rejected with a panic (true arbitrary-size DFT support via Bluestein’s algorithm is tracked as a follow-up).

§Returns

A tuple containing:

  1. The real part of the spectrum. Output length along dim is n / 2 + 1 (using n or signal_len respectively).
  2. The imaginary part of the spectrum (same shape).

§Example

use burn_core::tensor::Tensor;

let device = Default::default();
let signal = Tensor::<1>::from_floats([1.0, 2.0, 3.0, 4.0], &device);
let (real, imag) = burn_signal::rfft(signal, 0, None);