676
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 "utils.h" |
|
34 |
|
35 // This function should be merged with Fifft2. |
|
36 |
2465
|
37 DEFUN_DLD (fft2, args, , |
676
|
38 "fft2 (X [, N] [, M])\n\ |
|
39 \n\ |
|
40 two dimensional fast fourier transform of a vector") |
|
41 { |
2086
|
42 octave_value_list retval; |
676
|
43 |
|
44 int nargin = args.length (); |
|
45 |
712
|
46 if (nargin < 1 || nargin > 3) |
676
|
47 { |
|
48 print_usage ("fft2"); |
|
49 return retval; |
|
50 } |
|
51 |
2086
|
52 octave_value arg = args(0); |
676
|
53 |
|
54 int n_rows = arg.rows (); |
712
|
55 if (nargin > 1) |
1086
|
56 { |
|
57 double dval = args(1).double_value (); |
|
58 if (xisnan (dval)) |
|
59 error ("fft2: NaN is invalid as N_ROWS"); |
|
60 else |
|
61 n_rows = NINT (dval); |
|
62 } |
676
|
63 |
|
64 if (error_state) |
|
65 return retval; |
|
66 |
|
67 int n_cols = arg.columns (); |
712
|
68 if (nargin > 2) |
1086
|
69 { |
|
70 double dval = args(2).double_value (); |
|
71 if (xisnan (dval)) |
|
72 error ("fft2: NaN is invalid as N_COLS"); |
|
73 else |
|
74 n_cols = NINT (dval); |
|
75 } |
676
|
76 |
|
77 if (error_state) |
|
78 return retval; |
|
79 |
|
80 if (n_rows < 0 || n_cols < 0) |
|
81 { |
|
82 error ("fft2: number of points must be greater than zero"); |
|
83 return retval; |
|
84 } |
|
85 |
|
86 int arg_is_empty = empty_arg ("fft2", arg.rows (), arg.columns ()); |
|
87 |
|
88 if (arg_is_empty < 0) |
|
89 return retval; |
|
90 else if (arg_is_empty || n_rows == 0 || n_cols == 0) |
|
91 return Matrix (); |
|
92 |
|
93 if (arg.is_real_type ()) |
|
94 { |
|
95 Matrix m = arg.matrix_value (); |
|
96 |
|
97 if (! error_state) |
|
98 { |
|
99 m.resize (n_rows, n_cols, 0.0); |
|
100 retval = m.fourier2d (); |
|
101 } |
|
102 } |
|
103 else if (arg.is_complex_type ()) |
|
104 { |
|
105 ComplexMatrix m = arg.complex_matrix_value (); |
|
106 |
|
107 if (! error_state) |
|
108 { |
|
109 m.resize (n_rows, n_cols, 0.0); |
|
110 retval = m.fourier2d (); |
|
111 } |
|
112 } |
|
113 else |
|
114 { |
|
115 gripe_wrong_type_arg ("fft2", arg); |
|
116 } |
|
117 |
|
118 return retval; |
|
119 } |
|
120 |
|
121 /* |
|
122 ;;; Local Variables: *** |
|
123 ;;; mode: C++ *** |
|
124 ;;; End: *** |
|
125 */ |