STFT#

  • Domain: ai.onnx

  • Since version: 17

Computes the Short-time Fourier Transform of the signal.

The STFT is computed by sliding a window of length frame_length over the signal with a step size of frame_step, computing a DFT of each windowed frame.

The number of frames in the output is computed as:

`frames = floor((signal_length - frame_length) / frame_step) + 1`

Constraints on inputs:

  • frame_step must be a scalar.

  • frame_length must be a scalar. When omitted and window is provided, frame_length is inferred from window.shape[0]. When both window and frame_length are omitted, frame_length defaults to signal_length.

  • window must be a 1-D tensor. When omitted, a rectangular (all-ones) window of length frame_length is used. When both window and frame_length are provided, the length of the window tensor must equal frame_length.

Inputs

  • signal (T1): Input tensor representing a real or complex valued signal. For real input, the following shape is expected: [batch_size][signal_length][1]. For complex input, the following shape is expected: [batch_size][signal_length][2], where [batch_size][signal_length][0] represents the real component and [batch_size][signal_length][1] represents the imaginary component of the signal. The tensor is expected to have rank 3.

  • frame_step (T2): A scalar representing the number of samples to step between successive DFTs.

  • window (T1): An optional 1-D tensor representing the window function to be applied to each frame of the signal before computing the DFT. The length of the window (window.shape[0]) determines the frame length when frame_length is not specified. If both window and frame_length are provided, the length of the window must equal frame_length. When omitted, a rectangular (all-ones) window of length frame_length is used.

  • frame_length (T2): An optional scalar representing the length of each frame (i.e., the DFT size). When omitted and window is provided, frame_length is inferred from window.shape[0]. When both window and frame_length are omitted, frame_length defaults to signal_length. If both frame_length and window are provided, the length of the window must equal frame_length.

Outputs

  • output (T1): The Short-time Fourier Transform of the signal. The number of frames in the output is frames = floor((signal_length - frame_length) / frame_step) + 1. If onesided is 1, the output has the shape: [batch_size][frames][dft_unique_bins][2], where dft_unique_bins is frame_length // 2 + 1 (the unique components of the DFT). If onesided is 0, the output has the shape: [batch_size][frames][frame_length][2], where frame_length is the length of the DFT. The last dimension of size 2 represents the real and imaginary parts of each complex value.

Attributes

  • onesided (int): If onesided is 1, only values for w in [0, 1, 2, …, floor(n_fft/2) + 1] are returned because the real-to-complex Fourier transform satisfies the conjugate symmetry, i.e., X[m, w] = X[m, n_fft-w]*. Note if the input or window tensors are complex, then onesided output is not possible. Enabling onesided with real inputs performs a Real-valued fast Fourier transform (RFFT). When invoked with real or complex valued input, the default value is 1. Values can be 0 or 1.

Type Constraints

  • T1: Constrain signal and output to float tensors. Allowed types: tensor(bfloat16), tensor(double), tensor(float), tensor(float16).

  • T2: Constrain scalar length types to int64_t. Allowed types: tensor(int32), tensor(int64).

Examples#

test_cc_stft

Node:
  STFT(signal, frame_step, "", frame_length) -> (output)
  Attributes:
    onesided = 1
Inputs:
  signal: shape=(1, 16, 1), dtype=float32
    [[[1.],
      [2.],
      [3.],
      [4.],
      [5.],
      [6.],
      [7.],
      [8.],
      [8.],
      [7.],
      [6.],
      [5.],
      [4.],
      [3.],
      [2.],
      [1.]]]
  frame_step: shape=(), dtype=int64
    4
  frame_length: shape=(), dtype=int64
    8

Outputs:
  output: shape=(1, 3, 5, 2), dtype=float32
    [[[[ 3.6000000e+01,  0.0000000e+00],
       [-4.0000000e+00,  9.6568546e+00],
       [-4.0000000e+00,  4.0000000e+00],
       [-4.0000000e+00,  1.6568543e+00],
       [-4.0000000e+00, -3.9188699e-15]],

      [[ 5.2000000e+01,  0.0000000e+00],
       [-5.8284273e+00, -2.4142137e+00],
       [-2.1431318e-15, -8.8817842e-16],
       [-1.7157288e-01, -4.1421357e-01],
       [ 0.0000000e+00, -2.2043643e-15]],

      [[ 3.6000000e+01,  0.0000000e+00],
       [ 4.0000000e+00, -9.6568546e+00],
       [ 4.0000000e+00, -4.0000000e+00],
       [ 4.0000000e+00, -1.6568543e+00],
       [ 4.0000000e+00, -4.8985874e-16]]]]

test_cc_stft_complex_batched

Node:
  STFT(signal, frame_step, "", frame_length) -> (output)
  Attributes:
    onesided = 0
