math/doc/html/math_toolkit/whittaker_shannon.html
2019-10-31 17:55:35 +00:00

120 lines
12 KiB
HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Whittaker-Shannon interpolation</title>
<link rel="stylesheet" href="../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="Math Toolkit 2.11.0">
<link rel="up" href="../interpolation.html" title="Chapter&#160;12.&#160;Interpolation">
<link rel="prev" href="cardinal_quintic_b.html" title="Cardinal Quintic B-spline interpolation">
<link rel="next" href="barycentric.html" title="Barycentric Rational Interpolation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="math_toolkit.whittaker_shannon"></a><a class="link" href="whittaker_shannon.html" title="Whittaker-Shannon interpolation">Whittaker-Shannon interpolation</a>
</h2></div></div></div>
<h4>
<a name="math_toolkit.whittaker_shannon.h0"></a>
<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>
</h4>
<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>
</pre>
<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>
<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>
<span class="keyword">class</span> <span class="identifier">whittaker_shannon</span>
<span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<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>
<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>
<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>
<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>
<span class="special">};</span>
<span class="special">}}}</span> <span class="comment">// namespaces</span>
</pre>
<h4>
<a name="math_toolkit.whittaker_shannon.h1"></a>
<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
Interpolation</a>
</h4>
<p>
The Whittaker-Shannon interpolator takes equispaced data and interpolates between
them via a sum of sinc functions. This interpolation is stable and infinitely
smooth, but has linear complexity in the data, making it slow relative to compactly-supported
b-splines. In addition, we cannot pass an infinite amount of data into the
class, and must truncate the (perhaps) infinite sinc series to a finite number
of terms. Since the sinc function has slow <span class="emphasis"><em>1/x</em></span> decay,
the truncation of the series can incur large error. Hence this interpolator
works best when operating on samples of compactly-supported functions. Here
is an example of interpolating a smooth "bump function":
</p>
<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>
<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>
<span class="identifier">size_t</span> <span class="identifier">n</span> <span class="special">=</span> <span class="number">2049</span><span class="special">;</span>
<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>
<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>
<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>
<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>
<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>
<span class="special">}</span>
<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>
<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>
</pre>
<p>
The derivative of the interpolant can also be evaluated, but the accuracy is
not as high:
</p>
<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>
</pre>
<h4>
<a name="math_toolkit.whittaker_shannon.h2"></a>
<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
and Performance</a>
</h4>
<p>
The call to the constructor requires &#119926;(1) operations, simply moving data into
the class. Each call to the interpolant is &#119926;(<span class="emphasis"><em>n</em></span>), where
<span class="emphasis"><em>n</em></span> is the number of points to interpolate.
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2006-2019 Nikhar
Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos,
Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Matthew Pulver, Johan
R&#229;de, Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg,
Daryle Walker and Xiaogang Zhang<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
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>)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>