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/>. |
1025
|
18 |
3368
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} conv (@var{a}, @var{b}) |
2311
|
21 ## Convolve two vectors. |
3426
|
22 ## |
3368
|
23 ## @code{y = conv (a, b)} returns a vector of length equal to |
|
24 ## @code{length (a) + length (b) - 1}. |
|
25 ## If @var{a} and @var{b} are polynomial coefficient vectors, @code{conv} |
|
26 ## returns the coefficients of the product polynomial. |
5642
|
27 ## @seealso{deconv, poly, roots, residue, polyval, polyderiv, polyinteg} |
3368
|
28 ## @end deftypefn |
2311
|
29 |
3202
|
30 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
31 ## Created: June 1994 |
|
32 ## Adapted-By: jwe |
|
33 |
787
|
34 function y = conv (a, b) |
2325
|
35 |
787
|
36 if (nargin != 2) |
6046
|
37 print_usage (); |
787
|
38 endif |
|
39 |
4030
|
40 if (! (isvector (a) && isvector (b))) |
787
|
41 error("conv: both arguments must be vectors"); |
|
42 endif |
|
43 |
|
44 la = length (a); |
|
45 lb = length (b); |
|
46 |
|
47 ly = la + lb - 1; |
|
48 |
2303
|
49 ## Ensure that both vectors are row vectors. |
787
|
50 if (rows (a) > 1) |
|
51 a = reshape (a, 1, la); |
|
52 endif |
|
53 if (rows (b) > 1) |
|
54 b = reshape (b, 1, lb); |
|
55 endif |
|
56 |
2303
|
57 ## Use the shortest vector as the coefficent vector to filter. |
787
|
58 if (la < lb) |
|
59 if (ly > lb) |
1337
|
60 x = [b, (zeros (1, ly - lb))]; |
787
|
61 else |
|
62 x = b; |
|
63 endif |
|
64 y = filter (a, 1, x); |
|
65 else |
|
66 if(ly > la) |
1337
|
67 x = [a, (zeros (1, ly - la))]; |
787
|
68 else |
|
69 x = a; |
|
70 endif |
|
71 y = filter (b, 1, x); |
|
72 endif |
|
73 |
|
74 endfunction |