home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21fb.zip / octave / SCRIPTS.ZIP / scripts.fat / signal / fftconv.m < prev    next >
Text File  |  1999-12-24  |  2KB  |  63 lines

  1. ## Copyright (C) 1996, 1997 John W. Eaton
  2. ##
  3. ## This file is part of Octave.
  4. ##
  5. ## Octave is free software; you can redistribute it and/or modify it
  6. ## under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation; either version 2, or (at your option)
  8. ## any later version.
  9. ##
  10. ## Octave is distributed in the hope that it will be useful, but
  11. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13. ## General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with Octave; see the file COPYING.  If not, write to the Free
  17. ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  18. ## 02111-1307, USA.
  19.  
  20. ## -*- texinfo -*-
  21. ## @deftypefn {Function File} {} fftconv (@var{a}, @var{b}, @var{n})
  22. ## Return the convolution of the vectors @var{a} and @var{b}, as a vector
  23. ## with length equal to the @code{length (a) + length (b) - 1}.  If @var{a}
  24. ## and @var{b} are the coefficient vectors of two polynoms, the returned
  25. ## value is the coefficient vector of the product polynom.
  26. ## 
  27. ## The computation uses the FFT by calling the function @code{fftfilt}.  If
  28. ## the optional argument @var{n} is specified, an N-point FFT is used.
  29. ## @end deftypefn
  30.  
  31. ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at>
  32. ## Created: 3 September 1994
  33. ## Adapted-By: jwe
  34.  
  35. function c = fftconv (a, b, N)
  36.  
  37.   if (nargin < 2 || nargin > 3)
  38.     usage ("fftconv (b, x [, N])");
  39.   endif
  40.  
  41.   if (! (is_vec (a) && is_vec (b)))
  42.     error ("fftconv:  both a and b should be vectors");
  43.   endif
  44.   la = length (a);
  45.   lb = length (b);
  46.   if ((la == 1) || (lb == 1))
  47.     c = a * b;
  48.   else
  49.     lc = la + lb - 1;
  50.     a(lc) = 0;
  51.     b(lc) = 0;
  52.     if (nargin == 2)
  53.       c = fftfilt (a, b);
  54.     else
  55.       if !(is_scal (N))
  56.     error ("fftconv: N has to be a scalar");
  57.       endif
  58.       c = fftfilt (a, b, N);
  59.     endif
  60.   endif
  61.  
  62. endfunction
  63.