FFTEngine API
The main GPU-accelerated FFT engine for 1D and 2D transforms.
createFFTEngine()
Creates a new GPU-accelerated FFT engine instance.
Signature
ts
function createFFTEngine(config?: FFTEngineConfig): Promise<FFTEngine>;1
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
config | FFTEngineConfig | {} | Optional engine configuration |
Returns
Promise<FFTEngine> — Resolves when GPU resources are initialized.
Example
ts
import { createFFTEngine } from 'webgpu-fft';
const engine = await createFFTEngine();1
2
3
2
3
FFTEngine Class
Properties
| Property | Type | Description |
|---|---|---|
device | GPUDevice | The WebGPU device in use |
isDisposed | boolean | Whether resources have been released |
Methods
fft1D()
Performs a 1D forward FFT on the input data.
ts
fft1D(data: Float32Array, direction: FFTDirection): Promise<Float32Array>;1
Parameters:
data— Interleaved complex data[Re, Im, Re, Im, ...]. Length must be power of 2 (2-65536).direction—FFTDirection.ForwardorFFTDirection.Inverse
Returns: Promise<Float32Array> — Frequency domain data.
ts
const spectrum = await engine.fft1D(signal, FFTDirection.Forward);1
fft2D()
Performs a 2D FFT on image data.
ts
fft2D(
data: Float32Array,
width: number,
height: number,
direction: FFTDirection
): Promise<Float32Array>;1
2
3
4
5
6
2
3
4
5
6
Parameters:
data— Interleaved complex data of sizewidth * height * 2width— Image width (power of 2, max 2048)height— Image height (power of 2, max 2048)direction— Forward or Inverse
Returns: Promise<Float32Array> — 2D frequency domain data.
ts
const freqData = await engine.fft2D(imageData, 256, 256, FFTDirection.Forward);1
dispose()
Releases all GPU resources.
ts
dispose(): void;1
ts
engine.dispose();1
FFTDirection Enum
ts
enum FFTDirection {
Forward = -1,
Inverse = 1,
}1
2
3
4
2
3
4
FFTEngineConfig Type
ts
interface FFTEngineConfig {
/** GPU power preference */
powerPreference?: 'high-performance' | 'low-power';
}1
2
3
4
2
3
4
Related
- CPU FFT — CPU fallback implementation
- GPU Engine Architecture — Internal design