Mercurial > hg > octave-nkf
annotate scripts/general/interpft.m @ 14119:94e2a76f1e5a stable
doc: Final grammarcheck and spellcheck before 3.6.0 release.
* container.txi, aspell-octave.en.pws, expr.txi, vectorize.txi, accumarray.m,
accumdim.m, interpft.m, strread.m, parseparams.m, warning_ids.m, cellfun.cc,
help.cc: grammarcheck and spellcheck docstrings.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 29 Dec 2011 06:05:00 -0800 |
parents | 5f96b91b4e0c |
children | 72c96de7a403 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2001-2011 Paul Kienzle |
5837 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5837 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5837 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9051
diff
changeset
|
20 ## @deftypefn {Function File} {} interpft (@var{x}, @var{n}) |
5837 | 21 ## @deftypefnx {Function File} {} interpft (@var{x}, @var{n}, @var{dim}) |
22 ## | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
23 ## Fourier interpolation. If @var{x} is a vector, then @var{x} is |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
24 ## resampled with @var{n} points. The data in @var{x} is assumed to be |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
25 ## equispaced. If @var{x} is an array, then operate along each column of |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## the array separately. If @var{dim} is specified, then interpolate |
5837 | 27 ## along the dimension @var{dim}. |
28 ## | |
29 ## @code{interpft} assumes that the interpolated function is periodic, | |
14119
94e2a76f1e5a
doc: Final grammarcheck and spellcheck before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents:
13768
diff
changeset
|
30 ## and so assumptions are made about the endpoints of the interpolation. |
5837 | 31 ## |
32 ## @seealso{interp1} | |
33 ## @end deftypefn | |
34 | |
35 ## Author: Paul Kienzle | |
36 ## 2001-02-11 | |
37 ## * initial version | |
38 ## 2002-03-17 aadler | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
39 ## * added code to work on matrices as well |
5837 | 40 ## 2006-05-25 dbateman |
41 ## * Make it matlab compatiable, cutting out the 2-D interpolation | |
42 | |
43 function z = interpft (x, n, dim) | |
44 | |
45 if (nargin < 2 || nargin > 3) | |
46 print_usage (); | |
47 endif | |
48 | |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
49 if (! (isscalar (n) && n == fix (n))) |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
50 error ("interpft: N must be a scalar integer"); |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
51 endif |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
52 |
5837 | 53 if (nargin == 2) |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
54 if (isrow (x)) |
5837 | 55 dim = 2; |
56 else | |
57 dim = 1; | |
58 endif | |
59 endif | |
60 | |
5838 | 61 nd = ndims (x); |
5837 | 62 |
63 if (dim < 1 || dim > nd) | |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
64 error ("interpft: invalid dimension DIM"); |
5837 | 65 endif |
66 | |
5838 | 67 perm = [dim:nd, 1:(dim-1)]; |
68 x = permute (x, perm); | |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
69 m = rows (x); |
5837 | 70 |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
71 inc = max (1, fix (m/n)); |
5837 | 72 y = fft (x) / m; |
73 k = floor (m / 2); | |
5838 | 74 sz = size (x); |
5837 | 75 sz(1) = n * inc - m; |
12676
2783fa95cab7
Use common code idiom for creating cell array for indexing ND-arrays
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
76 |
2783fa95cab7
Use common code idiom for creating cell array for indexing ND-arrays
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
77 idx = repmat ({':'}, nd, 1); |
5837 | 78 idx{1} = 1:k; |
5838 | 79 z = cat (1, y(idx{:}), zeros (sz)); |
5837 | 80 idx{1} = k+1:m; |
81 z = cat (1, z, y(idx{:})); | |
82 z = n * ifft (z); | |
83 | |
84 if (inc != 1) | |
85 sz(1) = n; | |
5838 | 86 z = inc * reshape (z(1:inc:end), sz); |
5837 | 87 endif |
88 | |
89 z = ipermute (z, perm); | |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
90 |
5837 | 91 endfunction |
92 | |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
93 |
5837 | 94 %!demo |
95 %! t = 0 : 0.3 : pi; dt = t(2)-t(1); | |
96 %! n = length (t); k = 100; | |
97 %! ti = t(1) + [0 : k-1]*dt*n/k; | |
98 %! y = sin (4*t + 0.3) .* cos (3*t - 0.1); | |
99 %! yp = sin (4*ti + 0.3) .* cos (3*ti - 0.1); | |
6702 | 100 %! plot (ti, yp, 'g', ti, interp1(t, y, ti, 'spline'), 'b', ... |
101 %! ti, interpft (y, k), 'c', t, y, 'r+'); | |
102 %! legend ('sin(4t+0.3)cos(3t-0.1','spline','interpft','data'); | |
5837 | 103 |
104 %!shared n,y | |
105 %! x = [0:10]'; y = sin(x); n = length (x); | |
8656
e3041433a57e
increase tolerance in interpft tests
Rob Mahurin <rob@chimera.(none)>
parents:
8138
diff
changeset
|
106 %!assert (interpft(y, n), y, 20*eps); |
e3041433a57e
increase tolerance in interpft tests
Rob Mahurin <rob@chimera.(none)>
parents:
8138
diff
changeset
|
107 %!assert (interpft(y', n), y', 20*eps); |
e3041433a57e
increase tolerance in interpft tests
Rob Mahurin <rob@chimera.(none)>
parents:
8138
diff
changeset
|
108 %!assert (interpft([y,y],n), [y,y], 20*eps); |
5837 | 109 |
13768
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
110 %% Test input validation |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
111 %!error interpft () |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
112 %!error interpft (1) |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
113 %!error interpft (1,2,3) |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
114 %!error (interpft(1,[n,n])) |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
115 %!error (interpft(1,2,0)) |
5f96b91b4e0c
interpft.m: Miscellaneous code cleanup. Add more input validation tests.
Rik <octave@nomad.inbox5.com>
parents:
12676
diff
changeset
|
116 %!error (interpft(1,2,3)) |