istft#

diffsptk.ISTFT#

alias of InverseShortTimeFourierTransform

class diffsptk.InverseShortTimeFourierTransform(frame_length: int, frame_period: int, fft_length: int, *, center: bool = True, window: str = 'blackman', norm: str = 'power', symmetric: bool = True, learnable: bool | list[str] = False, device: device | None = None, dtype: dtype | None = None)[source]#

This is the opposite module to ShortTimeFourierTransform().

Parameters:
frame_lengthint >= 1

The frame length in samples, \(L\).

frame_periodint >= 1

The frame period in samples, \(P\).

fft_lengthint >= L

The number of FFT bins, \(N\).

centerbool

If True, pad the input on both sides so that the frame is centered.

window[‘blackman’, ‘hamming’, ‘hanning’, ‘bartlett’, ‘trapezoidal’, ‘rectangular’, ‘nuttall’]

The window type.

norm[‘none’, ‘power’, ‘magnitude’]

The normalization type of the window.

symmetricbool

If True, the window is symmetric, otherwise periodic.

learnablebool or list[str]

Indicates whether the parameters are learnable. If a boolean, it specifies whether all parameters are learnable. If a list, it contains the keys of the learnable parameters, which can only be “basis” and “window”.

devicetorch.device or None

The device of this module.

dtypetorch.dtype or None

The data type of this module.

forward(y: Tensor, out_length: int | None = None) Tensor[source]#

Compute inverse short-time Fourier transform.

Parameters:
yTensor [shape=(…, T/P, N/2+1)]

The complex spectrogram.

out_lengthint > 0 or None

The length of the output waveform.

Returns:
outTensor [shape=(…, T)]

The reconstructed waveform.

Examples

>>> x = diffsptk.ramp(1, 3)
>>> x
tensor([1., 2., 3.])
>>> stft_params = {"frame_length": 3, "frame_period": 1, "fft_length": 8}
>>> stft = diffsptk.STFT(**stft_params, out_format="complex")
>>> istft = diffsptk.ISTFT(**stft_params)
>>> y = istft(stft(x), out_length=3)
>>> y
tensor([1., 2., 3.])
diffsptk.functional.istft(y: Tensor, *, out_length: int | None = None, frame_length: int = 400, frame_period: int = 80, fft_length: int = 512, center: bool = True, window: str = 'blackman', norm: str = 'power', symmetric: bool = True) Tensor[source]#

Compute inverse short-time Fourier transform.

Parameters:
yTensor [shape=(…, T/P, N/2+1)]

The complex spectrogram.

out_lengthint >= 1 or None

The length of the output waveform.

frame_lengthint >= 1

The frame length in samples, \(L\).

frame_periodint >= 1

The frame period in samples, \(P\).

fft_lengthint >= L

The number of FFT bins, \(N\).

centerbool

If True, pad the input on both sides so that the frame is centered.

window[‘blackman’, ‘hamming’, ‘hanning’, ‘bartlett’, ‘trapezoidal’, ‘rectangular’, ‘nuttall’]

The window type.

norm[‘none’, ‘power’, ‘magnitude’]

The normalization type of the window.

symmetricbool

If True, the window is symmetric, otherwise periodic.

Returns:
outTensor [shape=(…, T)]

The reconstructed waveform.