cutcutcodec.core.signal.window.alpha_to_band
- cutcutcodec.core.signal.window.alpha_to_band(alpha: float) float[source]
Empirical estimation based on regression.
The fitted model is \(band = a*\alpha + b + c*tanh(d*\alpha)\).
This function is close to the identity function.
Examples
>>> import torch >>> from cutcutcodec.core.signal.window import find_dpss_law >>> alphas, _, bands = find_dpss_law() >>> alphas, bands = alphas.to(torch.float64), bands.to(torch.float64) >>> abcd = torch.tensor([0.932, 0.815, -0.559, 1.61], 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((bands - pred)**2).backward() ... optim.step() ... >>> abcd.detach().to(torch.float32) tensor([ 0.9321, 0.8148, -0.5588, 1.6099]) >>> # import matplotlib.pyplot as plt >>> # _ = plt.plot(alphas.numpy(force=True), bands.numpy(force=True)) >>> # _ = plt.plot(alphas.numpy(force=True), pred.numpy(force=True)) >>> # plt.show() >>>