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)
8 [section:whittaker_shannon Whittaker-Shannon interpolation]
12 #include <boost/math/interpolators/whittaker_shannon.hpp>
15 namespace boost { namespace math { namespace interpolators {
17 template <class RandomAccessContainer>
18 class whittaker_shannon
22 using Real = RandomAccessContainer::value_type;
24 whittaker_shannon(RandomAccessContainer&& v, Real left_endpoint, Real step_size);
26 Real operator()(Real x) const;
28 Real prime(Real x) const;
34 [heading Whittaker-Shannon Interpolation]
36 The Whittaker-Shannon interpolator takes equispaced data and interpolates between them via a sum of sinc functions.
37 This interpolation is stable and infinitely smooth, but has linear complexity in the data,
38 making it slow relative to compactly-supported b-splines.
39 In addition, we cannot pass an infinite amount of data into the class,
40 and must truncate the (perhaps) infinite sinc series to a finite number of terms.
41 Since the sinc function has slow /1/x/ decay, the truncation of the series can incur large error.
42 Hence this interpolator works best when operating on samples of compactly-supported functions.
43 Here is an example of interpolating a smooth "bump function":
45 auto bump = [](double x) { if (std::abs(x) >= 1) { return 0.0; } return std::exp(-1.0/(1.0-x*x)); };
49 double h = 2.0/(n-1.0);
51 std::vector<double> v(n);
52 for(size_t i = 0; i < n; ++i) {
57 auto ws = whittaker_shannon(std::move(v), t0, h);
61 The derivative of the interpolant can also be evaluated, but the accuracy is not as high:
63 double yp = ws.prime(0.3);
65 [heading Complexity and Performance]
67 The call to the constructor requires [bigo](1) operations, simply moving data into the class.
68 Each call to the interpolant is [bigo](/n/), where /n/ is the number of points to interpolate.
70 [endsect] [/section:whittaker_shannon]