676
|
1 /* |
|
2 |
1884
|
3 Copyright (C) 1996 John W. Eaton |
676
|
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 |
1315
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
676
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
1192
|
24 #include <config.h> |
676
|
25 #endif |
|
26 |
1352
|
27 #include "defun-dld.h" |
|
28 #include "error.h" |
|
29 #include "gripes.h" |
|
30 #include "help.h" |
1740
|
31 #include "mappers.h" |
|
32 #include "oct-obj.h" |
676
|
33 #include "user-prefs.h" |
|
34 #include "utils.h" |
|
35 |
|
36 // This function should be merged with Ffft2. |
|
37 |
1957
|
38 DEFUN_DLD_BUILTIN (ifft2, args, , |
676
|
39 "ifft2 (X [, N] [, M])\n\ |
|
40 \n\ |
|
41 two dimensional inverse fast fourier transform of a vector") |
|
42 { |
|
43 Octave_object retval; |
|
44 |
|
45 int nargin = args.length (); |
|
46 |
712
|
47 if (nargin < 1 || nargin > 3) |
676
|
48 { |
|
49 print_usage ("ifft2"); |
|
50 return retval; |
|
51 } |
|
52 |
712
|
53 tree_constant arg = args(0); |
676
|
54 |
|
55 int n_rows = arg.rows (); |
712
|
56 if (nargin > 1) |
1086
|
57 { |
|
58 double dval = args(1).double_value (); |
|
59 if (xisnan (dval)) |
|
60 error ("fft2: NaN is invalid as N_ROWS"); |
|
61 else |
|
62 n_rows = NINT (dval); |
|
63 } |
676
|
64 |
|
65 if (error_state) |
|
66 return retval; |
|
67 |
|
68 int n_cols = arg.columns (); |
712
|
69 if (nargin > 2) |
1086
|
70 { |
|
71 double dval = args(2).double_value (); |
|
72 if (xisnan (dval)) |
|
73 error ("fft2: NaN is invalid as N_COLS"); |
|
74 else |
|
75 n_cols = NINT (dval); |
|
76 } |
676
|
77 |
|
78 if (error_state) |
|
79 return retval; |
|
80 |
|
81 if (n_rows < 0 || n_cols < 0) |
|
82 { |
|
83 error ("ifft2: number of points must be greater than zero"); |
|
84 return retval; |
|
85 } |
|
86 |
|
87 int arg_is_empty = empty_arg ("ifft2", arg.rows (), arg.columns ()); |
|
88 |
|
89 if (arg_is_empty < 0) |
|
90 return retval; |
|
91 else if (arg_is_empty || n_rows == 0 || n_cols == 0) |
|
92 return Matrix (); |
|
93 |
|
94 if (arg.is_real_type ()) |
|
95 { |
|
96 Matrix m = arg.matrix_value (); |
|
97 |
|
98 if (! error_state) |
|
99 { |
|
100 m.resize (n_rows, n_cols, 0.0); |
|
101 retval = m.ifourier2d (); |
|
102 } |
|
103 } |
|
104 else if (arg.is_complex_type ()) |
|
105 { |
|
106 ComplexMatrix m = arg.complex_matrix_value (); |
|
107 |
|
108 if (! error_state) |
|
109 { |
|
110 m.resize (n_rows, n_cols, 0.0); |
|
111 retval = m.ifourier2d (); |
|
112 } |
|
113 } |
|
114 else |
|
115 { |
|
116 gripe_wrong_type_arg ("ifft2", arg); |
|
117 } |
|
118 |
|
119 return retval; |
|
120 } |
|
121 |
|
122 /* |
|
123 ;;; Local Variables: *** |
|
124 ;;; mode: C++ *** |
|
125 ;;; End: *** |
|
126 */ |