Mercurial > octave
annotate src/DLD-FUNCTIONS/fft.cc @ 9064:7c02ec148a3c
Check grammar on all .cc files
Same check as previously done on .m files
Attempt to enforce some conformity in documentation text for rules
such as two spaces after a period, commas around latin abbreviations, etc.
author | Rik <rdrider0-list@yahoo.com> |
---|---|
date | Sat, 28 Mar 2009 13:57:22 -0700 |
parents | eb63fbe60fab |
children | bd8e388043c4 |
rev | line source |
---|---|
2928 | 1 /* |
2 | |
8920 | 3 Copyright (C) 1997, 1999, 2002, 2004, 2005, 2006, 2007, 2008 David Bateman |
2928 | 4 Copyright (C) 1996, 1997 John W. Eaton |
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 | |
30 #include "defun-dld.h" | |
31 #include "error.h" | |
32 #include "gripes.h" | |
33 #include "oct-obj.h" | |
34 #include "utils.h" | |
35 | |
4773 | 36 #if defined (HAVE_FFTW3) |
37 #define FFTSRC "@sc{Fftw}" | |
38 #else | |
39 #define FFTSRC "@sc{Fftpack}" | |
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; |
59 | |
60 if (nargin > 1) | |
61 { | |
62 if (! args(1).is_empty ()) | |
63 { | |
64 double dval = args(1).double_value (); | |
65 if (xisnan (dval)) | |
66 error ("%s: NaN is invalid as the N_POINTS", fcn); | |
67 else | |
68 { | |
5275 | 69 n_points = NINTbig (dval); |
4773 | 70 if (n_points < 0) |
71 error ("%s: number of points must be greater than zero", fcn); | |
72 } | |
73 } | |
74 } | |
2928 | 75 |
4773 | 76 if (error_state) |
77 return retval; | |
78 | |
79 if (nargin > 2) | |
2928 | 80 { |
4773 | 81 double dval = args(2).double_value (); |
2928 | 82 if (xisnan (dval)) |
4773 | 83 error ("%s: NaN is invalid as the N_POINTS", fcn); |
84 else if (dval < 1 || dval > dims.length ()) | |
85 error ("%s: invalid dimension along which to perform fft", fcn); | |
2928 | 86 else |
5275 | 87 // to be safe, cast it back to int since dim is an int |
4773 | 88 dim = NINT (dval) - 1; |
2928 | 89 } |
90 | |
91 if (error_state) | |
92 return retval; | |
93 | |
5275 | 94 for (octave_idx_type i = 0; i < dims.length (); i++) |
4773 | 95 if (dims(i) < 0) |
2928 | 96 return retval; |
97 | |
4773 | 98 if (dim < 0) |
4869 | 99 { |
5275 | 100 for (octave_idx_type i = 0; i < dims.length (); i++) |
6620 | 101 if (dims(i) > 1) |
4869 | 102 { |
103 dim = i; | |
104 break; | |
105 } | |
106 | |
107 // And if the first argument is scalar? | |
108 if (dim < 0) | |
109 dim = 1; | |
110 } | |
2928 | 111 |
4773 | 112 if (n_points < 0) |
113 n_points = dims (dim); | |
114 else | |
115 dims (dim) = n_points; | |
116 | |
6620 | 117 if (dims.any_zero () || n_points == 0) |
7924 | 118 { |
119 if (arg.is_single_type ()) | |
120 return octave_value (FloatNDArray (dims)); | |
121 else | |
122 return octave_value (NDArray (dims)); | |
123 } | |
2928 | 124 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
125 if (arg.is_single_type ()) |
2928 | 126 { |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
127 if (arg.is_real_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
128 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
129 FloatNDArray nda = arg.float_array_value (); |
2928 | 130 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
131 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
132 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
133 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
134 retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
135 } |
2928 | 136 } |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
137 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
138 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
139 FloatComplexNDArray cnda = arg.float_complex_array_value (); |
2928 | 140 |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
141 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
142 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
143 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
144 retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
145 } |
2928 | 146 } |
147 } | |
148 else | |
149 { | |
7789
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
150 if (arg.is_real_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
151 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
152 NDArray nda = arg.array_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
153 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
154 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
155 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
156 nda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
157 retval = (type != 0 ? nda.ifourier (dim) : nda.fourier (dim)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
158 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
159 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
160 else if (arg.is_complex_type ()) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
161 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
162 ComplexNDArray cnda = arg.complex_array_value (); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
163 |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
164 if (! error_state) |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
165 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
166 cnda.resize (dims, 0.0); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
167 retval = (type != 0 ? cnda.ifourier (dim) : cnda.fourier (dim)); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
168 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
169 } |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
170 else |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
171 { |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
172 gripe_wrong_type_arg (fcn, arg); |
82be108cc558
First attempt at single precision tyeps
David Bateman <dbateman@free.fr>
parents:
7562
diff
changeset
|
173 } |
2928 | 174 } |
175 | |
176 return retval; | |
177 } | |
178 | |
6620 | 179 /* |
180 | |
181 %!error(fft()) | |
182 %!assert(fft([]), []) | |
6621 | 183 %!assert(fft(zeros(10,0)), zeros(10,0)) |
184 %!assert(fft(zeros(0,10)), zeros(0,10)) | |
6620 | 185 %!assert(fft(0), 0) |
186 %!assert(fft(1), 1) | |
187 %!assert(fft(ones(2,2)), [2,2; 0,0]) | |
188 %!assert(fft(eye(2,2)), [1,1; 1,-1]) | |
189 | |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
190 %!assert(fft(single([])), single([])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
191 %!assert(fft(zeros(10,0,'single')), zeros(10,0,'single')) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
192 %!assert(fft(zeros(0,10,'single')), zeros(0,10,'single')) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
193 %!assert(fft(single(0)), single(0)) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
194 %!assert(fft(single(1)), single(1)) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
195 %!assert(fft(ones(2,2,'single')), single([2,2; 0,0])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
196 %!assert(fft(eye(2,2,'single')), single([1,1; 1,-1])) |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
197 |
6620 | 198 */ |
199 | |
4773 | 200 |
201 DEFUN_DLD (fft, args, , | |
202 "-*- texinfo -*-\n\ | |
203 @deftypefn {Loadable Function} {} fft (@var{a}, @var{n}, @var{dim})\n\ | |
204 Compute the FFT of @var{a} using subroutines from\n" | |
205 FFTSRC | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
206 ". The FFT is calculated along the first non-singleton dimension of the\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
207 array. Thus if @var{a} is a matrix, @code{fft (@var{a})} computes the\n\ |
4773 | 208 FFT for each column of @var{a}.\n\ |
209 \n\ | |
210 If called with two arguments, @var{n} is expected to be an integer\n\ | |
211 specifying the number of elements of @var{a} to use, or an empty\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
212 matrix to specify that its value should be ignored. If @var{n} is\n\ |
4773 | 213 larger than the dimension along which the FFT is calculated, then\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
214 @var{a} is resized and padded with zeros. Otherwise, if @var{n} is\n\ |
4773 | 215 smaller than the dimension along which the FFT is calculated, then\n\ |
216 @var{a} is truncated.\n\ | |
217 \n\ | |
5448 | 218 If called with three arguments, @var{dim} is an integer specifying the\n\ |
4773 | 219 dimension of the matrix along which the FFT is performed\n\ |
6971 | 220 @seealso{ifft, fft2, fftn, fftw}\n\ |
5642 | 221 @end deftypefn") |
4773 | 222 { |
4782 | 223 return do_fft (args, "fft", 0); |
4773 | 224 } |
225 | |
226 | |
227 DEFUN_DLD (ifft, args, , | |
228 "-*- texinfo -*-\n\ | |
229 @deftypefn {Loadable Function} {} ifft (@var{a}, @var{n}, @var{dim})\n\ | |
230 Compute the inverse FFT of @var{a} using subroutines from\n" | |
231 FFTSRC | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
232 ". The inverse FFT is calculated along the first non-singleton dimension\n\ |
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
233 of the array. Thus if @var{a} is a matrix, @code{fft (@var{a})} computes\n\ |
4773 | 234 the inverse FFT for each column of @var{a}.\n\ |
235 \n\ | |
236 If called with two arguments, @var{n} is expected to be an integer\n\ | |
237 specifying the number of elements of @var{a} to use, or an empty\n\ | |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
238 matrix to specify that its value should be ignored. If @var{n} is\n\ |
4773 | 239 larger than the dimension along which the inverse FFT is calculated, then\n\ |
9064
7c02ec148a3c
Check grammar on all .cc files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
240 @var{a} is resized and padded with zeros. Otherwise, if@var{n} is\n\ |
4773 | 241 smaller than the dimension along which the inverse FFT is calculated,\n\ |
242 then @var{a} is truncated.\n\ | |
243 \n\ | |
7001 | 244 If called with three arguments, @var{dim} is an integer specifying the\n\ |
4773 | 245 dimension of the matrix along which the inverse FFT is performed\n\ |
6971 | 246 @seealso{fft, ifft2, ifftn, fftw}\n\ |
5642 | 247 @end deftypefn") |
4773 | 248 { |
4782 | 249 return do_fft (args, "ifft", 1); |
4773 | 250 } |
251 | |
2928 | 252 /* |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
253 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
254 %% 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
|
255 %% Comalco Research and Technology |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
256 %% 02 May 2000 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
257 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
258 %! N=64; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
259 %! n=4; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
260 %! t = 2*pi*(0:1:N-1)/N; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
261 %! s = cos(n*t); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
262 %! S = fft(s); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
263 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
264 %! answer = zeros (size(t)); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
265 %! answer(n+1) = N/2; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
266 %! answer(N-n+1) = N/2; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
267 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
268 %! assert(S, answer, 4*N*eps); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
269 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
270 %% 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
|
271 %% Comalco Research and Technology |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
272 %% 02 May 2000 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
273 %!test |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
274 %! N=64; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
275 %! n=7; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
276 %! t = 2*pi*(0:1:N-1)/N; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
277 %! s = cos(n*t); |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
278 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
279 %! S = zeros (size(t)); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
280 %! S(n+1) = N/2; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
281 %! S(N-n+1) = N/2; |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
282 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
283 %! 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
|
284 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
285 %% 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
|
286 %% Comalco Research and Technology |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
287 %% 02 May 2000 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
288 %!test |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
289 %! N=64; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
290 %! n=4; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
291 %! t = single (2*pi*(0:1:N-1)/N); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
292 %! s = cos(n*t); |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
293 %! S = fft(s); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
294 %! |
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 = zeros (size(t),'single'); |
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+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
|
297 %! answer(N-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 %! |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
299 %! 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
|
300 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
301 %% 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
|
302 %% Comalco Research and Technology |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
303 %% 02 May 2000 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
304 %!test |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
305 %! N=64; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
306 %! n=7; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
307 %! t = 2*pi*(0:1:N-1)/N; |
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
308 %! s = cos(n*t); |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
309 %! |
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 = zeros (size(t),'single'); |
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+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
|
312 %! S(N-n+1) = N/2; |
7562
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
313 %! |
7814
87865ed7405f
Second set of single precision test code and fix of resulting bugs
David Bateman <dbateman@free.fr>
parents:
7789
diff
changeset
|
314 %! 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
|
315 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
316 */ |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
317 |
c827f5673321
move tests to individual source files
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
318 /* |
2928 | 319 ;;; Local Variables: *** |
320 ;;; mode: C++ *** | |
321 ;;; End: *** | |
322 */ |