4773
|
1 /* |
|
2 |
|
3 Copyright (C) 2004 David Bateman |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "lo-mappers.h" |
|
28 |
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "oct-obj.h" |
|
33 #include "utils.h" |
|
34 |
|
35 // This function should be merged with Fifft. |
|
36 |
|
37 #if defined (HAVE_FFTW3) |
|
38 #define FFTSRC "@sc{Fftw}" |
|
39 #define WISDOM ", fft_wisdom" |
|
40 #else |
|
41 #define FFTSRC "@sc{Fftpack}" |
|
42 #define WISDOM |
|
43 #endif |
|
44 |
|
45 static octave_value |
|
46 do_fftn (const octave_value_list &args, const char *fcn, int type) |
|
47 { |
|
48 octave_value retval; |
|
49 |
|
50 int nargin = args.length (); |
|
51 |
|
52 if (nargin < 1 || nargin > 2) |
|
53 { |
|
54 print_usage (fcn); |
|
55 return retval; |
|
56 } |
|
57 |
|
58 octave_value arg = args(0); |
|
59 dim_vector dims = arg.dims (); |
|
60 |
|
61 for (int i = 0; i < dims.length (); i++) |
|
62 if (dims(i) < 0) |
|
63 return retval; |
|
64 |
|
65 if (nargin > 1) |
|
66 { |
|
67 Matrix val = args(1).matrix_value (); |
|
68 if (val.rows () > val.columns ()) |
|
69 val.transpose (); |
|
70 |
|
71 if (val.columns () != dims.length () || val.rows () != 1) |
|
72 error ("%s: second argument must be a vector of length dim", fcn); |
|
73 else |
|
74 { |
|
75 for (int i = 0; i < dims.length (); i++) |
|
76 { |
|
77 if (xisnan (val(i,0))) |
|
78 error ("%s: NaN is invalid as a dimension", fcn); |
|
79 else if (NINT (val(i,0)) < 0) |
|
80 error ("%s: all dimension must be greater than zero", fcn); |
|
81 else |
|
82 { |
|
83 dims(i) = NINT(val(i,0)); |
|
84 } |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 if (error_state) |
|
90 return retval; |
|
91 |
|
92 if (dims.all_zero ()) |
|
93 return octave_value (Matrix ()); |
|
94 |
|
95 if (arg.is_real_type ()) |
|
96 { |
|
97 NDArray nda = arg.array_value (); |
|
98 |
|
99 if (! error_state) |
|
100 { |
|
101 nda.resize (dims, 0.0); |
|
102 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ()); |
|
103 } |
|
104 } |
|
105 else if (arg.is_complex_type ()) |
|
106 { |
|
107 ComplexNDArray cnda = arg.complex_array_value (); |
|
108 |
|
109 if (! error_state) |
|
110 { |
|
111 cnda.resize (dims, 0.0); |
|
112 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ()); |
|
113 } |
|
114 } |
|
115 else |
|
116 { |
|
117 gripe_wrong_type_arg (fcn, arg); |
|
118 } |
|
119 |
|
120 return retval; |
|
121 } |
|
122 |
|
123 DEFUN_DLD (fftn, args, , |
|
124 "-*- texinfo -*-\n\ |
|
125 @deftypefn {Loadable Function} {} fftn (@var{a}, @var{siz})\n\ |
|
126 Compute the N dimensional FFT of @var{a} using subroutines from\n" |
|
127 FFTSRC |
|
128 ". The optional vector argument @var{siz} may be used specify the\n\ |
|
129 dimensions of the array to be used. If an element of @var{siz} is\n\ |
|
130 smaller than the corresponding dimension, then the dimension is\n\ |
|
131 truncated prior to performing the FFT. Otherwise if an element\n\ |
|
132 of @var{siz} is larger than the corresponding dimension @var{a}\n\ |
|
133 is resized and padded with zeros.\n\ |
|
134 @end deftypefn\n\ |
|
135 @seealso {ifftn, fft, fft2" |
|
136 WISDOM |
|
137 "}") |
|
138 { |
|
139 return do_fftn(args, "fftn", 0); |
|
140 } |
|
141 |
|
142 DEFUN_DLD (ifftn, args, , |
|
143 "-*- texinfo -*-\n\ |
|
144 @deftypefn {Loadable Function} {} ifftn (@var{a}, @var{siz})\n\ |
|
145 Compute the invesre N dimensional FFT of @var{a} using subroutines from\n" |
|
146 FFTSRC |
|
147 ". The optional vector argument @var{siz} may be used specify the\n\ |
|
148 dimensions of the array to be used. If an element of @var{siz} is\n\ |
|
149 smaller than the corresponding dimension, then the dimension is\n\ |
|
150 truncated prior to performing the inverse FFT. Otherwise if an element\n\ |
|
151 of @var{siz} is larger than the corresponding dimension @var{a}\n\ |
|
152 is resized and padded with zeros.\n\ |
|
153 @end deftypefn\n\ |
|
154 @seealso {fftn, ifft, ifft2" |
|
155 WISDOM |
|
156 "}") |
|
157 { |
|
158 return do_fftn(args, "ifftn", 1); |
|
159 } |
|
160 |
|
161 /* |
|
162 ;;; Local Variables: *** |
|
163 ;;; mode: C++ *** |
|
164 ;;; End: *** |
|
165 */ |