comparison scripts/polynomial/conv.m @ 787:c5d35bb139b6

[project @ 1994-10-11 00:34:13 by jwe] Initial revision
author jwe
date Tue, 11 Oct 1994 00:34:39 +0000
parents
children 3470f1e25a79
comparison
equal deleted inserted replaced
786:4fcd2e68dd3b 787:c5d35bb139b6
1 function y = conv (a, b)
2
3 # Convolve two vectors.
4 # y = conv (a, b) returns a vector of length equal to length (a) +
5 # length (b) -1.
6 # If a and b are polynomial coefficient vectors, conv returns the
7 # coefficients of the product polynomial.
8 #
9 # SEE ALSO: deconv, poly, roots, residue, polyval, polyderiv,
10 # polyinteg
11
12 # Author:
13 # Tony Richardson
14 # amr@mpl.ucsd.edu
15 # June 1994
16
17 if (nargin != 2)
18 error ("usage: conv(a,b)");
19 endif
20
21 if (is_matrix(a) || is_matrix(b))
22 error("conv: both arguments must be vectors");
23 endif
24
25 la = length (a);
26 lb = length (b);
27
28 ly = la + lb - 1;
29
30 # Ensure that both vectors are row vectors.
31 if (rows (a) > 1)
32 a = reshape (a, 1, la);
33 endif
34 if (rows (b) > 1)
35 b = reshape (b, 1, lb);
36 endif
37
38 # Use the shortest vector as the coefficent vector to filter.
39 if (la < lb)
40 if (ly > lb)
41 x = [b zeros (1, ly - lb)];
42 else
43 x = b;
44 endif
45 y = filter (a, 1, x);
46 else
47 if(ly > la)
48 x = [a zeros (1, ly - la)];
49 else
50 x = a;
51 endif
52 y = filter (b, 1, x);
53 endif
54
55 endfunction