Mercurial > octave
diff src/DLD-FUNCTIONS/fft2.cc @ 4773:ccfbd6047a54
[project @ 2004-02-16 19:02:32 by jwe]
author | jwe |
---|---|
date | Mon, 16 Feb 2004 19:02:33 +0000 |
parents | ccfdb55c8156 |
children | 3dfdf6f36854 |
line wrap: on
line diff
--- a/src/DLD-FUNCTIONS/fft2.cc Mon Feb 16 17:57:34 2004 +0000 +++ b/src/DLD-FUNCTIONS/fft2.cc Mon Feb 16 19:02:33 2004 +0000 @@ -1,5 +1,6 @@ /* +Copyright (C) 2004 David Bateman Copyright (C) 1996, 1997 John W. Eaton This file is part of Octave. @@ -32,18 +33,18 @@ #include "oct-obj.h" #include "utils.h" -// This function should be merged with Fifft2. +// This function should be merged with Fifft. -DEFUN_DLD (fft2, args, , - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\ -Compute the two dimensional FFT of @var{a}.\n\ -\n\ -The optional arguments @var{n} and @var{m} may be used specify the\n\ -number of rows and columns of @var{a} to use. If either of these is\n\ -larger than the size of @var{a}, @var{a} is resized and padded with\n\ -zeros.\n\ -@end deftypefn") +#if defined (HAVE_FFTW3) +#define FFTSRC "@sc{Fftw}" +#define WISDOM ", fft_wisdom" +#else +#define FFTSRC "@sc{Fftpack}" +#define WISDOM +#endif + +static octave_value +do_fft2 (const octave_value_list &args, const char *fcn, int type) { octave_value retval; @@ -51,79 +52,133 @@ if (nargin < 1 || nargin > 3) { - print_usage ("fft2"); + print_usage (fcn); return retval; } octave_value arg = args(0); - - int n_rows = arg.rows (); + dim_vector dims = arg.dims (); + int n_rows = -1; + if (nargin > 1) { double dval = args(1).double_value (); if (xisnan (dval)) - error ("fft2: NaN is invalid as N_ROWS"); + error ("%s: NaN is invalid as the N_ROWS", fcn); else - n_rows = NINT (dval); + { + n_rows = NINT (dval); + if (n_rows < 0) + error ("%s: number of rows must be greater than zero", fcn); + } } if (error_state) return retval; - int n_cols = arg.columns (); + int n_cols = -1; if (nargin > 2) { double dval = args(2).double_value (); if (xisnan (dval)) - error ("fft2: NaN is invalid as N_COLS"); + error ("%s: NaN is invalid as the N_COLS", fcn); else - n_cols = NINT (dval); + { + n_cols = NINT (dval); + if (n_cols < 0) + error ("%s: number of columns must be greater than zero", fcn); + } } if (error_state) return retval; - if (n_rows < 0 || n_cols < 0) - { - error ("fft2: number of points must be greater than zero"); + for (int i = 0; i < dims.length (); i++) + if (dims(i) < 0) return retval; - } - int arg_is_empty = empty_arg ("fft2", arg.rows (), arg.columns ()); + if (n_rows < 0) + n_rows = dims (0); + else + dims (0) = n_rows; - if (arg_is_empty < 0) - return retval; - else if (arg_is_empty || n_rows == 0 || n_cols == 0) + if (n_cols < 0) + n_cols = dims (1); + else + dims (1) = n_cols; + + if (dims.all_zero () || n_rows == 0 || n_cols == 0) return octave_value (Matrix ()); if (arg.is_real_type ()) { - Matrix m = arg.matrix_value (); + NDArray nda = arg.array_value (); if (! error_state) { - m.resize (n_rows, n_cols, 0.0); - retval = m.fourier2d (); + nda.resize (dims, 0.0); + retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ()); } } else if (arg.is_complex_type ()) { - ComplexMatrix m = arg.complex_matrix_value (); + ComplexNDArray cnda = arg.complex_array_value (); if (! error_state) { - m.resize (n_rows, n_cols, 0.0); - retval = m.fourier2d (); + cnda.resize (dims, 0.0); + retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ()); } } else { - gripe_wrong_type_arg ("fft2", arg); + gripe_wrong_type_arg (fcn, arg); } return retval; } +DEFUN_DLD (fft2, args, , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\ +Compute the two dimensional FFT of @var{a} using subroutines from\n" +FFTSRC +". The optional arguments @var{n} and @var{m} may be used specify the\n\ +number of rows and columns of @var{a} to use. If either of these is\n\ +larger than the size of @var{a}, @var{a} is resized and padded with\n\ +zeros.\n\ +\n\ +If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\ +of @var{a} is treated seperately\n\ +@end deftypefn\n\ +@seealso {ifft2, fft, fftn" +WISDOM +"}") +{ + return do_fft2(args, "fft2", 0); +} + + +DEFUN_DLD (ifft2, args, , + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\ +Compute the inverse two dimensional FFT of @var{a} using subroutines from\n" +FFTSRC +". The optional arguments @var{n} and @var{m} may be used specify the\n\ +number of rows and columns of @var{a} to use. If either of these is\n\ +larger than the size of @var{a}, @var{a} is resized and padded with\n\ +zeros.\n\ +\n\ +If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\ +of @var{a} is treated seperately\n\ +@end deftypefn\n\ +@seealso {fft2, ifft, ifftn" +WISDOM +"}") +{ + return do_fft2(args, "ifft2", 1); +} + /* ;;; Local Variables: *** ;;; mode: C++ ***