mindspore.ops.HammingWindow
- class mindspore.ops.HammingWindow(periodic=True, alpha=0.54, beta=0.46, dtype=mstype.float32)[source]
Computes the hamming window function with input window length.
\[w[n] = \alpha - \beta\ \cos \left( \frac{2 \pi n}{N - 1} \right),\]where \(N\) is the full window size.
Warning
This is an experimental API that is subject to change or deletion.
- Parameters
periodic (bool, optional) –
a flag determines whether the returned window trims off the last duplicate value from the symmetric window. Default:
True
.If True, returns a window to be used as periodic function, in above formula, \(N = \text{length} + 1\).
If False, return a symmetric window, \(N = \text{length}\).
alpha (float, optional) – The coefficient \(\alpha\) in the equation above. Default:
0.54
.beta (float, optional) – The coefficient \(\beta\) in the equation above. Default:
0.46
.dtype (
mindspore.dtype
, optional) – An optional data type ofmstype.float16
,mstype.float32
andmstype.float64
. Default:mstype.float32
.
- Inputs:
length (Tensor) - a positive integer tensor controlling the returned window size, must be 1D.
- Outputs:
Tensor, A 1-D tensor containing the window, whose shape is \((\text{length},)\).
- Raises
TypeError – If length is not a Tensor.
TypeError – If dtype of length is not integer data type.
TypeError – If periodic is not a bool.
TypeError – If alpha is not a float.
TypeError – If beta is not a float.
TypeError – If dtype is not mindspore.float16, mindspore.float32 or mindspore.float64.
ValueError – If dimension of length is not 1.
ValueError – If data of length is negative.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor, ops >>> # case 1: periodic=True. >>> length = Tensor(np.array([6]).astype(np.int32)) >>> hamming_window = ops.HammingWindow(periodic=True) >>> y = hamming_window(length) >>> print(y) [0.08000001 0.31 0.77000004 1. 0.77000004 0.31 ] >>> # case 2: periodic=False. >>> length = Tensor(np.array([7]).astype(np.int32)) >>> hamming_window = ops.HammingWindow(periodic=False) >>> y = hamming_window(length) >>> print(y) [0.08000001 0.31 0.77000004 1. 0.77000004 0.31 0.08000001]