2313
|
1 ## Copyright (C) 1996 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. |
1026
|
19 |
2311
|
20 ## usage: fftconv (a, b [, N]) |
|
21 ## |
|
22 ## c = fftconv (a, b) returns the convolution of the vectors a and b, |
2325
|
23 ## a vector with length equal to length (a) + length (b) - 1. |
2311
|
24 ## If a and b are the coefficient vectors of two polynomials, c is |
|
25 ## the coefficient vector of the product polynomial. |
|
26 ## |
|
27 ## The computation uses the FFT by calling fftfilt. If the optional |
|
28 ## argument N is specified, an N-point FFT is used. |
787
|
29 |
2312
|
30 ## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> |
|
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) |
1026
|
37 usage ("fftconv (b, x [, N])"); |
787
|
38 endif |
2325
|
39 |
787
|
40 if (is_matrix (a) || is_matrix (b)) |
|
41 error ("fftconv: both a and b should be vectors"); |
|
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 |
|
54 if !(is_scalar (N)) |
1026
|
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 |