fn

bartlett

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

Bartlett (triangular) window.

Generates a triangular taper that ramps linearly from 0 to 1 and back to 0 across the window length. Equivalent to the convolution of two boxcar windows, the Bartlett window provides the simplest non-trivial reduction of spectral leakage at the price of a wider main lobe.

Parameters

Mint
Number of samples in the output window; must be >= 0.
symbool= True
If True (default) generate a symmetric window suitable for filter design. If False generate a periodic window suitable for use with the DFT (the length-M+1M+1 symmetric form with the last sample dropped).
dtypeDTypeLike= None
Desired dtype of the output tensor; defaults to float32.
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]=12nN11,0n<N,w[n] = 1 - \left| \frac{2n}{N - 1} - 1 \right|, \qquad 0 \le n < N,

where N=MN = M (symmetric) or N=M+1N = M + 1 (periodic). The main-lobe width is roughly 8π/N8\pi / N (about twice that of the rectangular window) and the peak side-lobe attenuation is 26.5dB\approx -26.5\, \text{dB}.

Examples

>>> from lucid.signal.windows import bartlett
>>> bartlett(5)
Tensor([0.0000, 0.5000, 1.0000, 0.5000, 0.0000])