2928
|
1 /* |
|
2 |
4773
|
3 Copyright (C) 2004 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 |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
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 |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
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 // This function should be merged with Fifft. |
2928
|
37 |
4773
|
38 #if defined (HAVE_FFTW3) |
|
39 #define FFTSRC "@sc{Fftw}" |
|
40 #define WISDOM ", fft_wisdom" |
|
41 #else |
|
42 #define FFTSRC "@sc{Fftpack}" |
|
43 #define WISDOM |
|
44 #endif |
|
45 |
|
46 static octave_value |
|
47 do_fft2 (const octave_value_list &args, const char *fcn, int type) |
2928
|
48 { |
4233
|
49 octave_value retval; |
2928
|
50 |
|
51 int nargin = args.length (); |
|
52 |
|
53 if (nargin < 1 || nargin > 3) |
|
54 { |
4773
|
55 print_usage (fcn); |
2928
|
56 return retval; |
|
57 } |
|
58 |
|
59 octave_value arg = args(0); |
4773
|
60 dim_vector dims = arg.dims (); |
|
61 int n_rows = -1; |
|
62 |
2928
|
63 if (nargin > 1) |
|
64 { |
|
65 double dval = args(1).double_value (); |
|
66 if (xisnan (dval)) |
4773
|
67 error ("%s: NaN is invalid as the N_ROWS", fcn); |
2928
|
68 else |
4773
|
69 { |
|
70 n_rows = NINT (dval); |
|
71 if (n_rows < 0) |
|
72 error ("%s: number of rows must be greater than zero", fcn); |
|
73 } |
2928
|
74 } |
|
75 |
|
76 if (error_state) |
|
77 return retval; |
|
78 |
4773
|
79 int n_cols = -1; |
2928
|
80 if (nargin > 2) |
|
81 { |
|
82 double dval = args(2).double_value (); |
|
83 if (xisnan (dval)) |
4773
|
84 error ("%s: NaN is invalid as the N_COLS", fcn); |
2928
|
85 else |
4773
|
86 { |
|
87 n_cols = NINT (dval); |
|
88 if (n_cols < 0) |
|
89 error ("%s: number of columns must be greater than zero", fcn); |
|
90 } |
2928
|
91 } |
|
92 |
|
93 if (error_state) |
|
94 return retval; |
|
95 |
4773
|
96 for (int i = 0; i < dims.length (); i++) |
|
97 if (dims(i) < 0) |
2928
|
98 return retval; |
|
99 |
4773
|
100 if (n_rows < 0) |
|
101 n_rows = dims (0); |
|
102 else |
|
103 dims (0) = n_rows; |
2928
|
104 |
4773
|
105 if (n_cols < 0) |
|
106 n_cols = dims (1); |
|
107 else |
|
108 dims (1) = n_cols; |
|
109 |
|
110 if (dims.all_zero () || n_rows == 0 || n_cols == 0) |
4233
|
111 return octave_value (Matrix ()); |
2928
|
112 |
|
113 if (arg.is_real_type ()) |
|
114 { |
4773
|
115 NDArray nda = arg.array_value (); |
2928
|
116 |
|
117 if (! error_state) |
|
118 { |
4773
|
119 nda.resize (dims, 0.0); |
|
120 retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ()); |
2928
|
121 } |
|
122 } |
|
123 else if (arg.is_complex_type ()) |
|
124 { |
4773
|
125 ComplexNDArray cnda = arg.complex_array_value (); |
2928
|
126 |
|
127 if (! error_state) |
|
128 { |
4773
|
129 cnda.resize (dims, 0.0); |
|
130 retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ()); |
2928
|
131 } |
|
132 } |
|
133 else |
|
134 { |
4773
|
135 gripe_wrong_type_arg (fcn, arg); |
2928
|
136 } |
|
137 |
|
138 return retval; |
|
139 } |
|
140 |
4773
|
141 DEFUN_DLD (fft2, args, , |
|
142 "-*- texinfo -*-\n\ |
|
143 @deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\ |
|
144 Compute the two dimensional FFT of @var{a} using subroutines from\n" |
|
145 FFTSRC |
|
146 ". The optional arguments @var{n} and @var{m} may be used specify the\n\ |
|
147 number of rows and columns of @var{a} to use. If either of these is\n\ |
|
148 larger than the size of @var{a}, @var{a} is resized and padded with\n\ |
|
149 zeros.\n\ |
|
150 \n\ |
|
151 If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\ |
|
152 of @var{a} is treated seperately\n\ |
|
153 @end deftypefn\n\ |
|
154 @seealso {ifft2, fft, fftn" |
|
155 WISDOM |
|
156 "}") |
|
157 { |
|
158 return do_fft2(args, "fft2", 0); |
|
159 } |
|
160 |
|
161 |
|
162 DEFUN_DLD (ifft2, args, , |
|
163 "-*- texinfo -*-\n\ |
|
164 @deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\ |
|
165 Compute the inverse two dimensional FFT of @var{a} using subroutines from\n" |
|
166 FFTSRC |
|
167 ". The optional arguments @var{n} and @var{m} may be used specify the\n\ |
|
168 number of rows and columns of @var{a} to use. If either of these is\n\ |
|
169 larger than the size of @var{a}, @var{a} is resized and padded with\n\ |
|
170 zeros.\n\ |
|
171 \n\ |
|
172 If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\ |
|
173 of @var{a} is treated seperately\n\ |
|
174 @end deftypefn\n\ |
|
175 @seealso {fft2, ifft, ifftn" |
|
176 WISDOM |
|
177 "}") |
|
178 { |
|
179 return do_fft2(args, "ifft2", 1); |
|
180 } |
|
181 |
2928
|
182 /* |
|
183 ;;; Local Variables: *** |
|
184 ;;; mode: C++ *** |
|
185 ;;; End: *** |
|
186 */ |