# tensorplay.functional.hamming_window Source: https://www.tensorplay.cn/docs/generated/tensorplay.functional.hamming_window.html ```python tensorplay.functional.hamming_window(window_length, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function. $$w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),$$ where $N$ is the full window size. The input window_length is a positive integer controlling the returned window size. periodic flag determines whether the returned window trims off the last duplicate value from the symmetric window and is ready to be used as a periodic window with functions like tensorplay.stft(). Therefore, if periodic is true, the $N$ in above formula is in fact $\text{window\_length} + 1$. Also, we always have tensorplay.hamming_window(L, periodic=True) equal to tensorplay.hamming_window(L + 1, periodic=False)[:-1]). > **Note** > > If window_length $=1$, the returned window contains a single value 1. > **Note** > > This is a generalized version of tensorplay.hann_window(). Parameters: window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) ```python tensorplay.functional.hamming_window(window_length, periodic, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function with periodic specified. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – If True, returns a window to be used as periodic function. If False, return a symmetric window. Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) ```python tensorplay.functional.hamming_window(window_length, periodic, float alpha, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function with periodic and alpha specified. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – If True, returns a window to be used as periodic function. If False, return a symmetric window. - alpha ([float](https://docs.python.org/3/builtins/functions.html#float)) – The coefficient $\alpha$ in the equation above Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor) ```python tensorplay.functional.hamming_window(window_length, periodic, float alpha, float beta, *, dtype=None, layout=None, device=None, pin_memory=False, requires_grad=False) → Tensor ``` Hamming window function with periodic, alpha and beta specified. Parameters: - window_length ([int](https://docs.python.org/3/builtins/functions.html#int)) – the size of returned window - periodic ([bool](https://docs.python.org/3/builtins/functions.html#bool)) – If True, returns a window to be used as periodic function. If False, return a symmetric window. - alpha ([float](https://docs.python.org/3/builtins/functions.html#float)) – The coefficient $\alpha$ in the equation above - beta ([float](https://docs.python.org/3/builtins/functions.html#float)) – The coefficient $\beta$ in the equation above Keyword Arguments: - dtype ([tensorplay.dtype](/docs/generated/tensorplay.DType.html#tensorplay.DType), optional) – the desired data type of returned tensor. Default: if None, uses a global default (see [tensorplay.set_default_dtype()](/docs/generated/tensorplay.set_default_dtype.html#tensorplay.set_default_dtype)). Only floating point types are supported. - layout (tensorplay.layout, optional) – the desired layout of returned window tensor. Only tensorplay.strided (dense layout) is supported. - device ([tensorplay.device](/docs/generated/tensorplay.Device.html#tensorplay.Device), optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor type (see [tensorplay.set_default_device()](/docs/generated/tensorplay.set_default_device.html#tensorplay.set_default_device)). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. - pin_memory ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Default: False. - requires_grad ([bool](https://docs.python.org/3/builtins/functions.html#bool), optional) – If autograd should record operations on the returned tensor. Default: False. Returns: A 1-D tensor of size $(\text{window\_length},)$ containing the window. Return type: [Tensor](/docs/generated/tensorplay.Tensor.html#tensorplay.Tensor)