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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
1026
|
18 |
3367
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} fftconv (@var{a}, @var{b}, @var{n}) |
|
21 ## Return the convolution of the vectors @var{a} and @var{b}, as a vector |
|
22 ## with length equal to the @code{length (a) + length (b) - 1}. If @var{a} |
|
23 ## and @var{b} are the coefficient vectors of two polynomials, the returned |
|
24 ## value is the coefficient vector of the product polynomial. |
3426
|
25 ## |
3367
|
26 ## The computation uses the FFT by calling the function @code{fftfilt}. If |
|
27 ## the optional argument @var{n} is specified, an N-point FFT is used. |
|
28 ## @end deftypefn |
787
|
29 |
5428
|
30 ## Author: KH <Kurt.Hornik@wu-wien.ac.at> |
2312
|
31 ## Created: 3 September 1994 |
|
32 ## Adapted-By: jwe |
|
33 |
2311
|
34 function c = fftconv (a, b, N) |
787
|
35 |
|
36 if (nargin < 2 || nargin > 3) |
6046
|
37 print_usage (); |
787
|
38 endif |
2325
|
39 |
4030
|
40 if (! (isvector (a) && isvector (b))) |
3457
|
41 error ("fftconv: both a and b should be vectors"); |
787
|
42 endif |
|
43 la = length (a); |
|
44 lb = length (b); |
|
45 if ((la == 1) || (lb == 1)) |
|
46 c = a * b; |
|
47 else |
|
48 lc = la + lb - 1; |
|
49 a(lc) = 0; |
|
50 b(lc) = 0; |
|
51 if (nargin == 2) |
|
52 c = fftfilt (a, b); |
|
53 else |
4030
|
54 if (! (isscalar (N))) |
3426
|
55 error ("fftconv: N has to be a scalar"); |
787
|
56 endif |
|
57 c = fftfilt (a, b, N); |
|
58 endif |
|
59 endif |
|
60 |
|
61 endfunction |