cutcutcodec.core.signal.window.alpha_to_att

cutcutcodec.core.signal.window.alpha_to_att(alpha: float) float[source]

Empirical estimation based on regression.

The fitted model is (attenuation = a*alpha + b + c*tanh(d*alpha)).

Examples

>>> import torch
>>> from cutcutcodec.core.signal.window import find_dpss_law
>>> alphas, atts, _ = find_dpss_law()
>>> alphas, atts = alphas.to(torch.float64), atts.to(torch.float64)
>>> abcd = torch.tensor([3.393, 9.292, 271.5, 0.06323], dtype=torch.float64, requires_grad=True)
>>> optim = torch.optim.Adam([abcd])
>>> for _ in range(10000):
...     pred = abcd[0]*alphas + abcd[1] + abcd[2]*torch.tanh(abcd[3]*alphas)
...     optim.zero_grad()
...     torch.mean((atts - pred)**2).backward()
...     optim.step()
...
>>> abcd.detach().to(torch.float32)
tensor([3.3538e+00, 9.2918e+00, 2.7240e+02, 6.3155e-02])
>>> # import matplotlib.pyplot as plt
>>> # _ = plt.plot(alphas.numpy(force=True), atts.numpy(force=True))
>>> # _ = plt.plot(alphas.numpy(force=True), pred.numpy(force=True))
>>> # plt.show()
>>>