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.
- 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 of mindspore.dtype.float16, mindspore.dtype.float32 and mindspore.dtype.float64. Default: mindspore.dtype.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:
GPU
CPU
Examples
>>> # 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]