cutcutcodec.core.signal.window.dpss

cutcutcodec.core.signal.window.dpss(nb_samples: Integral, alpha: Real, dtype=torch.float64) Tensor[source]

Compute the Discrete Prolate Spheroidal Sequences (DPSS).

It is similar to the scipy function scipy.signal.windows.dpss.

DPSS windows

Parameters

nb_samplesint

The window size, it has to be >= 3.

alphafloat

Standardized half bandwidth.

dtypetorch.dtype, default=float64

The data type of the window samples: torch.float64 or torch.float32.

Returns

windowtorch.Tensor

The 1d symetric window, normalized with the maximum value at 1.

Examples

>>> import torch
>>> from cutcutcodec.core.signal.window import dpss
>>> dpss(1024, 2.0)
tensor([0.0158, 0.0163, 0.0169,  ..., 0.0169, 0.0163, 0.0158],
       dtype=torch.float64)
>>>
>>> # comparison with kaiser
>>> alpha, nbr = 5.0, 129
>>> win_dpss = dpss(nbr, alpha)
>>> win_kaiser = torch.kaiser_window(
...     nbr, periodic=False, beta=alpha*torch.pi, dtype=torch.float64
... )
>>> gain_dpss = 20*torch.log10(abs(torch.fft.rfft(win_dpss, 100000)))
>>> gain_dpss -= torch.max(gain_dpss)
>>> gain_kaiser = 20*torch.log10(abs(torch.fft.rfft(win_kaiser, 100000)))
>>> gain_kaiser -= torch.max(gain_kaiser)
>>>
>>> # import matplotlib.pyplot as plt
>>> # fig, (ax1, ax2) = plt.subplots(2)
>>> # _ = ax1.plot(win_dpss, label="dpss")
>>> # _ = ax1.plot(win_kaiser, label="kaiser")
>>> # _ = ax1.legend()
>>> # _ = ax2.plot(torch.linspace(0, 0.5, 50001), gain_dpss, label="dpss")
>>> # _ = ax2.plot(torch.linspace(0, 0.5, 50001), gain_kaiser, label="kaiser")
>>> # _ = ax2.axvline(x=alpha/nbr)
>>> # _ = ax2.legend()
>>> # plt.show()
>>>