• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4<title>Whittaker-Shannon interpolation</title>
5<link rel="stylesheet" href="../math.css" type="text/css">
6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7<link rel="home" href="../index.html" title="Math Toolkit 2.12.0">
8<link rel="up" href="../interpolation.html" title="Chapter 12. Interpolation">
9<link rel="prev" href="cardinal_quintic_b.html" title="Cardinal Quintic B-spline interpolation">
10<link rel="next" href="barycentric.html" title="Barycentric Rational Interpolation">
11</head>
12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13<table cellpadding="2" width="100%"><tr>
14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15<td align="center"><a href="../../../../../index.html">Home</a></td>
16<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19<td align="center"><a href="../../../../../more/index.htm">More</a></td>
20</tr></table>
21<hr>
22<div class="spirit-nav">
23<a accesskey="p" href="cardinal_quintic_b.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interpolation.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="barycentric.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
24</div>
25<div class="section">
26<div class="titlepage"><div><div><h2 class="title" style="clear: both">
27<a name="math_toolkit.whittaker_shannon"></a><a class="link" href="whittaker_shannon.html" title="Whittaker-Shannon interpolation">Whittaker-Shannon interpolation</a>
28</h2></div></div></div>
29<h4>
30<a name="math_toolkit.whittaker_shannon.h0"></a>
31      <span class="phrase"><a name="math_toolkit.whittaker_shannon.synopsis"></a></span><a class="link" href="whittaker_shannon.html#math_toolkit.whittaker_shannon.synopsis">Synopsis</a>
32    </h4>
33<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">interpolators</span><span class="special">/</span><span class="identifier">whittaker_shannon</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
34</pre>
35<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">math</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">interpolators</span> <span class="special">{</span>
36
37  <span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">RandomAccessContainer</span><span class="special">&gt;</span>
38  <span class="keyword">class</span> <span class="identifier">whittaker_shannon</span>
39  <span class="special">{</span>
40  <span class="keyword">public</span><span class="special">:</span>
41
42      <span class="keyword">using</span> <span class="identifier">Real</span> <span class="special">=</span> <span class="identifier">RandomAccessContainer</span><span class="special">::</span><span class="identifier">value_type</span><span class="special">;</span>
43
44      <span class="identifier">whittaker_shannon</span><span class="special">(</span><span class="identifier">RandomAccessContainer</span><span class="special">&amp;&amp;</span> <span class="identifier">v</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">left_endpoint</span><span class="special">,</span> <span class="identifier">Real</span> <span class="identifier">step_size</span><span class="special">);</span>
45
46      <span class="identifier">Real</span> <span class="keyword">operator</span><span class="special">()(</span><span class="identifier">Real</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
47
48      <span class="identifier">Real</span> <span class="identifier">prime</span><span class="special">(</span><span class="identifier">Real</span> <span class="identifier">x</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
49  <span class="special">};</span>
50
51<span class="special">}}}</span> <span class="comment">// namespaces</span>
52</pre>
53<h4>
54<a name="math_toolkit.whittaker_shannon.h1"></a>
55      <span class="phrase"><a name="math_toolkit.whittaker_shannon.whittaker_shannon_interpolation"></a></span><a class="link" href="whittaker_shannon.html#math_toolkit.whittaker_shannon.whittaker_shannon_interpolation">Whittaker-Shannon
56      Interpolation</a>
57    </h4>
58<p>
59      The Whittaker-Shannon interpolator takes equispaced data and interpolates between
60      them via a sum of sinc functions. This interpolation is stable and infinitely
61      smooth, but has linear complexity in the data, making it slow relative to compactly-supported
62      b-splines. In addition, we cannot pass an infinite amount of data into the
63      class, and must truncate the (perhaps) infinite sinc series to a finite number
64      of terms. Since the sinc function has slow <span class="emphasis"><em>1/x</em></span> decay,
65      the truncation of the series can incur large error. Hence this interpolator
66      works best when operating on samples of compactly-supported functions. Here
67      is an example of interpolating a smooth "bump function":
68    </p>
69<pre class="programlisting"><span class="keyword">auto</span> <span class="identifier">bump</span> <span class="special">=</span> <span class="special">[](</span><span class="keyword">double</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">if</span> <span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">abs</span><span class="special">(</span><span class="identifier">x</span><span class="special">)</span> <span class="special">&gt;=</span> <span class="number">1</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="number">0.0</span><span class="special">;</span> <span class="special">}</span> <span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">exp</span><span class="special">(-</span><span class="number">1.0</span><span class="special">/(</span><span class="number">1.0</span><span class="special">-</span><span class="identifier">x</span><span class="special">*</span><span class="identifier">x</span><span class="special">));</span> <span class="special">};</span>
70
71<span class="keyword">double</span> <span class="identifier">t0</span> <span class="special">=</span> <span class="special">-</span><span class="number">1</span><span class="special">;</span>
72<span class="identifier">size_t</span> <span class="identifier">n</span> <span class="special">=</span> <span class="number">2049</span><span class="special">;</span>
73<span class="keyword">double</span> <span class="identifier">h</span> <span class="special">=</span> <span class="number">2.0</span><span class="special">/(</span><span class="identifier">n</span><span class="special">-</span><span class="number">1.0</span><span class="special">);</span>
74
75<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">v</span><span class="special">(</span><span class="identifier">n</span><span class="special">);</span>
76<span class="keyword">for</span><span class="special">(</span><span class="identifier">size_t</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special">&lt;</span> <span class="identifier">n</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{</span>
77    <span class="keyword">double</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">t0</span> <span class="special">+</span> <span class="identifier">i</span><span class="special">*</span><span class="identifier">h</span><span class="special">;</span>
78    <span class="identifier">v</span><span class="special">[</span><span class="identifier">i</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">bump</span><span class="special">(</span><span class="identifier">t</span><span class="special">);</span>
79<span class="special">}</span>
80
81<span class="keyword">auto</span> <span class="identifier">ws</span> <span class="special">=</span> <span class="identifier">whittaker_shannon</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">move</span><span class="special">(</span><span class="identifier">v</span><span class="special">),</span> <span class="identifier">t0</span><span class="special">,</span> <span class="identifier">h</span><span class="special">);</span>
82
83<span class="keyword">double</span> <span class="identifier">y</span> <span class="special">=</span> <span class="identifier">ws</span><span class="special">(</span><span class="number">0.3</span><span class="special">);</span>
84</pre>
85<p>
86      The derivative of the interpolant can also be evaluated, but the accuracy is
87      not as high:
88    </p>
89<pre class="programlisting"><span class="keyword">double</span> <span class="identifier">yp</span> <span class="special">=</span> <span class="identifier">ws</span><span class="special">.</span><span class="identifier">prime</span><span class="special">(</span><span class="number">0.3</span><span class="special">);</span>
90</pre>
91<h4>
92<a name="math_toolkit.whittaker_shannon.h2"></a>
93      <span class="phrase"><a name="math_toolkit.whittaker_shannon.complexity_and_performance"></a></span><a class="link" href="whittaker_shannon.html#math_toolkit.whittaker_shannon.complexity_and_performance">Complexity
94      and Performance</a>
95    </h4>
96<p>
97      The call to the constructor requires ��(1) operations, simply moving data into
98      the class. Each call to the interpolant is ��(<span class="emphasis"><em>n</em></span>), where
99      <span class="emphasis"><em>n</em></span> is the number of points to interpolate.
100    </p>
101</div>
102<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
103<td align="left"></td>
104<td align="right"><div class="copyright-footer">Copyright © 2006-2019 Nikhar
105      Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
106      Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
107      Råde, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
108      Daryle Walker and Xiaogang Zhang<p>
109        Distributed under the Boost Software License, Version 1.0. (See accompanying
110        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
111      </p>
112</div></td>
113</tr></table>
114<hr>
115<div class="spirit-nav">
116<a accesskey="p" href="cardinal_quintic_b.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../interpolation.html"><img src="../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="barycentric.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
117</div>
118</body>
119</html>
120