2847
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
2313
|
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. |
1026
|
19 |
3367
|
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 polynomials, the returned |
|
25 ## value is the coefficient vector of the product polynomial. |
3426
|
26 ## |
3367
|
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 |
787
|
30 |
2312
|
31 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
32 ## Created: 3 September 1994 |
|
33 ## Adapted-By: jwe |
|
34 |
2311
|
35 function c = fftconv (a, b, N) |
787
|
36 |
|
37 if (nargin < 2 || nargin > 3) |
3449
|
38 usage ("fftconv (b, x, N)"); |
787
|
39 endif |
2325
|
40 |
4030
|
41 if (! (isvector (a) && isvector (b))) |
3457
|
42 error ("fftconv: both a and b should be vectors"); |
787
|
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 |
4030
|
55 if (! (isscalar (N))) |
3426
|
56 error ("fftconv: N has to be a scalar"); |
787
|
57 endif |
|
58 c = fftfilt (a, b, N); |
|
59 endif |
|
60 endif |
|
61 |
|
62 endfunction |