Mercurial > octave-nkf
annotate libinterp/corefcn/fft.cc @ 20614:10ec79b47808
use new string_value method to handle value extraction errors
* __voronoi__.cc, chol.cc, colamd.cc, fftw.cc:
Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 18:15:56 -0400 |
parents | f90c8372b7ba |
children |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17787
diff
changeset
|
3 Copyright (C) 1997-2015 David Bateman |
11523 | 4 Copyright (C) 1996-1997 John W. Eaton |
2928 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2928 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2928 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
28 #include "lo-mappers.h" | |
29 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
30 #include "defun.h" |
2928 | 31 #include "error.h" |
32 #include "gripes.h" | |
33 #include "oct-obj.h" | |
34 #include "utils.h" | |
35 | |
9523
0ce82753dd72
more configure changes for libraries
John W. Eaton <jwe@octave.org>
parents:
9072
diff
changeset
|
36 #if defined (HAVE_FFTW) |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
37 #define FFTSRC "@sc{fftw}" |
4773 | 38 #else |
9072
bd8e388043c4
Cleanup documentation for signal.texi, image.texi, audio.texi
Rik <rdrider0-list@yahoo.com>
parents:
9064
diff
changeset
|
39 #define FFTSRC "@sc{fftpack}" |
4773 | 40 #endif |
2928 | 41 |
4773 | 42 static octave_value |
43 do_fft (const octave_value_list &args, const char *fcn, int type) | |
2928 | 44 { |
4233 | 45 octave_value retval; |
2928 | 46 |
47 int nargin = args.length (); | |
48 | |
4773 | 49 if (nargin < 1 || nargin > 3) |
2928 | 50 { |
5823 | 51 print_usage (); |
2928 | 52 return retval; |
53 } | |
54 | |
55 octave_value arg = args(0); | |
4773 | 56 dim_vector dims = arg.dims (); |
5275 | 57 octave_idx_type n_points = -1; |
4773 | 58 int dim = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
59 |
4773 | 60 if (nargin > 1) |
61 { | |
62 if (! args(1).is_empty ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
63 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
64 double dval = args(1).double_value (); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
65 if (xisnan (dval)) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
66 error ("%s: number of points (N) cannot be NaN", fcn); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
67 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
68 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
69 n_points = NINTbig (dval); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
70 if (n_points < 0) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
71 error ("%s: number of points (N) must be greater than zero", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
72 fcn); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
73 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
74 } |
4773 | 75 } |
2928 | 76 |
4773 | 77 if (nargin > 2) |
2928 | 78 { |
4773 | 79 double dval = args(2).double_value (); |
2928 | 80 if (xisnan (dval)) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
81 error ("%s: DIM cannot be NaN", fcn); |
4773 | 82 else if (dval < 1 || dval > dims.length ()) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
83 error ("%s: DIM must be a valid dimension along which to perform FFT", |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
84 fcn); |
2928 | 85 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
86 // to be safe, cast it back to int since dim is an int |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
87 dim = NINT (dval) - 1; |
2928 | 88 } |
89 | |
5275 | 90 for (octave_idx_type i = 0; i < dims.length (); i++) |
4773 | 91 if (dims(i) < 0) |
2928 | 92 return retval; |
93 | |
4773 | 94 if (dim < 0) |
4869 | 95 { |
5275 | 96 for (octave_idx_type i = 0; i < dims.length (); i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
97 if (dims(i) > 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
98 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
99 dim = i; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
100 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
101 } |
4869 | 102 |
103 // And if the first argument is scalar? | |
104 if (dim < 0) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
105 dim = 1; |
4869 | 106 } |
2928 | 107 |
4773 | 108 if (n_points < 0) |
20253
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
109 n_points = dims(dim); |
4773 | 110 else |
20253
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19731
diff
changeset
|
111 dims(dim) = n_points; |
4773 | 112 |
6620 | 113 if (dims.any_zero () || n_points == 0) |
7924 | 114 { |
115 if (arg.is_single_type ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
116 return octave_value (FloatNDArray (dims)); |
7924 | 117 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
118 return octave_value (NDArray (dims)); |
7924 | 119 } |
2928 | 120 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
121 if (arg.is_single_type ()) |
2928 | 122 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
123 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
124 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
125 FloatNDArray nda = arg.float_array_value (); |
2928 | 126 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
127 nda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
128 retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
129 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
130 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
131 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
132 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
2928 | 133 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
134 cnda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
135 retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
136 } |
2928 | 137 } |
138 else | |
139 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
140 if (arg.is_real_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
141 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
142 NDArray nda = arg.array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
143 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
144 nda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
145 retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
146 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
147 else if (arg.is_complex_type ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
148 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
149 ComplexNDArray cnda = arg.complex_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
150 |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
151 cnda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
152 retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim)); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
153 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
154 else |
20587
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20253
diff
changeset
|
155 gripe_wrong_type_arg (fcn, arg); |
2928 | 156 } |
157 | |
158 return retval; | |
159 } | |
160 | |
6620 | 161 /* |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
162 %!assert (fft ([]), []) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
163 %!assert (fft (zeros (10,0)), zeros (10,0)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
164 %!assert (fft (zeros (0,10)), zeros (0,10)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
165 %!assert (fft (0), 0) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
166 %!assert (fft (1), 1) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
167 %!assert (fft (ones (2,2)), [2,2; 0,0]) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
168 %!assert (fft (eye (2,2)), [1,1; 1,-1]) |
6620 | 169 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
170 %!assert (fft (single ([])), single ([])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
171 %!assert (fft (zeros (10,0,"single")), zeros (10,0,"single")) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
172 %!assert (fft (zeros (0,10,"single")), zeros (0,10,"single")) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
173 %!assert (fft (single (0)), single (0)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
174 %!assert (fft (single (1)), single (1)) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
175 %!assert (fft (ones (2,2,"single")), single ([2,2; 0,0])) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
176 %!assert (fft (eye (2,2,"single")), single ([1,1; 1,-1])) |
6620 | 177 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
178 %!error (fft ()) |
6620 | 179 */ |
180 | |
4773 | 181 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
182 DEFUN (fft, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
183 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
184 @deftypefn {Built-in Function} {} fft (@var{x})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
185 @deftypefnx {Built-in Function} {} fft (@var{x}, @var{n})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
186 @deftypefnx {Built-in Function} {} fft (@var{x}, @var{n}, @var{dim})\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
187 Compute the discrete Fourier transform of @var{A} using\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
188 a Fast Fourier Transform (FFT) algorithm.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
189 \n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
190 The FFT is calculated along the first non-singleton dimension of the\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
191 array. Thus if @var{x} is a matrix, @code{fft (@var{x})} computes the\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
192 FFT for each column of @var{x}.\n\ |
4773 | 193 \n\ |
194 If called with two arguments, @var{n} is expected to be an integer\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
195 specifying the number of elements of @var{x} to use, or an empty\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
196 matrix to specify that its value should be ignored. If @var{n} is\n\ |
4773 | 197 larger than the dimension along which the FFT is calculated, then\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
198 @var{x} is resized and padded with zeros. Otherwise, if @var{n} is\n\ |
4773 | 199 smaller than the dimension along which the FFT is calculated, then\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
200 @var{x} is truncated.\n\ |
4773 | 201 \n\ |
5448 | 202 If called with three arguments, @var{dim} is an integer specifying the\n\ |
4773 | 203 dimension of the matrix along which the FFT is performed\n\ |
6971 | 204 @seealso{ifft, fft2, fftn, fftw}\n\ |
5642 | 205 @end deftypefn") |
4773 | 206 { |
4782 | 207 return do_fft (args, "fft", 0); |
4773 | 208 } |
209 | |
210 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
211 DEFUN (ifft, args, , |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
212 "-*- texinfo -*-\n\ |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
213 @deftypefn {Built-in Function} {} ifft (@var{x})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
214 @deftypefnx {Built-in Function} {} ifft (@var{x}, @var{n})\n\ |
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
215 @deftypefnx {Built-in Function} {} ifft (@var{x}, @var{n}, @var{dim})\n\ |
12160
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
216 Compute the inverse discrete Fourier transform of @var{A}\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
217 using a Fast Fourier Transform (FFT) algorithm.\n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
218 \n\ |
b64b82721062
Make documentation static by removing docstrings depending on #ifdef variables
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
219 The inverse FFT is calculated along the first non-singleton dimension\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
220 of the array. Thus if @var{x} is a matrix, @code{fft (@var{x})} computes\n\ |
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
221 the inverse FFT for each column of @var{x}.\n\ |
4773 | 222 \n\ |
223 If called with two arguments, @var{n} is expected to be an integer\n\ | |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
224 specifying the number of elements of @var{x} to use, or an empty\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
225 matrix to specify that its value should be ignored. If @var{n} is\n\ |
4773 | 226 larger than the dimension along which the inverse FFT is calculated, then\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
227 @var{x} is resized and padded with zeros. Otherwise, if @var{n} is\n\ |
4773 | 228 smaller than the dimension along which the inverse FFT is calculated,\n\ |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
229 then @var{x} is truncated.\n\ |
4773 | 230 \n\ |
7001 | 231 If called with three arguments, @var{dim} is an integer specifying the\n\ |
4773 | 232 dimension of the matrix along which the inverse FFT is performed\n\ |
6971 | 233 @seealso{fft, ifft2, ifftn, fftw}\n\ |
5642 | 234 @end deftypefn") |
4773 | 235 { |
4782 | 236 return do_fft (args, "ifft", 1); |
4773 | 237 } |
238 | |
2928 | 239 /* |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
240 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
241 %% Comalco Research and Technology |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
242 %% 02 May 2000 |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
243 %!test |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
244 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
245 %! n = 4; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
246 %! t = 2*pi*(0:1:N-1)/N; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
247 %! s = cos (n*t); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
248 %! S = fft (s); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
249 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
250 %! answer = zeros (size (t)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
251 %! answer(n+1) = N/2; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
252 %! answer(N-n+1) = N/2; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
253 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
254 %! assert (S, answer, 4*N*eps); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
255 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
256 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
257 %% Comalco Research and Technology |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
258 %% 02 May 2000 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
259 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
260 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
261 %! n = 7; |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
262 %! t = 2*pi*(0:1:N-1)/N; |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
263 %! s = cos (n*t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
264 %! |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
265 %! S = zeros (size (t)); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
266 %! S(n+1) = N/2; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
267 %! S(N-n+1) = N/2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
268 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
269 %! assert (ifft (S), s, 4*N*eps); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
270 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
271 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
272 %% Comalco Research and Technology |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
273 %% 02 May 2000 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
274 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
275 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
276 %! n = 4; |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
277 %! t = single (2*pi*(0:1:N-1)/N); |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
278 %! s = cos (n*t); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
279 %! S = fft (s); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
280 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
281 %! answer = zeros (size (t), "single"); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
282 %! answer(n+1) = N/2; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
283 %! answer(N-n+1) = N/2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
284 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
285 %! assert (S, answer, 4*N*eps ("single")); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
286 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
287 %% Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
288 %% Comalco Research and Technology |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
289 %% 02 May 2000 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
290 %!test |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
291 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
292 %! n = 7; |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
293 %! t = 2*pi*(0:1:N-1)/N; |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
294 %! s = cos (n*t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
295 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
296 %! S = zeros (size (t), "single"); |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
297 %! S(n+1) = N/2; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
298 %! S(N-n+1) = N/2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
299 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
300 %! assert (ifft (S), s, 4*N*eps ("single")); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
301 */ |