fn

general_hamming

Tensor
general_hamming(M: int, alpha: float, sym: bool = True, dtype: DTypeLike = None, device: DeviceLike = None)
source

Generalised Hamming-family window.

Parametric two-term cosine window covering the Hann (α=0.5\alpha = 0.5) / Hamming (α=0.54\alpha = 0.54) family. The free parameter α\alpha controls the trade-off between the level of the first side-lobe and the asymptotic side-lobe roll-off rate.

Parameters

Mint
Number of samples in the output window; must be >= 0.
alphafloat
Mixing coefficient; α=0.5\alpha = 0.5 gives Hann, α=0.54\alpha = 0.54 gives Hamming.
symbool= True
Symmetric (True, default) or periodic (False) variant.
dtypeDTypeLike= None
Desired dtype of the output tensor.
deviceDeviceLike= None
Target device for the output tensor.

Returns

Tensor

1-D tensor of length M containing the window samples.

Notes

Sample formula:

w[n]=α(1α)cos ⁣(2πnN1),0n<N.w[n] = \alpha - (1 - \alpha)\, \cos\!\left( \frac{2\pi n}{N - 1} \right), \qquad 0 \le n < N.

With α=25/460.5435\alpha = 25/46 \approx 0.5435 the first side-lobe is minimised in absolute level (the so-called "optimal" Hamming).

Examples

>>> from lucid.signal.windows import general_hamming
>>> general_hamming(5, alpha=0.5)
Tensor([0.0000, 0.5000, 1.0000, 0.5000, 0.0000])