whittaker_shannon.qbk 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. [/
  2. Copyright (c) 2019 Nick Thompson
  3. Use, modification and distribution are subject to the
  4. Boost Software License, Version 1.0. (See accompanying file
  5. LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ]
  7. [section:whittaker_shannon Whittaker-Shannon interpolation]
  8. [heading Synopsis]
  9. ``
  10. #include <boost/math/interpolators/whittaker_shannon.hpp>
  11. ``
  12. namespace boost { namespace math { namespace interpolators {
  13. template <class RandomAccessContainer>
  14. class whittaker_shannon
  15. {
  16. public:
  17. using Real = RandomAccessContainer::value_type;
  18. whittaker_shannon(RandomAccessContainer&& v, Real left_endpoint, Real step_size);
  19. Real operator()(Real x) const;
  20. Real prime(Real x) const;
  21. };
  22. }}} // namespaces
  23. [heading Whittaker-Shannon Interpolation]
  24. The Whittaker-Shannon interpolator takes equispaced data and interpolates between them via a sum of sinc functions.
  25. This interpolation is stable and infinitely smooth, but has linear complexity in the data,
  26. making it slow relative to compactly-supported b-splines.
  27. In addition, we cannot pass an infinite amount of data into the class,
  28. and must truncate the (perhaps) infinite sinc series to a finite number of terms.
  29. Since the sinc function has slow /1/x/ decay, the truncation of the series can incur large error.
  30. Hence this interpolator works best when operating on samples of compactly-supported functions.
  31. Here is an example of interpolating a smooth "bump function":
  32. auto bump = [](double x) { if (std::abs(x) >= 1) { return 0.0; } return std::exp(-1.0/(1.0-x*x)); };
  33. double t0 = -1;
  34. size_t n = 2049;
  35. double h = 2.0/(n-1.0);
  36. std::vector<double> v(n);
  37. for(size_t i = 0; i < n; ++i) {
  38. double t = t0 + i*h;
  39. v[i] = bump(t);
  40. }
  41. auto ws = whittaker_shannon(std::move(v), t0, h);
  42. double y = ws(0.3);
  43. The derivative of the interpolant can also be evaluated, but the accuracy is not as high:
  44. double yp = ws.prime(0.3);
  45. [heading Complexity and Performance]
  46. The call to the constructor requires [bigo](1) operations, simply moving data into the class.
  47. Each call to the interpolant is [bigo](/n/), where /n/ is the number of points to interpolate.
  48. [endsect] [/section:whittaker_shannon]