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