5#include <isce3/except/Error.h>
6#include <isce3/math/Sinc.h>
8namespace isce3 {
namespace core {
18 double t2 = fabs(t / this->_halfwidth);
30T _sampling_window(T t, T halfwidth, T bandwidth)
32 using isce3::except::RuntimeError;
33 if (!((0.0 < bandwidth) && (bandwidth < 1.0))) {
34 throw RuntimeError(ISCE_SRCINFO(),
"Require 0 < bandwidth < 1");
36 const T c = M_PI * halfwidth * (1.0 - bandwidth);
37 const T tf = t / halfwidth;
38 std::complex<T> y = sqrt((std::complex<T>) (1.0 - tf * tf));
39 T window = std::real<T>(cosh(c * y) / cosh(c));
40 if (!std::isfinite(window)) {
41 throw RuntimeError(ISCE_SRCINFO(),
"Invalid window parameters.");
50 auto st = isce3::math::sinc<T>(t);
51 return _sampling_window(t, this->_halfwidth, this->_bandwidth) * st;
61 : Kernel<T>(2 * m + 1), _m(m), _n(n), _fft_size(fft_size)
63 if ((m < 1) || (n < 1) || (fft_size < 1)) {
64 throw isce3::except::LengthError(ISCE_SRCINFO(),
65 "NFFT parameters must be positive.");
67 _b = M_PI * (2.0 - 1.0 * n / fft_size);
68 _scale = 1.0 / (M_PI * isce3::math::bessel_i0(_m * _b));
75 T x2 = t * t - _m * _m;
77 if (std::abs(x2) < std::numeric_limits<double>::epsilon()) {
82 T x = std::sqrt(std::abs(x2));
83 out = std::sinh(_b * x) / x;
86 out = std::sin(_b * x) / x;
97 const double x = std::abs(t * 2 / this->_halfwidth);
103 return x * x * (0.75 * x - 1.5) + 1.0;
106 return x * (x * (-0.25 * x + 1.5) - 3.0) + 2.0;
117 :
Kernel<T>(kernel.width())
121 throw isce3::except::LengthError(ISCE_SRCINFO(),
122 "Require table size >= 2.");
129 const double dx = this->_halfwidth / (n - 1.0);
131 for (
int i = 0; i < n; ++i) {
133 _table[i] =
static_cast<T
>(kernel(x));
142 auto ax = std::abs(x);
143 if (ax > this->_halfwidth) {
147 auto axn = ax * _1_dx;
149 int i = std::floor(axn);
151 i = std::min(i, _imax);
153 return _table[i] + (axn - i) * (_table[i + 1] - _table[i]);
157template<
typename Tin>
159 : Kernel<T>(kernel.
width())
162 throw isce3::except::LengthError(ISCE_SRCINFO(),
163 "Need at least one coefficient.");
168 std::vector<T> q(n), fx(n);
169 _scale = 4.0 / kernel.
width();
170 for (
int i = 0; i < n; ++i) {
171 q[i] = M_PI * (2.0 * i + 1.0) / (2.0 * n);
173 T x = (std::cos(q[i]) + 1.0) / _scale;
174 fx[i] =
static_cast<T
>(kernel(x));
180 for (
int i = 0; i < n; ++i) {
182 for (
int j = 0; j < n; ++j) {
183 T w = std::cos(i * q[j]);
184 _coeffs[i] += w * fx[j];
186 _coeffs[i] *= 2.0 / n;
195 const auto ax = std::abs(x);
196 if (ax > this->_halfwidth) {
200 const T q = (ax * _scale) - T(1);
201 const T twoq = T(2) * q;
202 const int n = _coeffs.size();
204 T bk = 0, bk1 = 0, bk2 = 0;
205 for (
int i = n - 1; i > 0; --i) {
206 bk = _coeffs[i] + twoq * bk1 - bk2;
210 return _coeffs[0] + q * bk1 - bk2;
T operator()(double x) const override
Evaluate kernel at given location in [-halfwidth, halfwidth].
Definition Kernels.icc:95
T operator()(double x) const override
Evaluate kernel at given location in [-halfwidth, halfwidth].
Definition Kernels.icc:16
T operator()(double x) const override
Evaluate kernel at given location in [-halfwidth, halfwidth].
Definition Kernels.icc:192
ChebyKernel(const Kernel< Tin > &kernel, int n)
Constructor that computes fit of another Kernel.
Definition Kernels.icc:158
Abstract base class for all kernels.
Definition Kernels.h:19
double width() const
Get width of kernel.
Definition Kernels.h:35
T operator()(double x) const override
Evaluate kernel at given location in [-halfwidth, halfwidth].
Definition Kernels.icc:48
T operator()(double x) const override
Evaluate kernel at given location in [-halfwidth, halfwidth].
Definition Kernels.icc:73
NFFTKernel(int m, int n, int fft_size)
Constructor of NFFT kernel.
Definition Kernels.icc:60
TabulatedKernel(const Kernel< Tin > &kernel, int n)
Constructor of tabulated kernel.
T operator()(double x) const override
Evaluate kernel at given location in [-halfwidth, halfwidth].
Definition Kernels.icc:139
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5