changelog shortlog tags changeset files revisions annotate raw

src/DLD-FUNCTIONS/fftn.cc

changeset 10289: 4b124317dc38
parent:40dfc0c99116
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (32 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1/*
2
3Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 David Bateman
4
5This file is part of Octave.
6
7Octave is free software; you can redistribute it and/or modify it
8under the terms of the GNU General Public License as published by the
9Free Software Foundation; either version 3 of the License, or (at your
10option) any later version.
11
12Octave is distributed in the hope that it will be useful, but WITHOUT
13ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with Octave; see the file COPYING. If not, see
19<http://www.gnu.org/licenses/>.
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#if defined (HAVE_FFTW)
38#define FFTSRC "@sc{fftw}"
39#else
40#define FFTSRC "@sc{fftpack}"
41#endif
42
43static octave_value
44do_fftn (const octave_value_list &args, const char *fcn, int type)
45{
46 octave_value retval;
47
48 int nargin = args.length ();
49
50 if (nargin < 1 || nargin > 2)
51 {
52 print_usage ();
53 return retval;
54 }
55
56 octave_value arg = args(0);
57 dim_vector dims = arg.dims ();
58
59 for (int i = 0; i < dims.length (); i++)
60 if (dims(i) < 0)
61 return retval;
62
63 if (nargin > 1)
64 {
65 Matrix val = args(1).matrix_value ();
66 if (val.rows () > val.columns ())
67 val = val.transpose ();
68
69 if (error_state || val.columns () != dims.length () || val.rows () != 1)
70 error ("%s: second argument must be a vector of length dim", fcn);
71 else
72 {
73 for (int i = 0; i < dims.length (); i++)
74 {
75 if (xisnan (val(i,0)))
76 error ("%s: NaN is invalid as a dimension", fcn);
77 else if (NINTbig (val(i,0)) < 0)
78 error ("%s: all dimension must be greater than zero", fcn);
79 else
80 {
81 dims(i) = NINTbig(val(i,0));
82 }
83 }
84 }
85 }
86
87 if (error_state)
88 return retval;
89
90 if (dims.all_zero ())
91 {
92 if (arg.is_single_type ())
93 return octave_value (FloatMatrix ());
94 else
95 return octave_value (Matrix ());
96 }
97
98 if (arg.is_single_type ())
99 {
100 if (arg.is_real_type ())
101 {
102 FloatNDArray nda = arg.float_array_value ();
103
104 if (! error_state)
105 {
106 nda.resize (dims, 0.0);
107 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
108 }
109 }
110 else
111 {
112 FloatComplexNDArray cnda = arg.float_complex_array_value ();
113
114 if (! error_state)
115 {
116 cnda.resize (dims, 0.0);
117 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
118 }
119 }
120 }
121 else
122 {
123 if (arg.is_real_type ())
124 {
125 NDArray nda = arg.array_value ();
126
127 if (! error_state)
128 {
129 nda.resize (dims, 0.0);
130 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
131 }
132 }
133 else if (arg.is_complex_type ())
134 {
135 ComplexNDArray cnda = arg.complex_array_value ();
136
137 if (! error_state)
138 {
139 cnda.resize (dims, 0.0);
140 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
141 }
142 }
143 else
144 {
145 gripe_wrong_type_arg (fcn, arg);
146 }
147 }
148
149 return retval;
150}
151
152DEFUN_DLD (fftn, args, ,
153 "-*- texinfo -*-\n\
154@deftypefn {Loadable Function} {} fftn (@var{a}, @var{size})\n\
155Compute the N-dimensional FFT of @var{a} using subroutines from\n"
156FFTSRC
157". The optional vector argument @var{size} may be used specify the\n\
158dimensions of the array to be used. If an element of @var{size} is\n\
159smaller than the corresponding dimension, then the dimension is\n\
160truncated prior to performing the FFT. Otherwise if an element\n\
161of @var{size} is larger than the corresponding dimension @var{a}\n\
162is resized and padded with zeros.\n\
163@seealso {ifftn, fft, fft2, fftw}\n\
164@end deftypefn")
165{
166 return do_fftn (args, "fftn", 0);
167}
168
169DEFUN_DLD (ifftn, args, ,
170 "-*- texinfo -*-\n\
171@deftypefn {Loadable Function} {} ifftn (@var{a}, @var{size})\n\
172Compute the inverse N-dimensional FFT of @var{a} using subroutines from\n"
173FFTSRC
174". The optional vector argument @var{size} may be used specify the\n\
175dimensions of the array to be used. If an element of @var{size} is\n\
176smaller than the corresponding dimension, then the dimension is\n\
177truncated prior to performing the inverse FFT. Otherwise if an element\n\
178of @var{size} is larger than the corresponding dimension @var{a}\n\
179is resized and padded with zeros.\n\
180@seealso {fftn, ifft, ifft2, fftw}\n\
181@end deftypefn")
182{
183 return do_fftn (args, "ifftn", 1);
184}