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