home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / src / f-fft.cc < prev    next >
C/C++ Source or Header  |  1995-01-30  |  3KB  |  125 lines

  1. // f-fft.cc                                           -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1993, 1994, 1995 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. */
  23.  
  24. #ifdef HAVE_CONFIG_H
  25. #include "config.h"
  26. #endif
  27.  
  28. #include "dMatrix.h"
  29. #include "CMatrix.h"
  30.  
  31. #include "tree-const.h"
  32. #include "user-prefs.h"
  33. #include "gripes.h"
  34. #include "error.h"
  35. #include "utils.h"
  36. #include "help.h"
  37. #include "defun-dld.h"
  38.  
  39. // This function should be merged with Fifft.
  40.  
  41. DEFUN_DLD_BUILTIN ("fft", Ffft, Sfft, 3, 1,
  42.   "fft (X [, N]): fast fourier transform of a vector")
  43. {
  44.   Octave_object retval;
  45.  
  46.   int nargin = args.length ();
  47.  
  48.   if (nargin < 1 || nargin > 2)
  49.     {
  50.       print_usage ("fft");
  51.       return retval;
  52.     }
  53.  
  54.   tree_constant arg = args(0);
  55.  
  56.   int n_points = arg.rows ();
  57.   if (n_points == 1)
  58.     n_points = arg.columns ();
  59.  
  60.   if (nargin == 2)
  61.     {
  62.       double dval = args(1).double_value ();
  63.       if (xisnan (dval))
  64.     error ("fft: NaN is invalid as the N_POINTS");
  65.       else
  66.     n_points = NINT (dval);
  67.     }
  68.  
  69.   if (error_state)
  70.     return retval;
  71.  
  72.   if (n_points < 0)
  73.     {
  74.       error ("fft: number of points must be greater than zero");
  75.       return retval;
  76.     }
  77.  
  78.   int arg_is_empty = empty_arg ("fft", arg.rows (), arg.columns ());
  79.  
  80.   if (arg_is_empty < 0)
  81.     return retval;
  82.   else if (arg_is_empty || n_points == 0)
  83.     return Matrix ();
  84.  
  85.   if (arg.is_real_type ())
  86.     {
  87.       Matrix m = arg.matrix_value ();
  88.  
  89.       if (! error_state)
  90.     {
  91.       if (m.rows () == 1)
  92.         m.resize (1, n_points, 0.0);
  93.       else
  94.         m.resize (n_points, m.columns (), 0.0);
  95.       retval = m.fourier ();
  96.     }
  97.     }
  98.   else if (arg.is_complex_type ())
  99.     {
  100.       ComplexMatrix m = arg.complex_matrix_value ();
  101.  
  102.       if (! error_state)
  103.     {
  104.       if (m.rows () == 1)
  105.         m.resize (1, n_points, 0.0);
  106.       else
  107.         m.resize (n_points, m.columns (), 0.0);
  108.       retval = m.fourier ();
  109.     }
  110.     }
  111.   else
  112.     {
  113.       gripe_wrong_type_arg ("fft", arg);
  114.     }
  115.  
  116.   return retval;
  117. }
  118.  
  119. /*
  120. ;;; Local Variables: ***
  121. ;;; mode: C++ ***
  122. ;;; page-delimiter: "^/\\*" ***
  123. ;;; End: ***
  124. */
  125.