ai.onnx.STFT

ai.onnx · standard ONNX operator · ONNX opset ≥ 17

Description

Computes the short-time Fourier transform (STFT) of a rank-3 real or complex signal by sliding a complete frame over the input and applying the DFT. The frameStep scalar represents the required positive frame_step input. At least one of window or frameLength is required; when both are supplied, their lengths must match. The output contains the real and imaginary components of every frequency bin for each complete frame.

See the ONNX STFT spec for the reference semantics.

Inputs

Name Bind key Logical dtype Rank Shape Description Presence
signal signal T 3 Real input signal with shape (batch_size, signal_length, 1), or complex input with shape (batch_size, signal_length, 2). required
window window T 1 Optional 1-D window tensor with shape (window_length) to multiply by each frame before the DFT. optional

Outputs

Name Bind key Logical dtype Rank Shape Description Presence
output output T 4 derived; see description STFT result with shape (batch_size, frames, dft_unique_bins, 2) in one-sided mode or (batch_size, frames, frame_length, 2) in two-sided mode, with real and imaginary parts in the last dimension. frames = floor((signal_length - frame_length) / frame_step) + 1; partial trailing frames are not emitted. required

Runtime arguments

Name Kind Semantic Description Presence
frameStep i32 frame_step Positive number of signal positions between the starts of consecutive frames. required
frameLength i32 frame_length Optional number of signal values in each frame; must equal the window length when both are supplied. optional

Attributes

Default values (overridable per request):

Attribute Default Description
onesided 1 When 1 (default), returns floor(n_fft / 2) + 1 non-redundant frequency bins with indices [0, ..., floor(n_fft / 2)] for a real-valued input (RFFT); set to 0 to return the full spectrum.

Type constraints

Variable Allowed dtypes
T float32

Files

Use with @huggingface/kernels

The loader derives every required output's shape and logical dtype from the manifest contract and this call. It then allocates the result tensors automatically.

The version: 1 option selects the published kernel contract; it is independent of any operator opset, contrib since_version, or model version.

Replace each *Data placeholder with a typed array containing the corresponding input data.

import { getKernel } from "@huggingface/kernels";

const kernel = await getKernel("webgpu-kernels/ai.onnx.STFT", { version: 1 });
const { output } = await kernel({
  signal: { data: signalData, shape: [1, 4, 1] },
  window: { data: windowData, shape: [4] },
  frameStep: 4,
});
Downloads last month
-
kernel
webgpu
wgsl
apache-2.0
WebGPU

Requires WebGPU support. See the compatibility table.