stft

paddle.signal. stft ( x, n_fft, hop_length=None, win_length=None, window=None, center=True, pad_mode='reflect', normalized=False, onesided=True, name=None ) [source]

Short-time Fourier transform (STFT).

The STFT computes the discrete Fourier transforms (DFT) of short overlapping windows of the input using this formula:

\[X_t[\omega] = \sum_{n = 0}^{N-1}% \text{window}[n]\ x[t \times H + n]\ % e^{-{2 \pi j \omega n}/{N}}\]

Where: - \(t\): The \(t\)-th input window. - \(\omega\): Frequency \(0 \leq \omega < \text{n\_fft}\) for onesided=False,

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/signal.py:docstring of paddle.signal.stft, line 14)

Unexpected indentation.

or \(0 \leq \omega < \lfloor \text{n\_fft} / 2 \rfloor + 1\) for onesided=True.

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/signal.py:docstring of paddle.signal.stft, line 15)

Block quote ends without a blank line; unexpected unindent.

  • \(N\): Value of n_fft.

  • \(H\): Value of hop_length.

Parameters
  • x (Tensor) – The input data which is a 1-dimensional or 2-dimensional Tensor with shape […, seq_length]. It can be a real-valued or a complex Tensor.

  • n_fft (int) – The number of input samples to perform Fourier transform.

  • hop_length (int, optional) – Number of steps to advance between adjacent windows and 0 < hop_length. Default: None`(treated as equal to `n_fft//4)

  • win_length (int, optional) – The size of window. Default: None`(treated as equal to `n_fft)

  • window (Tensor, optional) – A 1-dimensional tensor of size win_length. It will be center padded to length n_fft if win_length < n_fft. Default: None`( treated as a rectangle window with value equal to 1 of size `win_length).

  • center (bool, optional) – Whether to pad x to make that the \(t \times hop\_length\) at the center of \(t\)-th frame. Default: True.

  • pad_mode (str, optional) – Choose padding pattern when center is True. See paddle.nn.functional.pad for all padding options. Default: “reflect”

  • normalized (bool, optional) – Control whether to scale the output by 1/sqrt(n_fft). Default: False

  • onesided (bool, optional) – Control whether to return half of the Fourier transform output that satisfies the conjugate symmetry condition when input is a real-valued tensor. It can not be True if input is a complex tensor. Default: True

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns

The complex STFT output tensor with shape `[…, n_fft//2 + 1, num_frames]`(

System Message: WARNING/2 (/usr/local/lib/python3.8/site-packages/paddle/signal.py:docstring of paddle.signal.stft, line 54); backlink

Inline interpreted text or phrase reference start-string without end-string.

real-valued input and onesided is True) or […, n_fft, num_frames]`( `onesided is False)

Examples

import paddle
from paddle.signal import stft

# real-valued input
x = paddle.randn([8, 48000], dtype=paddle.float64)
y1 = stft(x, n_fft=512)  # [8, 257, 376]
y2 = stft(x, n_fft=512, onesided=False)  # [8, 512, 376]

# complex input
x = paddle.randn([8, 48000], dtype=paddle.float64) + \
        paddle.randn([8, 48000], dtype=paddle.float64)*1j  # [8, 48000] complex128
y1 = stft(x, n_fft=512, center=False, onesided=False)  # [8, 512, 372]