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