Mercurial > octave-nkf
annotate doc/interpreter/interp.txi @ 8920:eb63fbe60fab
update copyright notices
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 07 Mar 2009 10:41:27 -0500 |
parents | 8463d1a2e544 |
children | e9dc2ed2ec0f |
rev | line source |
---|---|
8920 | 1 @c Copyright (C) 2007, 2008, 2009 John W. Eaton |
7018 | 2 @c |
3 @c This file is part of Octave. | |
4 @c | |
5 @c Octave is free software; you can redistribute it and/or modify it | |
6 @c under the terms of the GNU General Public License as published by the | |
7 @c Free Software Foundation; either version 3 of the License, or (at | |
8 @c your option) any later version. | |
9 @c | |
10 @c Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 @c ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 @c FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 @c for more details. | |
14 @c | |
15 @c You should have received a copy of the GNU General Public License | |
16 @c along with Octave; see the file COPYING. If not, see | |
17 @c <http://www.gnu.org/licenses/>. | |
6549 | 18 |
19 @node Interpolation | |
20 @chapter Interpolation | |
21 | |
6702 | 22 @menu |
23 * One-dimensional Interpolation:: | |
24 * Multi-dimensional Interpolation:: | |
25 @end menu | |
26 | |
27 @node One-dimensional Interpolation | |
28 @section One-dimensional Interpolation | |
6549 | 29 |
6850 | 30 Octave supports several methods for one-dimensional interpolation, most |
31 of which are described in this section. @ref{Polynomial Interpolation} | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
32 and @ref{Interpolation on Scattered Data} describe further methods. |
6850 | 33 |
6549 | 34 @DOCSTRING(interp1) |
35 | |
6721 | 36 There are some important differences between the various interpolation |
37 methods. The 'spline' method enforces that both the first and second | |
38 derivatives of the interpolated values have a continuous derivative, | |
6743 | 39 whereas the other methods do not. This means that the results of the |
40 'spline' method are generally smoother. If the function to be | |
41 interpolated is in fact smooth, then 'spline' will give excellent | |
42 results. However, if the function to be evaluated is in some manner | |
43 discontinuous, then 'pchip' interpolation might give better results. | |
44 | |
45 This can be demonstrated by the code | |
6721 | 46 |
47 @example | |
48 @group | |
6743 | 49 t = -2:2; |
50 dt = 1; | |
51 ti =-2:0.025:2; | |
52 dti = 0.025; | |
53 y = sign(t); | |
54 ys = interp1(t,y,ti,'spline'); | |
55 yp = interp1(t,y,ti,'pchip'); | |
56 ddys = diff(diff(ys)./dti)./dti; | |
57 ddyp = diff(diff(yp)./dti)./dti; | |
58 figure(1); | |
59 plot (ti, ys,'r-', ti, yp,'g-'); | |
60 legend('spline','pchip',4); | |
61 figure(2); | |
62 plot (ti, ddys,'r+', ti, ddyp,'g*'); | |
63 legend('spline','pchip'); | |
6721 | 64 @end group |
65 @end example | |
66 | |
67 @ifnotinfo | |
68 @noindent | |
6743 | 69 The result of which can be seen in @ref{fig:interpderiv1} and |
70 @ref{fig:interpderiv2}. | |
6721 | 71 |
6743 | 72 @float Figure,fig:interpderiv1 |
73 @image{interpderiv1,8cm} | |
74 @caption{Comparison of 'phcip' and 'spline' interpolation methods for a | |
75 step function} | |
76 @end float | |
77 | |
78 @float Figure,fig:interpderiv2 | |
79 @image{interpderiv2,8cm} | |
8325
b93ac0586e4b
spelling corrections
Brian Gough<bjg@network-theory.co.uk>
parents:
7984
diff
changeset
|
80 @caption{Comparison of the second derivative of the 'phcip' and 'spline' |
6743 | 81 interpolation methods for a step function} |
6721 | 82 @end float |
83 @end ifnotinfo | |
84 | |
7984
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
85 A simplified version of @code{interp1} that performs only linear |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
86 interpolation is available in @code{interp1q}. This argument is slightly |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
87 faster than @code{interp1} as to performs little error checking. |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
88 |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
89 @DOCSTRING(interp1q) |
bbaa5d7d0143
Some documentation updates
David Bateman <dbateman@free.fr>
parents:
7018
diff
changeset
|
90 |
6702 | 91 Fourier interpolation, is a resampling technique where a signal is |
92 converted to the frequency domain, padded with zeros and then | |
93 reconverted to the time domain. | |
6549 | 94 |
95 @DOCSTRING(interpft) | |
96 | |
6702 | 97 There are two significant limitations on Fourier interpolation. Firstly, |
8495
e7b4de25ecb6
[docs] non periodic => non-periodic
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
98 the function signal is assumed to be periodic, and so non-periodic |
6702 | 99 signals will be poorly represented at the edges. Secondly, both the |
100 signal and its interpolation are required to be sampled at equispaced | |
101 points. An example of the use of @code{interpft} is | |
6549 | 102 |
6702 | 103 @example |
104 @group | |
105 t = 0 : 0.3 : pi; dt = t(2)-t(1); | |
106 n = length (t); k = 100; | |
107 ti = t(1) + [0 : k-1]*dt*n/k; | |
108 y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
109 yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
110 plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ... | |
111 ti, interpft (y, k), 'c', t, y, 'r+'); | |
112 legend ('sin(4t+0.3)cos(3t-0.1','spline','interpft','data'); | |
113 @end group | |
114 @end example | |
115 | |
8828 | 116 @noindent |
6721 | 117 @ifinfo |
8495
e7b4de25ecb6
[docs] non periodic => non-periodic
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
118 which demonstrates the poor behavior of Fourier interpolation for non-periodic functions. |
6721 | 119 @end ifinfo |
120 @ifnotinfo | |
8495
e7b4de25ecb6
[docs] non periodic => non-periodic
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
121 which demonstrates the poor behavior of Fourier interpolation for non-periodic functions, as can be seen in @ref{fig:interpft}. |
6721 | 122 |
123 @float Figure,fig:interpft | |
124 @image{interpft,8cm} | |
8495
e7b4de25ecb6
[docs] non periodic => non-periodic
Brian Gough <bjg@gnu.org>
parents:
8347
diff
changeset
|
125 @caption{Comparison of @code{interp1} and @code{interpft} for non-periodic data} |
6721 | 126 @end float |
127 @end ifnotinfo | |
6702 | 128 |
129 In additional the support function @code{spline} and @code{lookup} that | |
130 underlie the @code{interp1} function can be called directly. | |
6549 | 131 |
6558 | 132 @DOCSTRING(spline) |
133 | |
8347
fa78cb8d8a5c
corrections for typos
Brian Gough<bjg@network-theory.co.uk>
parents:
8325
diff
changeset
|
134 The @code{lookup} function is used by other interpolation functions to identify |
6702 | 135 the points of the original data that are closest to the current point |
136 of interest. | |
137 | |
6549 | 138 @DOCSTRING(lookup) |
6702 | 139 |
140 @node Multi-dimensional Interpolation | |
141 @section Multi-dimensional Interpolation | |
142 | |
6939 | 143 There are three multi-dimensional interpolation functions in Octave, with |
6850 | 144 similar capabilities. Methods using Delaunay tessellation are described |
145 in @ref{Interpolation on Scattered Data}. | |
6702 | 146 |
147 @DOCSTRING(interp2) | |
148 | |
149 @DOCSTRING(interp3) | |
150 | |
151 @DOCSTRING(interpn) | |
152 | |
153 A significant difference between @code{interpn} and the other two | |
6939 | 154 multidimensional interpolation functions is the fashion in which the |
6702 | 155 dimensions are treated. For @code{interp2} and @code{interp3}, the 'y' |
156 axis is considered to be the columns of the matrix, whereas the 'x' | |
6939 | 157 axis corresponds to the rows of the array. As Octave indexes arrays in |
6702 | 158 column major order, the first dimension of any array is the columns, and |
159 so @code{interpn} effectively reverses the 'x' and 'y' dimensions. | |
160 Consider the example | |
161 | |
162 @example | |
163 @group | |
164 x = y = z = -1:1; | |
165 f = @@(x,y,z) x.^2 - y - z.^2; | |
166 [xx, yy, zz] = meshgrid (x, y, z); | |
167 v = f (xx,yy,zz); | |
6721 | 168 xi = yi = zi = -1:0.1:1; |
6702 | 169 [xxi, yyi, zzi] = meshgrid (xi, yi, zi); |
6721 | 170 vi = interp3(x, y, z, v, xxi, yyi, zzi, 'spline'); |
6702 | 171 [xxi, yyi, zzi] = ndgrid (xi, yi, zi); |
6721 | 172 vi2 = interpn(x, y, z, v, xxi, yyi, zzi, 'spline'); |
6723 | 173 mesh (zi, yi, squeeze (vi2(1,:,:))); |
6702 | 174 @end group |
175 @end example | |
176 | |
177 @noindent | |
178 where @code{vi} and @code{vi2} are identical. The reversal of the | |
179 dimensions is treated in the @code{meshgrid} and @code{ndgrid} functions | |
180 respectively. | |
6721 | 181 @ifnotinfo |
182 The result of this code can be seen in @ref{fig:interpn}. | |
183 | |
184 @float Figure,fig:interpn | |
185 @image{interpn,8cm} | |
186 @caption{Demonstration of the use of @code{interpn}} | |
187 @end float | |
188 @end ifnotinfo | |
6702 | 189 |
190 In additional the support function @code{bicubic} that underlies the | |
191 cubic interpolation of @code{interp2} function can be called directly. | |
192 | |
193 @DOCSTRING(bicubic) |