|
| 1 | +# FFTWOperators.jl |
| 2 | + |
| 3 | +[](https://kul-optec.github.io/AbstractOperators.jl/stable/operators/#FFTW) |
| 4 | +[](https://kul-optec.github.io/AbstractOperators.jl/latest/operators/#FFTW) |
| 5 | + |
| 6 | +Fast Fourier Transform operators for the AbstractOperators.jl framework. |
| 7 | + |
| 8 | +## Overview |
| 9 | + |
| 10 | +FFTWOperators.jl is a specialized extension package for [AbstractOperators.jl](../README.md) that provides linear operators for efficient Fourier and frequency-domain transforms. It wraps the high-performance FFTW library to offer Discrete Fourier Transforms (DFT), Real FFTs (RDFT), Inverse Real FFTs (IRDFT), and Discrete Cosine Transforms (DCT) as seamlessly integrated `LinearOperator` instances. |
| 11 | + |
| 12 | +## Relationship to AbstractOperators.jl |
| 13 | + |
| 14 | +FFTWOperators.jl is a **subpackage** of the AbstractOperators.jl ecosystem. While AbstractOperators.jl provides the core abstract operator framework, FFTWOperators.jl extends it with domain-specific functionality for Fourier analysis and frequency-domain operations. This modular design allows users to access high-performance FFT capabilities only when needed. |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```julia |
| 19 | +pkg> add FFTWOperators |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage Example |
| 23 | + |
| 24 | +```julia |
| 25 | +using FFTWOperators |
| 26 | + |
| 27 | +# Create input data |
| 28 | +x = randn(64, 64) |
| 29 | + |
| 30 | +# Create a DFT operator |
| 31 | +dft_op = DFT(x) |
| 32 | + |
| 33 | +# Compute the Fourier transform |
| 34 | +X_fft = dft_op * x |
| 35 | + |
| 36 | +# Use in optimization or iterative algorithms |
| 37 | +# The operator integrates with AbstractOperators.jl algorithms |
| 38 | +``` |
| 39 | + |
| 40 | +## Main Features |
| 41 | + |
| 42 | +### 1. **DFT** - Discrete Fourier Transform |
| 43 | +Computes the N-dimensional Discrete Fourier Transform using FFTW's optimized algorithms. |
| 44 | + |
| 45 | +- **Multi-dimensional support**: Works on arbitrary-dimensional arrays |
| 46 | +- **Selective dimensions**: Transform over specified dimensions of a multi-dimensional array |
| 47 | +- **Multiple normalizations**: UNNORMALIZED, ORTHO, FORWARD, and BACKWARD schemes |
| 48 | +- **Customizable planning**: Control FFTW planning flags and time limits |
| 49 | +- **Orthogonal properties**: Supports orthogonal DFT operations for optimization algorithms |
| 50 | + |
| 51 | +```julia |
| 52 | +using FFTWOperators |
| 53 | + |
| 54 | +# Complex-valued DFT |
| 55 | +dft_op = DFT(Complex{Float64}, (10, 10)) |
| 56 | + |
| 57 | +# Real-valued input (transforms to complex output) |
| 58 | +x = randn(64, 64) |
| 59 | +dft_op = DFT(x) |
| 60 | +X = dft_op * x # Fourier transform |
| 61 | + |
| 62 | +# Transform along specific dimensions |
| 63 | +dft_op = DFT(x, 1) # Only along first dimension |
| 64 | +``` |
| 65 | + |
| 66 | +### 2. **RDFT** - Real FFT |
| 67 | +Specialized Fast Fourier Transform for real-valued inputs, exploiting Hermitian symmetry for efficiency. |
| 68 | + |
| 69 | +- **Real input efficiency**: Optimized for real-valued signals, outputs complex values |
| 70 | +- **Dimension-selective**: Transform along specific dimensions |
| 71 | +- **Conjugate symmetry**: Automatically exploits Hermitian symmetry properties |
| 72 | +- **Reduced computation**: Approximately 50% faster than complex FFT for real inputs |
| 73 | + |
| 74 | +```julia |
| 75 | +using FFTWOperators |
| 76 | + |
| 77 | +# Real FFT of a real-valued array |
| 78 | +rdft_op = RDFT(Float64, (10, 10)) |
| 79 | + |
| 80 | +# Apply along a specific dimension |
| 81 | +x = randn(100, 10, 10) |
| 82 | +rdft_op = RDFT(x, 2) # Transform along dimension 2 |
| 83 | +X = rdft_op * x |
| 84 | +``` |
| 85 | + |
| 86 | +### 3. **IRDFT** - Inverse Real FFT |
| 87 | +Transforms complex-valued k-space data back to real-valued spatial domain, inverse of RDFT. |
| 88 | + |
| 89 | +- **Hermitian reconstruction**: Properly reconstructs real values from complex k-space |
| 90 | +- **Adjoint operation**: Acts as the adjoint of RDFT for linear algebra operations |
| 91 | +- **Energy preserving**: Maintains signal energy in the inverse transform |
| 92 | + |
| 93 | +```julia |
| 94 | +using FFTWOperators |
| 95 | + |
| 96 | +# Inverse real FFT - transforms complex-valued input to real-valued output |
| 97 | +# Takes the k-space dimension, the desired output spatial dimension, and optionally the transform dimension |
| 98 | +irdft_op = IRDFT((51,), 100, 1) # 51 complex input -> 100 real output along dimension 1 |
| 99 | +``` |
| 100 | + |
| 101 | +### 4. **DCT** - Discrete Cosine Transform |
| 102 | +Computes the Discrete Cosine Transform, useful for image compression and spectral analysis. |
| 103 | + |
| 104 | +- **Real-valued I/O**: Works with real-valued signals for many applications |
| 105 | +- **Complex support**: Also supports complex-valued transforms |
| 106 | +- **Standard DCT**: Implements standard DCT-II (the most common variant) |
| 107 | +- **Orthogonal transform**: Invertible with fast IDCT operation |
| 108 | + |
| 109 | +```julia |
| 110 | +using FFTWOperators |
| 111 | + |
| 112 | +# Real-valued DCT |
| 113 | +dct_op = DCT(Float64, (10, 10)) |
| 114 | +x = randn(10, 10) |
| 115 | +y = dct_op * x # Cosine transform |
| 116 | + |
| 117 | +# Complex DCT |
| 118 | +dct_complex = DCT(Complex{Float64}, (8, 8)) |
| 119 | + |
| 120 | +# Inverse DCT |
| 121 | +idct_op = IDCT(Float64, (10, 10)) |
| 122 | +``` |
| 123 | + |
| 124 | +### 5. **Shift** - Frequency Shift Operator |
| 125 | +Applies frequency shifts and zero-padding to signals. |
| 126 | + |
| 127 | +- **Frequency shifting**: Shift zero-frequency component to the center |
| 128 | +- **Zero-padding**: Efficiently apply padding for zero-padded transforms |
| 129 | +- **Composable**: Combines seamlessly with other operators |
| 130 | + |
| 131 | +## License |
| 132 | + |
| 133 | +See LICENSE.md for details. |
0 commit comments