3Copyright (C) 1997, 1999, 2002, 2004, 2005, 2006, 2007, 2008,
5Copyright (C) 1996, 1997 John W. Eaton
7This file is part of Octave.
9Octave is free software; you can redistribute it and/or modify it
10under the terms of the GNU General Public License as published by the
11Free Software Foundation; either version 3 of the License, or (at your
12option) any later version.
14Octave is distributed in the hope that it will be useful, but WITHOUT
15ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19You should have received a copy of the GNU General Public License
20along with Octave; see the file COPYING. If not, see
21<http://www.gnu.org/licenses/>.
29#include "lo-mappers.h"
37// This function should be merged with Fifft.
39#if defined (HAVE_FFTW)
40#define FFTSRC "@sc{fftw}"
42#define FFTSRC "@sc{fftpack}"
46do_fft2 (const octave_value_list &args, const char *fcn, int type)
50 int nargin = args.length ();
52 if (nargin < 1 || nargin > 3)
58 octave_value arg = args(0);
59 dim_vector dims = arg.dims ();
60 octave_idx_type n_rows = -1;
64 double dval = args(1).double_value ();
66 error ("%s: NaN is invalid as the N_ROWS", fcn);
69 n_rows = NINTbig (dval);
71 error ("%s: number of rows must be greater than zero", fcn);
78 octave_idx_type n_cols = -1;
81 double dval = args(2).double_value ();
83 error ("%s: NaN is invalid as the N_COLS", fcn);
86 n_cols = NINTbig (dval);
88 error ("%s: number of columns must be greater than zero", fcn);
95 for (int i = 0; i < dims.length (); i++)
109 if (dims.all_zero () || n_rows == 0 || n_cols == 0)
111 if (arg.is_single_type ())
112 return octave_value (FloatMatrix ());
114 return octave_value (Matrix ());
117 if (arg.is_single_type ())
119 if (arg.is_real_type ())
121 FloatNDArray nda = arg.float_array_value ();
125 nda.resize (dims, 0.0);
126 retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ());
131 FloatComplexNDArray cnda = arg.float_complex_array_value ();
135 cnda.resize (dims, 0.0);
136 retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ());
142 if (arg.is_real_type ())
144 NDArray nda = arg.array_value ();
148 nda.resize (dims, 0.0);
149 retval = (type != 0 ? nda.ifourier2d () : nda.fourier2d ());
152 else if (arg.is_complex_type ())
154 ComplexNDArray cnda = arg.complex_array_value ();
158 cnda.resize (dims, 0.0);
159 retval = (type != 0 ? cnda.ifourier2d () : cnda.fourier2d ());
164 gripe_wrong_type_arg (fcn, arg);
171DEFUN_DLD (fft2, args, ,
173@deftypefn {Loadable Function} {} fft2 (@var{a}, @var{n}, @var{m})\n\
174Compute the two-dimensional FFT of @var{a} using subroutines from\n"
176". The optional arguments @var{n} and @var{m} may be used specify the\n\
177number of rows and columns of @var{a} to use. If either of these is\n\
178larger than the size of @var{a}, @var{a} is resized and padded with\n\
181If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\
182of @var{a} is treated separately\n\
183@seealso {ifft2, fft, fftn, fftw}\n\
186 return do_fft2 (args, "fft2", 0);
190DEFUN_DLD (ifft2, args, ,
192@deftypefn {Loadable Function} {} ifft2 (@var{a}, @var{n}, @var{m})\n\
193Compute the inverse two-dimensional FFT of @var{a} using subroutines from\n"
195". The optional arguments @var{n} and @var{m} may be used specify the\n\
196number of rows and columns of @var{a} to use. If either of these is\n\
197larger than the size of @var{a}, @var{a} is resized and padded with\n\
200If @var{a} is a multi-dimensional matrix, each two-dimensional sub-matrix\n\
201of @var{a} is treated separately\n\
202@seealso {fft2, ifft, ifftn, fftw}\n\
205 return do_fft2 (args, "ifft2", 1);
210%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
211%% Comalco Research and Technology
220%! x = 2*pi*(0:1:M-1)/M;
221%! y = 2*pi*(0:1:N-1)/N;
226%! answer = kron(fft(sx)',fft(sy));
227%! assert(S, answer, 4*M*N*eps);
229%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
230%% Comalco Research and Technology
239%! x = 2*pi*(0:1:M-1)/M;
240%! y = 2*pi*(0:1:N-1)/N;
245%! S = kron(fft(sx)',fft(sy));
246%! answer=kron(sx',sy);
249%! assert(s, answer, 30*eps);
252%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
253%% Comalco Research and Technology
262%! x = 2*pi*(0:1:M-1)/M;
263%! y = 2*pi*(0:1:N-1)/N;
264%! sx = single(cos(m*x));
265%! sy = single(sin(n*y));
268%! answer = kron(fft(sx)',fft(sy));
269%! assert(S, answer, 4*M*N*eps('single'));
271%% Author: David Billinghurst (David.Billinghurst@riotinto.com.au)
272%% Comalco Research and Technology
281%! x = single(2*pi*(0:1:M-1)/M);
282%! y = single(2*pi*(0:1:N-1)/N);
287%! S = kron(fft(sx)',fft(sy));
288%! answer=kron(sx',sy);
291%! assert(s, answer, 30*eps('single'));