Inputs:
  signal: shape=(2, 128, 2), dtype=float32
    [[[ 1.,  0.],
      [ 1.,  0.],
      [ 1.,  0.],
      ...,
      [ 1.,  0.],
      [ 1.,  0.],
      [ 1.,  0.]],

     [[99.,  0.],
      [99.,  0.],
      [99.,  0.],
      ...,
      [99.,  0.],
      [99.,  0.],
      [99.,  0.]]]
  frame_step: shape=(), dtype=int64
    16
  frame_length: shape=(), dtype=int64
    32

Outputs:
  output: shape=(2, 7, 32, 2), dtype=float32
    [[[[ 3.2000000e+01,  0.0000000e+00],
       [-2.3314684e-15, -2.2482016e-15],
       [-3.3306691e-16,  0.0000000e+00],
       ...,
       [-3.2973624e-14, -3.2751579e-14],
       [ 6.1395333e-14, -3.2418512e-14],
       [ 4.9960036e-14, -2.8810287e-14]],

      [[ 3.2000000e+01,  0.0000000e+00],
       [-2.3314684e-15, -2.2482016e-15],
       [-3.3306691e-16,  0.0000000e+00],
       ...,
       [-3.2973624e-14, -3.2751579e-14],
       [ 6.1395333e-14, -3.2418512e-14],
       [ 4.9960036e-14, -2.8810287e-14]],

      [[ 3.2000000e+01,  0.0000000e+00],
       [-2.3314684e-15, -2.2482016e-15],
       [-3.3306691e-16,  0.0000000e+00],
       ...,
       [-3.2973624e-14, -3.2751579e-14],
       [ 6.1395333e-14, -3.2418512e-14],
       [ 4.9960036e-14, -2.8810287e-14]],

      ...,

      [[ 3.2000000e+01,  0.0000000e+00],
       [-2.3314684e-15, -2.2482016e-15],
       [-3.3306691e-16,  0.0000000e+00],
       ...,
       [-3.2973624e-14, -3.2751579e-14],
       [ 6.1395333e-14, -3.2418512e-14],
       [ 4.9960036e-14, -2.8810287e-14]],

      [[ 3.2000000e+01,  0.0000000e+00],
       [-2.3314684e-15, -2.2482016e-15],
       [-3.3306691e-16,  0.0000000e+00],
       ...,
       [-3.2973624e-14, -3.2751579e-14],
       [ 6.1395333e-14, -3.2418512e-14],
       [ 4.9960036e-14, -2.8810287e-14]],

      [[ 3.2000000e+01,  0.0000000e+00],
       [-2.3314684e-15, -2.2482016e-15],
       [-3.3306691e-16,  0.0000000e+00],
       ...,
       [-3.2973624e-14, -3.2751579e-14],
       [ 6.1395333e-14, -3.2418512e-14],
       [ 4.9960036e-14, -2.8810287e-14]]],


     [[[ 3.1680000e+03,  0.0000000e+00],
       [ 2.8421709e-14, -9.5923269e-14],
       [-8.5265128e-14, -8.5265128e-14],
       ...,
       [-3.2827074e-12, -3.2329694e-12],
       [ 6.1533001e-12, -3.1405989e-12],
       [ 5.1727511e-12, -3.0588865e-12]],

      [[ 3.1680000e+03,  0.0000000e+00],
       [ 2.8421709e-14, -9.5923269e-14],
       [-8.5265128e-14, -8.5265128e-14],
       ...,
       [-3.2827074e-12, -3.2329694e-12],
       [ 6.1533001e-12, -3.1405989e-12],
       [ 5.1727511e-12, -3.0588865e-12]],

      [[ 3.1680000e+03,  0.0000000e+00],
       [ 2.8421709e-14, -9.5923269e-14],
       [-8.5265128e-14, -8.5265128e-14],
       ...,
       [-3.2827074e-12, -3.2329694e-12],
       [ 6.1533001e-12, -3.1405989e-12],
       [ 5.1727511e-12, -3.0588865e-12]],

      ...,

      [[ 3.1680000e+03,  0.0000000e+00],
       [ 2.8421709e-14, -9.5923269e-14],
       [-8.5265128e-14, -8.5265128e-14],
       ...,
       [-3.2827074e-12, -3.2329694e-12],
       [ 6.1533001e-12, -3.1405989e-12],
       [ 5.1727511e-12, -3.0588865e-12]],

      [[ 3.1680000e+03,  0.0000000e+00],
       [ 2.8421709e-14, -9.5923269e-14],
       [-8.5265128e-14, -8.5265128e-14],
       ...,
       [-3.2827074e-12, -3.2329694e-12],
       [ 6.1533001e-12, -3.1405989e-12],
       [ 5.1727511e-12, -3.0588865e-12]],

      [[ 3.1680000e+03,  0.0000000e+00],
       [ 2.8421709e-14, -9.5923269e-14],
       [-8.5265128e-14, -8.5265128e-14],
       ...,
       [-3.2827074e-12, -3.2329694e-12],
       [ 6.1533001e-12, -3.1405989e-12],
       [ 5.1727511e-12, -3.0588865e-12]]]]

