2928
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include "lo-mappers.h" |
|
28 |
|
29 #include "defun-dld.h" |
|
30 #include "error.h" |
|
31 #include "gripes.h" |
|
32 #include "oct-obj.h" |
|
33 #include "utils.h" |
|
34 |
|
35 // This function should be merged with Fifft. |
|
36 |
|
37 DEFUN_DLD (fft, args, , |
3367
|
38 "-*- texinfo -*-\n\ |
|
39 @deftypefn {Loadable Function} {} fft (@var{a}, @var{n})\n\ |
|
40 Compute the FFT of @var{a} using subroutines from @sc{Fftpack}. If @var{a}\n\ |
|
41 is a matrix, @code{fft} computes the FFT for each column of @var{a}.\n\ |
|
42 \n\ |
|
43 If called with two arguments, @var{n} is expected to be an integer\n\ |
|
44 specifying the number of elements of @var{a} to use. If @var{a} is a\n\ |
|
45 matrix, @var{n} specifies the number of rows of @var{a} to use. If\n\ |
|
46 @var{n} is larger than the size of @var{a}, @var{a} is resized and\n\ |
|
47 padded with zeros.\n\ |
|
48 @end deftypefn") |
2928
|
49 { |
4233
|
50 octave_value retval; |
2928
|
51 |
|
52 int nargin = args.length (); |
|
53 |
|
54 if (nargin < 1 || nargin > 2) |
|
55 { |
|
56 print_usage ("fft"); |
|
57 return retval; |
|
58 } |
|
59 |
|
60 octave_value arg = args(0); |
|
61 |
|
62 int n_points = arg.rows (); |
|
63 if (n_points == 1) |
|
64 n_points = arg.columns (); |
|
65 |
|
66 if (nargin == 2) |
|
67 { |
|
68 double dval = args(1).double_value (); |
|
69 if (xisnan (dval)) |
|
70 error ("fft: NaN is invalid as the N_POINTS"); |
|
71 else |
|
72 n_points = NINT (dval); |
|
73 } |
|
74 |
|
75 if (error_state) |
|
76 return retval; |
|
77 |
|
78 if (n_points < 0) |
|
79 { |
|
80 error ("fft: number of points must be greater than zero"); |
|
81 return retval; |
|
82 } |
|
83 |
|
84 int arg_is_empty = empty_arg ("fft", arg.rows (), arg.columns ()); |
|
85 |
|
86 if (arg_is_empty < 0) |
|
87 return retval; |
|
88 else if (arg_is_empty || n_points == 0) |
4233
|
89 return octave_value (Matrix ()); |
2928
|
90 |
|
91 if (arg.is_real_type ()) |
|
92 { |
|
93 Matrix m = arg.matrix_value (); |
|
94 |
|
95 if (! error_state) |
|
96 { |
|
97 if (m.rows () == 1) |
|
98 m.resize (1, n_points, 0.0); |
|
99 else |
|
100 m.resize (n_points, m.columns (), 0.0); |
|
101 retval = m.fourier (); |
|
102 } |
|
103 } |
|
104 else if (arg.is_complex_type ()) |
|
105 { |
|
106 ComplexMatrix m = arg.complex_matrix_value (); |
|
107 |
|
108 if (! error_state) |
|
109 { |
|
110 if (m.rows () == 1) |
|
111 m.resize (1, n_points, 0.0); |
|
112 else |
|
113 m.resize (n_points, m.columns (), 0.0); |
|
114 retval = m.fourier (); |
|
115 } |
|
116 } |
|
117 else |
|
118 { |
|
119 gripe_wrong_type_arg ("fft", arg); |
|
120 } |
|
121 |
|
122 return retval; |
|
123 } |
|
124 |
|
125 /* |
|
126 ;;; Local Variables: *** |
|
127 ;;; mode: C++ *** |
|
128 ;;; End: *** |
|
129 */ |