window#

class diffsptk.Window(in_length: int, out_length: int | None = None, *, window: str | int = 'blackman', norm: str | int = 'power', symmetric: bool = True, learnable: bool = False, device: device | None = None, dtype: dtype | None = None)[source]#

See this page for details.

Parameters:
in_lengthint >= 1

The window length, \(L_1\).

out_lengthint >= L1 or None

The output length, \(L_2\). If \(L_2 > L_1\), output is zero-padded. If None, \(L_2 = L_1\).

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

The window type.

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

The normalization type of the window.

symmetricbool

If True, the window is symmetric, otherwise periodic.

learnablebool

Whether to make the window learnable.

devicetorch.device or None

The device of this module.

dtypetorch.dtype or None

The data type of this module.

forward(x: Tensor) Tensor[source]#

Apply a window function to the given waveform.

Parameters:
xTensor [shape=(…, L1)]

The input framed waveform.

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

The windowed waveform.

Examples

>>> x = torch.ones(5)
>>> window = diffsptk.Window(5, out_length=7, window="hamming", norm="none")
>>> y = window(x)
>>> y
tensor([0.0800, 0.5400, 1.0000, 0.5400, 0.0800, 0.0000, 0.0000])
diffsptk.functional.window(x: Tensor, out_length: int | None = None, *, window: str = 'blackman', norm: str = 'power', symmetric: bool = True) Tensor[source]#

Apply a window function to the given waveform.

Parameters:
xTensor [shape=(…, L1)]

The input framed waveform.

out_lengthint >= L1 or None

The output length, \(L_2\). If \(L_2 > L_1\), output is zero-padded. If None, \(L_2 = L_1\).

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

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=(…, L2)]

The windowed waveform.

See also

frame unframe spec