787
|
1 function c = fftconv (a, b, N) |
|
2 |
|
3 # usage: fftconv (a, b [, N]) |
|
4 # |
|
5 # c = fftconv (a, b) returns the convolution of the vectors a and b, |
|
6 # a vector with length equal to length (a) + length (b) - 1. |
|
7 # If a and b are the coefficient vectors of two polynomials, c is |
|
8 # the coefficient vector of the product polynomial. |
|
9 # |
|
10 # The computation uses the FFT by calling fftfilt. If the optional |
|
11 # argument N is specified, an N-point FFT is used. |
|
12 |
|
13 # Written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Sep 3, 1994 |
|
14 # Copyright Dept of Statistics and Probability Theory TU Wien |
|
15 |
|
16 if (nargin < 2 || nargin > 3) |
|
17 error ("usage: fftconv (b, x [, N])"); |
|
18 endif |
|
19 |
|
20 if (is_matrix (a) || is_matrix (b)) |
|
21 error ("fftconv: both a and b should be vectors"); |
|
22 endif |
|
23 la = length (a); |
|
24 lb = length (b); |
|
25 if ((la == 1) || (lb == 1)) |
|
26 c = a * b; |
|
27 else |
|
28 lc = la + lb - 1; |
|
29 a(lc) = 0; |
|
30 b(lc) = 0; |
|
31 if (nargin == 2) |
|
32 c = fftfilt (a, b); |
|
33 else |
|
34 if !(is_scalar (N)) |
|
35 error ("fftconv: N has to be a scalar"); |
|
36 endif |
|
37 c = fftfilt (a, b, N); |
|
38 endif |
|
39 endif |
|
40 |
|
41 endfunction |