GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
fftn.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2004-2017 David Bateman
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 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include "lo-mappers.h"
28 
29 #include "defun.h"
30 #include "error.h"
31 #include "errwarn.h"
32 #include "ovl.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 
43 static octave_value
44 do_fftn (const octave_value_list &args, const char *fcn, int type)
45 {
46  int nargin = args.length ();
47 
48  if (nargin < 1 || nargin > 2)
49  print_usage ();
50 
52  octave_value arg = args(0);
53  dim_vector dims = arg.dims ();
54 
55  for (int i = 0; i < dims.ndims (); i++)
56  if (dims(i) < 0)
57  return retval;
58 
59  if (nargin > 1)
60  {
61  Matrix val = args(1).xmatrix_value ("%s: SIZE must be a vector of length dim", fcn);
62 
63  if (val.rows () > val.columns ())
64  val = val.transpose ();
65 
66  if (val.columns () != dims.ndims () || val.rows () != 1)
67  error ("%s: SIZE must be a vector of length dim", fcn);
68 
69  for (int i = 0; i < dims.ndims (); i++)
70  {
71  if (octave::math::isnan (val(i,0)))
72  error ("%s: SIZE has invalid NaN entries", fcn);
73  else if (octave::math::nint_big (val(i,0)) < 0)
74  error ("%s: all dimensions in SIZE must be greater than zero", fcn);
75  else
77  }
78  }
79 
80  if (dims.all_zero ())
81  {
82  if (arg.is_single_type ())
83  return octave_value (FloatMatrix ());
84  else
85  return octave_value (Matrix ());
86  }
87 
88  if (arg.is_single_type ())
89  {
90  if (arg.is_real_type ())
91  {
92  FloatNDArray nda = arg.float_array_value ();
93 
94  nda.resize (dims, 0.0);
95  retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
96  }
97  else
98  {
100 
101  cnda.resize (dims, 0.0);
102  retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
103  }
104  }
105  else
106  {
107  if (arg.is_real_type ())
108  {
109  NDArray nda = arg.array_value ();
110 
111  nda.resize (dims, 0.0);
112  retval = (type != 0 ? nda.ifourierNd () : nda.fourierNd ());
113  }
114  else if (arg.is_complex_type ())
115  {
116  ComplexNDArray cnda = arg.complex_array_value ();
117 
118  cnda.resize (dims, 0.0);
119  retval = (type != 0 ? cnda.ifourierNd () : cnda.fourierNd ());
120  }
121  else
122  err_wrong_type_arg (fcn, arg);
123  }
124 
125  return retval;
126 }
127 
128 DEFUN (fftn, args, ,
129  doc: /* -*- texinfo -*-
130 @deftypefn {} {} fftn (@var{A})
131 @deftypefnx {} {} fftn (@var{A}, @var{size})
132 Compute the N-dimensional discrete Fourier transform of @var{A} using
133 a Fast Fourier Transform (FFT) algorithm.
134 
135 The optional vector argument @var{size} may be used specify the dimensions
136 of the array to be used. If an element of @var{size} is smaller than the
137 corresponding dimension of @var{A}, then the dimension of @var{A} is
138 truncated prior to performing the FFT@. Otherwise, if an element of
139 @var{size} is larger than the corresponding dimension then @var{A} is
140 resized and padded with zeros.
141 @seealso{ifftn, fft, fft2, fftw}
142 @end deftypefn */)
143 {
144  return do_fftn (args, "fftn", 0);
145 }
146 
147 DEFUN (ifftn, args, ,
148  doc: /* -*- texinfo -*-
149 @deftypefn {} {} ifftn (@var{A})
150 @deftypefnx {} {} ifftn (@var{A}, @var{size})
151 Compute the inverse N-dimensional discrete Fourier transform of @var{A}
152 using a Fast Fourier Transform (FFT) algorithm.
153 
154 The optional vector argument @var{size} may be used specify the dimensions
155 of the array to be used. If an element of @var{size} is smaller than the
156 corresponding dimension of @var{A}, then the dimension of @var{A} is
157 truncated prior to performing the inverse FFT@. Otherwise, if an element of
158 @var{size} is larger than the corresponding dimension then @var{A} is
159 resized and padded with zeros.
160 @seealso{fftn, ifft, ifft2, fftw}
161 @end deftypefn */)
162 {
163  return do_fftn (args, "ifftn", 1);
164 }
ComplexNDArray complex_array_value(bool frc_str_conv=false) const
Definition: ov.h:812
bool is_real_type(void) const
Definition: ov.h:667
OCTINTERP_API void print_usage(void)
Definition: defun.cc:52
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
octave_idx_type length(void) const
Definition: ovl.h:96
bool isnan(double x)
Definition: lo-mappers.cc:347
#define DEFUN(name, args_name, nargout_name, doc)
Definition: defun.h:46
void error(const char *fmt,...)
Definition: error.cc:570
ComplexNDArray ifourierNd(void) const
Definition: CNDArray.cc:175
octave_idx_type rows(void) const
Definition: Array.h:401
octave_value arg
Definition: pr-output.cc:3440
FloatComplexNDArray ifourierNd(void) const
Definition: fCNDArray.cc:175
octave_function * fcn
Definition: ov-class.cc:1743
FloatComplexNDArray ifourierNd(void) const
Definition: fNDArray.cc:173
static octave_value do_fftn(const octave_value_list &args, const char *fcn, int type)
Definition: fftn.cc:44
JNIEnv void * args
Definition: ov-java.cc:67
FloatNDArray float_array_value(bool frc_str_conv=false) const
Definition: ov.h:796
ComplexNDArray fourierNd(void) const
Definition: dNDArray.cc:200
int nargin
Definition: graphics.cc:10115
FloatComplexNDArray float_complex_array_value(bool frc_str_conv=false) const
Definition: ov.h:816
FloatComplexNDArray fourierNd(void) const
Definition: fCNDArray.cc:160
bool is_complex_type(void) const
Definition: ov.h:670
void resize(const dim_vector &dv, const T &rfv)
Definition: Array.cc:1028
octave_value retval
Definition: data.cc:6294
Matrix transpose(void) const
Definition: dMatrix.h:129
FloatComplexNDArray fourierNd(void) const
Definition: fNDArray.cc:158
idx type
Definition: ov.cc:3129
Definition: dMatrix.h:37
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
Definition: sub2ind.cc:255
dim_vector dims(void) const
Definition: ov.h:486
bool all_zero(void) const
Definition: dim-vector.h:333
void err_wrong_type_arg(const char *name, const char *s)
Definition: errwarn.cc:156
ComplexNDArray fourierNd(void) const
Definition: CNDArray.cc:160
NDArray array_value(bool frc_str_conv=false) const
Definition: ov.h:793
=val(i)}if ode{val(i)}occurs in table i
Definition: lookup.cc:239
octave_idx_type nint_big(double x)
Definition: lo-mappers.cc:409
octave_idx_type ndims(void) const
Number of dimensions.
Definition: dim-vector.h:301
ComplexNDArray ifourierNd(void) const
Definition: dNDArray.cc:215
bool is_single_type(void) const
Definition: ov.h:627
Vector representing the dimensions (size) of an Array.
Definition: dim-vector.h:87
octave_idx_type columns(void) const
Definition: Array.h:410
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))