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