rfft

Function rfft 

pub fn rfft<B, const D: usize>(
    signal: Tensor<B, D>,
    dim: usize,
    n: Option<usize>,
) -> (Tensor<B, D>, Tensor<B, D>)
where B: Backend,
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$). For now, the autodiff is not yet supported

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.
  • 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_tensor::backend::Backend;
use burn_tensor::Tensor;

fn example<B: Backend>() {
    let device = B::Device::default();
    let signal = Tensor::<B, 1>::from_floats([1.0, 2.0, 3.0, 4.0], &device);
    let (real, imag) = burn_tensor::signal::rfft(signal, 0, None);
}