test_cc_stft_default_frame_length

Node:
  STFT(signal, frame_step, "") -> (output)
  Attributes:
    onesided = 1
Inputs:
  signal: shape=(1, 16, 1), dtype=float32
    [[[1.],
      [2.],
      [3.],
      [4.],
      [5.],
      [6.],
      [7.],
      [8.],
      [8.],
      [7.],
      [6.],
      [5.],
      [4.],
      [3.],
      [2.],
      [1.]]]
  frame_step: shape=(), dtype=int64
    4

Outputs:
  output: shape=(1, 1, 9, 2), dtype=float32
    [[[[ 7.2000000e+01,  0.0000000e+00],
       [-2.5274143e+01, -5.0273395e+00],
       [ 2.6645353e-15, -1.2212453e-15],
       [-2.2398288e+00, -1.4966058e+00],
       [-1.6239563e-14, -4.4408921e-16],
       [-4.4646269e-01, -6.6817862e-01],
       [-1.3877788e-14,  3.6637360e-15],
       [-3.9566129e-02, -1.9891237e-01],
       [ 0.0000000e+00, -1.1148000e-14]]]]

test_cc_stft_twosided

Node:
  STFT(signal, frame_step, "", frame_length) -> (output)
  Attributes:
    onesided = 0
Inputs:
  signal: shape=(1, 16, 1), dtype=float32
    [[[1.],
      [2.],
      [3.],
      [4.],
      [5.],
      [6.],
      [7.],
      [8.],
      [8.],
      [7.],
      [6.],
      [5.],
      [4.],
      [3.],
      [2.],
      [1.]]]
  frame_step: shape=(), dtype=int64
    4
  frame_length: shape=(), dtype=int64
    8

Outputs:
  output: shape=(1, 3, 8, 2), dtype=float32
    [[[[ 3.6000000e+01,  0.0000000e+00],
       [-4.0000000e+00,  9.6568546e+00],
       [-4.0000000e+00,  4.0000000e+00],
       [-4.0000000e+00,  1.6568543e+00],
       [-4.0000000e+00, -3.9188699e-15],
       [-4.0000000e+00, -1.6568543e+00],
       [-4.0000000e+00, -4.0000000e+00],
       [-4.0000000e+00, -9.6568546e+00]],

      [[ 5.2000000e+01,  0.0000000e+00],
       [-5.8284273e+00, -2.4142137e+00],
       [-2.1431318e-15, -8.8817842e-16],
       [-1.7157288e-01, -4.1421357e-01],
       [ 0.0000000e+00, -2.2043643e-15],
       [-1.7157288e-01,  4.1421357e-01],
       [-1.7551422e-14, -2.6645353e-15],
       [-5.8284273e+00,  2.4142137e+00]],

      [[ 3.6000000e+01,  0.0000000e+00],
       [ 4.0000000e+00, -9.6568546e+00],
       [ 4.0000000e+00, -4.0000000e+00],
       [ 4.0000000e+00, -1.6568543e+00],
       [ 4.0000000e+00, -4.8985874e-16],
       [ 4.0000000e+00,  1.6568543e+00],
       [ 4.0000000e+00,  4.0000000e+00],
       [ 4.0000000e+00,  9.6568546e+00]]]]

test_cc_stft_with_window

Node:
  STFT(signal, frame_step, window, frame_length) -> (output)
  Attributes:
    onesided = 1
Inputs:
  signal: shape=(1, 16, 1), dtype=float32
    [[[1.],
      [2.],
      [3.],
      [4.],
      [5.],
      [6.],
      [7.],
      [8.],
      [8.],
      [7.],
      [6.],
      [5.],
      [4.],
      [3.],
      [2.],
      [1.]]]
  frame_step: shape=(), dtype=int64
    4
  window: shape=(8,), dtype=float32
    [1., 1., 1., 1., 1., 1., 1., 1.]
  frame_length: shape=(), dtype=int64
    8

Outputs:
  output: shape=(1, 3, 5, 2), dtype=float32
    [[[[ 3.6000000e+01,  0.0000000e+00],
       [-4.0000000e+00,  9.6568546e+00],
       [-4.0000000e+00,  4.0000000e+00],
       [-4.0000000e+00,  1.6568543e+00],
       [-4.0000000e+00, -3.9188699e-15]],

      [[ 5.2000000e+01,  0.0000000e+00],
       [-5.8284273e+00, -2.4142137e+00],
       [-2.1431318e-15, -8.8817842e-16],
       [-1.7157288e-01, -4.1421357e-01],
       [ 0.0000000e+00, -2.2043643e-15]],

      [[ 3.6000000e+01,  0.0000000e+00],
       [ 4.0000000e+00, -9.6568546e+00],
       [ 4.0000000e+00, -4.0000000e+00],
       [ 4.0000000e+00, -1.6568543e+00],
       [ 4.0000000e+00, -4.8985874e-16]]]]