1026
|
1 # Copyright (C) 1995 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 the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # 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, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
787
|
19 function c = fftconv (a, b, N) |
|
20 |
1026
|
21 # usage: fftconv (a, b [, N]) |
904
|
22 # |
|
23 # c = fftconv (a, b) returns the convolution of the vectors a and b, |
|
24 # a vector with length equal to length (a) + length (b) - 1. |
|
25 # If a and b are the coefficient vectors of two polynomials, c is |
|
26 # the coefficient vector of the product polynomial. |
|
27 # |
|
28 # The computation uses the FFT by calling fftfilt. If the optional |
|
29 # argument N is specified, an N-point FFT is used. |
787
|
30 |
1026
|
31 # Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 3, 1994. |
787
|
32 |
|
33 if (nargin < 2 || nargin > 3) |
1026
|
34 usage ("fftconv (b, x [, N])"); |
787
|
35 endif |
|
36 |
|
37 if (is_matrix (a) || is_matrix (b)) |
|
38 error ("fftconv: both a and b should be vectors"); |
|
39 endif |
|
40 la = length (a); |
|
41 lb = length (b); |
|
42 if ((la == 1) || (lb == 1)) |
|
43 c = a * b; |
|
44 else |
|
45 lc = la + lb - 1; |
|
46 a(lc) = 0; |
|
47 b(lc) = 0; |
|
48 if (nargin == 2) |
|
49 c = fftfilt (a, b); |
|
50 else |
|
51 if !(is_scalar (N)) |
1026
|
52 error ("fftconv: N has to be a scalar"); |
787
|
53 endif |
|
54 c = fftfilt (a, b, N); |
|
55 endif |
|
56 endif |
|
57 |
|
58 endfunction |