stft¶
- paddle.signal. stft ( x: Tensor, n_fft: int, hop_length: int | None = None, win_length: int | None = None, window: Tensor | None = None, center: bool = True, pad_mode: Literal[reflect, constant] = 'reflect', normalized: bool = False, onesided: bool = True, name: str | None = None ) Tensor [source]
-
Short-time Fourier transform (STFT).
The STFT computes the discrete Fourier transforms (DFT) of short overlapping windows of the input using this formula:
Xt[f]=N−1∑n=0window[n] x[t×H+n] e−2πjfn/NWhere: - t: The t-th input window. - f: Frequency 0≤f<n_fft for onesided=False, or 0≤f<⌊n_fft/2⌋+1 for onesided=True. - 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|None, 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|None, optional) – The size of window. Default: None (treated as equal to n_fft)
window (Tensor|None, 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×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|None, 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] (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) >>> print(y1.shape) [8, 257, 376] >>> y2 = stft(x, n_fft=512, onesided=False) >>> print(y2.shape) [8, 512, 376] >>> # complex input >>> x = paddle.randn([8, 48000], dtype=paddle.float64) + \ ... paddle.randn([8, 48000], dtype=paddle.float64)*1j >>> print(x.shape) [8, 48000] >>> print(x.dtype) paddle.complex128 >>> y1 = stft(x, n_fft=512, center=False, onesided=False) >>> print(y1.shape) [8, 512, 372]