mindspore.ops.hann_window

mindspore.ops.hann_window(window_length, periodic=True, *, dtype=None)[source]

Generates a Hann Window.

The Hann window is defined as

\[w(n) = \frac{1}{2} - \frac{1}{2} \cos\left(\frac{2\pi{n}}{M-1}\right),\qquad 0 \leq n \leq M-1\]
Parameters
  • window_length (int) – Length of window.

  • periodic (bool, optional) – When set to True, generates a periodic window for spectral analysis. When set to False, generates a symmetric window for filter design.Default: True.

Keyword Arguments

dtype (mindspore.dtype, optional) – The output window data type, it must be float. Default: None.

Returns

Tensor, a Hann window.

Raises
  • TypeError – If window_length is not an integer.

  • TypeError – If periodic is not a variable of Boolean type.

  • ValueError – If window_length is negative.

Supported Platforms:

Ascend GPU CPU

Examples

>>> window_length = 5
>>> out = ops.hann_window(window_length)
>>> print(out.asnumpy())
[0.        0.3454915 0.9045085 0.9045085 0.3454915]