Mercurial > octave
annotate libinterp/corefcn/fft.cc @ 27919:1891570abac8
update Octave Project Developers copyright for the new year
In files that have the "Octave Project Developers" copyright notice,
update for 2020.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 06 Jan 2020 22:29:51 -0500 |
parents | b442ec6dda5c |
children | bd51beb6205e |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
27919
1891570abac8
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
27918
diff
changeset
|
3 Copyright (C) 1996-2020 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
5 See the file COPYRIGHT.md in the top-level directory of this distribution |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
6 or <https://octave.org/COPYRIGHT.html/>. |
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
7 |
2928 | 8 |
9 This file is part of Octave. | |
10 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
11 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22701
diff
changeset
|
12 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
13 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22701
diff
changeset
|
14 (at your option) any later version. |
2928 | 15 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22701
diff
changeset
|
16 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22701
diff
changeset
|
17 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22701
diff
changeset
|
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22701
diff
changeset
|
19 GNU General Public License for more details. |
2928 | 20 |
21 You should have received a copy of the GNU General Public License | |
7016 | 22 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23582
diff
changeset
|
23 <https://www.gnu.org/licenses/>. |
2928 | 24 |
25 */ | |
26 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21660
diff
changeset
|
27 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
28 # include "config.h" |
2928 | 29 #endif |
30 | |
31 #include "lo-mappers.h" | |
32 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
33 #include "defun.h" |
2928 | 34 #include "error.h" |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
35 #include "errwarn.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20918
diff
changeset
|
36 #include "ovl.h" |
2928 | 37 #include "utils.h" |
38 | |
4773 | 39 static octave_value |
23433
c9fab0bc983e
maint: Use convention 'int& x' for naming references.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
40 do_fft (const octave_value_list& args, const char *fcn, int type) |
2928 | 41 { |
42 int nargin = args.length (); | |
43 | |
4773 | 44 if (nargin < 1 || nargin > 3) |
20802
8bb38ba1bad6
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20555
diff
changeset
|
45 print_usage (); |
2928 | 46 |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
47 octave_value retval; |
2928 | 48 octave_value arg = args(0); |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
49 octave_idx_type n_points = -1; |
4773 | 50 dim_vector dims = arg.dims (); |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
51 int ndims = dims.ndims (); |
4773 | 52 int dim = -1; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
53 |
4773 | 54 if (nargin > 1) |
55 { | |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23433
diff
changeset
|
56 if (! args(1).isempty ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
57 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
58 double dval = args(1).double_value (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
59 if (octave::math::isnan (dval)) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
60 error ("%s: number of points (N) cannot be NaN", fcn); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
61 |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
62 n_points = octave::math::nint_big (dval); |
20918
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
63 if (n_points < 0) |
6f0bd96f93c0
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20853
diff
changeset
|
64 error ("%s: number of points (N) must be greater than zero", fcn); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
65 } |
4773 | 66 } |
2928 | 67 |
4773 | 68 if (nargin > 2) |
2928 | 69 { |
4773 | 70 double dval = args(2).double_value (); |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
71 if (octave::math::isnan (dval)) |
11553
01f703952eff
Improve docstrings for functions in DLD-FUNCTIONS directory.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
72 error ("%s: DIM cannot be NaN", fcn); |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
73 else if (dval < 1 || dval > ndims) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 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
|
75 fcn); |
2928 | 76 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
77 // to be safe, cast it back to int since dim is an int |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
78 dim = octave::math::nint (dval) - 1; |
2928 | 79 } |
80 | |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
81 // FIXME: This seems strange and unnecessary (10/21/16). |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
82 // How would you ever arrive at an octave_value object without correct dims? |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
83 // We certainly don't make this check every other place in Octave. |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
84 for (octave_idx_type i = 0; i < ndims; i++) |
4773 | 85 if (dims(i) < 0) |
2928 | 86 return retval; |
87 | |
4773 | 88 if (dim < 0) |
4869 | 89 { |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
90 dim = dims.first_non_singleton (); |
4869 | 91 |
92 // And if the first argument is scalar? | |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
93 if (dim == ndims) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
94 dim = 1; |
4869 | 95 } |
2928 | 96 |
4773 | 97 if (n_points < 0) |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
98 n_points = dims(dim); |
4773 | 99 else |
20218
b2100e1659ac
maint: Use cuddled parentheses when indexing dimension_vectors.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
100 dims(dim) = n_points; |
4773 | 101 |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
102 if (n_points == 0 || dims.any_zero ()) |
7924 | 103 { |
104 if (arg.is_single_type ()) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
105 return octave_value (FloatNDArray (dims)); |
7924 | 106 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
107 return octave_value (NDArray (dims)); |
7924 | 108 } |
2928 | 109 |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
110 if (n_points == 1) |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
111 { |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
112 octave_value_list idx (ndims); |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
113 for (octave_idx_type i = 0; i < ndims; i++) |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
114 idx(i) = idx_vector::colon; |
22701
8e71fd674bcf
maint: libinterp/corefcn/fft.cc: minor style fixes for C++ code.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents:
22700
diff
changeset
|
115 idx(dim) = idx_vector (static_cast<octave_idx_type> (0)); |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
116 |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
117 return arg.do_index_op (idx); |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
118 } |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
119 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
120 if (arg.is_single_type ()) |
2928 | 121 { |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
122 if (arg.isreal ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
123 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
124 FloatNDArray nda = arg.float_array_value (); |
2928 | 125 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
126 nda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
127 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
|
128 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
129 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
130 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
131 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
2928 | 132 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
133 cnda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
134 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
|
135 } |
2928 | 136 } |
137 else | |
138 { | |
23582
0cc2011d800e
maint: Deprecate is_real_type and replace with isreal.
Rik <rik@octave.org>
parents:
23581
diff
changeset
|
139 if (arg.isreal ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
140 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
141 NDArray nda = arg.array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
142 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
143 nda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
144 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
|
145 } |
23581
c3075ae020e1
maint: Deprecate is_complex_type and replace with iscomplex.
Rik <rik@octave.org>
parents:
23577
diff
changeset
|
146 else if (arg.iscomplex ()) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
147 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9523
diff
changeset
|
148 ComplexNDArray cnda = arg.complex_array_value (); |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
149 |
20555
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
150 cnda.resize (dims, 0.0); |
f90c8372b7ba
eliminate many more simple uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20218
diff
changeset
|
151 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
|
152 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
153 else |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
20940
diff
changeset
|
154 err_wrong_type_arg (fcn, arg); |
2928 | 155 } |
156 | |
157 return retval; | |
158 } | |
159 | |
6620 | 160 /* |
25586 | 161 %!testif HAVE_FFTW |
162 %! assert (fft ([]), []) | |
163 %!testif HAVE_FFTW | |
164 %! assert (fft (zeros (10,0)), zeros (10,0)) | |
165 %!testif HAVE_FFTW | |
166 %! assert (fft (zeros (0,10)), zeros (0,10)) | |
167 %!testif HAVE_FFTW | |
168 %! assert (fft (0), 0) | |
169 %!testif HAVE_FFTW | |
170 %! assert (fft (1), 1) | |
171 %!testif HAVE_FFTW | |
172 %! assert (fft (ones (2,2)), [2,2; 0,0]) | |
173 %!testif HAVE_FFTW | |
174 %! assert (fft (eye (2,2)), [1,1; 1,-1]) | |
6620 | 175 |
25586 | 176 %!testif HAVE_FFTW |
177 %! assert (fft (single ([])), single ([])) | |
178 %!testif HAVE_FFTW | |
179 %! assert (fft (zeros (10,0,"single")), zeros (10,0,"single")) | |
180 %!testif HAVE_FFTW | |
181 %! assert (fft (zeros (0,10,"single")), zeros (0,10,"single")) | |
182 %!testif HAVE_FFTW | |
183 %! assert (fft (single (0)), single (0)) | |
184 %!testif HAVE_FFTW | |
185 %! assert (fft (single (1)), single (1)) | |
186 %!testif HAVE_FFTW | |
187 %! assert (fft (ones (2,2,"single")), single ([2,2; 0,0])) | |
188 %!testif HAVE_FFTW | |
189 %! assert (fft (eye (2,2,"single")), single ([1,1; 1,-1])) | |
6620 | 190 |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
191 %!error (fft ()) |
6620 | 192 */ |
193 | |
4773 | 194 |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
195 DEFUN (fft, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
196 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
197 @deftypefn {} {} fft (@var{x}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
198 @deftypefnx {} {} fft (@var{x}, @var{n}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
199 @deftypefnx {} {} fft (@var{x}, @var{n}, @var{dim}) |
24575
93714122ed59
doc: Fixes for signal, image, audio, and OOP chapters (bug #52844).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
200 Compute the discrete Fourier transform of @var{x} using |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
201 a Fast Fourier Transform (FFT) algorithm. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
202 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
203 The FFT is calculated along the first non-singleton dimension of the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
204 array. Thus if @var{x} is a matrix, @code{fft (@var{x})} computes the |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
205 FFT for each column of @var{x}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
206 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
207 If called with two arguments, @var{n} is expected to be an integer |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
208 specifying the number of elements of @var{x} to use, or an empty |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
209 matrix to specify that its value should be ignored. If @var{n} is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
210 larger than the dimension along which the FFT is calculated, then |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
211 @var{x} is resized and padded with zeros. Otherwise, if @var{n} is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
212 smaller than the dimension along which the FFT is calculated, then |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
213 @var{x} is truncated. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
214 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
215 If called with three arguments, @var{dim} is an integer specifying the |
24575
93714122ed59
doc: Fixes for signal, image, audio, and OOP chapters (bug #52844).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
216 dimension of the matrix along which the FFT is performed. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
217 @seealso{ifft, fft2, fftn, fftw} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
218 @end deftypefn */) |
4773 | 219 { |
4782 | 220 return do_fft (args, "fft", 0); |
4773 | 221 } |
222 | |
223 | |
15039
e753177cde93
maint: Move non-dynamically linked functions from DLD-FUNCTIONS/ to corefcn/ directory
Rik <rik@octave.org>
parents:
14854
diff
changeset
|
224 DEFUN (ifft, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
225 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
226 @deftypefn {} {} ifft (@var{x}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
227 @deftypefnx {} {} ifft (@var{x}, @var{n}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
228 @deftypefnx {} {} ifft (@var{x}, @var{n}, @var{dim}) |
24575
93714122ed59
doc: Fixes for signal, image, audio, and OOP chapters (bug #52844).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
229 Compute the inverse discrete Fourier transform of @var{x} |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
230 using a Fast Fourier Transform (FFT) algorithm. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
231 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
232 The inverse FFT is calculated along the first non-singleton dimension |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
233 of the array. Thus if @var{x} is a matrix, @code{fft (@var{x})} computes |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
234 the inverse FFT for each column of @var{x}. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
235 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
236 If called with two arguments, @var{n} is expected to be an integer |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
237 specifying the number of elements of @var{x} to use, or an empty |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
238 matrix to specify that its value should be ignored. If @var{n} is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
239 larger than the dimension along which the inverse FFT is calculated, then |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
240 @var{x} is resized and padded with zeros. Otherwise, if @var{n} is |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
241 smaller than the dimension along which the inverse FFT is calculated, |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
242 then @var{x} is truncated. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
243 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
244 If called with three arguments, @var{dim} is an integer specifying the |
24575
93714122ed59
doc: Fixes for signal, image, audio, and OOP chapters (bug #52844).
Rik <rik@octave.org>
parents:
23219
diff
changeset
|
245 dimension of the matrix along which the inverse FFT is performed. |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
246 @seealso{fft, ifft2, ifftn, fftw} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
247 @end deftypefn */) |
4773 | 248 { |
4782 | 249 return do_fft (args, "ifft", 1); |
4773 | 250 } |
251 | |
2928 | 252 /* |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
253 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
254 ## Comalco Research and Technology |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
255 ## 02 May 2000 |
25586 | 256 %!testif HAVE_FFTW |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
257 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
258 %! n = 4; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
259 %! 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
|
260 %! s = cos (n*t); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
261 %! S = fft (s); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
262 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
263 %! answer = zeros (size (t)); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
264 %! 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
|
265 %! 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
|
266 %! |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
267 %! assert (S, answer, 4*N*eps); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
268 |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
269 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
270 ## Comalco Research and Technology |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
271 ## 02 May 2000 |
25586 | 272 %!testif HAVE_FFTW |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
273 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
274 %! n = 7; |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
275 %! 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
|
276 %! s = cos (n*t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
277 %! |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
278 %! S = zeros (size (t)); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
279 %! S(n+1) = N/2; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
280 %! S(N-n+1) = N/2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
281 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
282 %! 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
|
283 |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
284 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
285 ## Comalco Research and Technology |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
286 ## 02 May 2000 |
25586 | 287 %!testif HAVE_FFTW |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
288 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
289 %! 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
|
290 %! 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
|
291 %! s = cos (n*t); |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
292 %! S = fft (s); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
293 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
294 %! 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
|
295 %! 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
|
296 %! answer(N-n+1) = N/2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
297 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
298 %! 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
|
299 |
22662
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
300 ## Author: David Billinghurst (David.Billinghurst@riotinto.com.au) |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
301 ## Comalco Research and Technology |
655157b34a9f
Fix segfault when calling fft on last dimension (bug #49026).
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
302 ## 02 May 2000 |
25586 | 303 %!testif HAVE_FFTW |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
304 %! N = 64; |
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
305 %! 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
|
306 %! 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
|
307 %! s = cos (n*t); |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
308 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
309 %! 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
|
310 %! 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
|
311 %! S(N-n+1) = N/2; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
312 %! |
14501
60e5cf354d80
Update %!tests in DLD-FUNCTIONS/ directory with Octave coding conventions.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
313 %! 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
|
314 */ |