Principle:Avhz RustQuant Fast Fourier Transform
| Knowledge Sources | |
|---|---|
| Domains | Numerical_Methods, Signal_Processing |
| Last Updated | 2026-02-07 21:00 GMT |
Overview
The Fast Fourier Transform (FFT) is an efficient algorithm for computing the Discrete Fourier Transform, reducing computational complexity from O(n^2) to O(n log n), with applications in signal processing and option pricing via characteristic functions.
Description
The Fast Fourier Transform implementation in RustQuant provides both real-valued and complex-valued FFT computation using the classic Cooley-Tukey radix-2 decimation-in-time algorithm.
The module exposes four primary functions:
fft_real(x): computes the FFT of a real-valued input vector, returning a new vector of resultsfft_real_inplace(x): computes the FFT of a real-valued vector in place, modifying the inputfft_complex(x): computes the FFT of a complex-valued input vector, returning a new vectorfft_complex_inplace(x): computes the FFT of a complex-valued vector in place
All functions require that the input length be a power of 2, which is validated by the is_valid_length helper function. This constraint arises from the radix-2 algorithm's recursive halving strategy.
The implementation uses a recursive divide-and-conquer approach: 1. Split the input into even-indexed and odd-indexed subsequences 2. Recursively compute the FFT of each half 3. Combine the results using twiddle factors
For real-valued FFT, the twiddle factor's magnitude (norm) is used in the combination step, while the complex-valued FFT uses the full complex exponential multiplication.
The complex number support comes from the num::Complex crate, providing precise arithmetic for the Fourier basis functions.
Usage
Use the FFT for spectral analysis of time series data, frequency-domain filtering, and option pricing via characteristic function methods (e.g., the Carr-Madan method for pricing European options under models with known characteristic functions such as Heston or Variance Gamma). The input vector length must be a power of 2; pad with zeros if necessary.
Theoretical Basis
The Discrete Fourier Transform (DFT) of a sequence is:
The Cooley-Tukey algorithm exploits the periodicity and symmetry of the complex exponential. By separating even and odd indices:
This can be written as:
where and are the DFTs of the even and odd subsequences, and is the twiddle factor. This butterfly operation reduces the DFT to recursive steps.