3Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 David Bateman
5This file is part of Octave.
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.
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
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/>.
27#include "lo-mappers.h"
35// This function should be merged with Fifft.
37#if defined (HAVE_FFTW)
38#define FFTSRC "@sc{fftw}"
40#define FFTSRC "@sc{fftpack}"
44do_fftn (const octave_value_list &args, const char *fcn, int type)
48 int nargin = args.length ();
50 if (nargin < 1 || nargin > 2)
56 octave_value arg = args(0);
57 dim_vector dims = arg.dims ();
59 for (int i = 0; i < dims.length (); i++)
65 Matrix val = args(1).matrix_value ();
66 if (val.rows () > val.columns ())
67 val = val.transpose ();
69 if (error_state || val.columns () != dims.length () || val.rows () != 1)
70 error ("%s: second argument must be a vector of length dim", fcn);
73 for (int i = 0; i < dims.length (); i++)
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);
81 dims(i) = NINTbig(val(i,0));
92 if (arg.is_single_type ())
93 return octave_value (FloatMatrix ());
95 return octave_value (Matrix ());
98 if (arg.is_single_type ())
100 if (arg.is_real_type ())
102 FloatNDArray nda = arg.float_array_value ();
106 nda.resize (dims, 0.0);
107 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
112 FloatComplexNDArray cnda = arg.float_complex_array_value ();
116 cnda.resize (dims, 0.0);
117 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
123 if (arg.is_real_type ())
125 NDArray nda = arg.array_value ();
129 nda.resize (dims, 0.0);
130 retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
133 else if (arg.is_complex_type ())
135 ComplexNDArray cnda = arg.complex_array_value ();
139 cnda.resize (dims, 0.0);
140 retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
145 gripe_wrong_type_arg (fcn, arg);
152DEFUN_DLD (fftn, args, ,
154@deftypefn {Loadable Function} {} fftn (@var{a}, @var{size})\n\
155Compute the N-dimensional FFT of @var{a} using subroutines from\n"
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\
166 return do_fftn (args, "fftn", 0);
169DEFUN_DLD (ifftn, args, ,
171@deftypefn {Loadable Function} {} ifftn (@var{a}, @var{size})\n\
172Compute the inverse N-dimensional FFT of @var{a} using subroutines from\n"
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\
183 return do_fftn (args, "ifftn", 1);