comparison scripts/polynomial/conv.m @ 1025:f558749713f1

[project @ 1995-01-11 20:52:10 by jwe]
author jwe
date Wed, 11 Jan 1995 20:52:10 +0000
parents 3470f1e25a79
children 611d403c7f3d
comparison
equal deleted inserted replaced
1024:56520a75b5b3 1025:f558749713f1
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
1 function y = conv (a, b) 19 function y = conv (a, b)
2 20
21 # usage: conv (a, b)
22 #
3 # Convolve two vectors. 23 # Convolve two vectors.
24 #
4 # y = conv (a, b) returns a vector of length equal to length (a) + 25 # y = conv (a, b) returns a vector of length equal to length (a) +
5 # length (b) -1. 26 # length (b) -1.
27 #
6 # If a and b are polynomial coefficient vectors, conv returns the 28 # If a and b are polynomial coefficient vectors, conv returns the
7 # coefficients of the product polynomial. 29 # coefficients of the product polynomial.
8 # 30 #
9 # SEE ALSO: deconv, poly, roots, residue, polyval, polyderiv, polyinteg 31 # SEE ALSO: deconv, poly, roots, residue, polyval, polyderiv, polyinteg
10 32
11 # Author: 33 # Written by Tony Richardson (amr@mpl.ucsd.edu) June 1994.
12 # Tony Richardson
13 # amr@mpl.ucsd.edu
14 # June 1994
15 34
16 if (nargin != 2) 35 if (nargin != 2)
17 usage (" conv(a,b)"); 36 usage ("conv(a, b)");
18 endif 37 endif
19 38
20 if (is_matrix(a) || is_matrix(b)) 39 if (is_matrix (a) || is_matrix (b))
21 error("conv: both arguments must be vectors"); 40 error("conv: both arguments must be vectors");
22 endif 41 endif
23 42
24 la = length (a); 43 la = length (a);
25 lb = length (b); 44 lb = length (b);
35 endif 54 endif
36 55
37 # Use the shortest vector as the coefficent vector to filter. 56 # Use the shortest vector as the coefficent vector to filter.
38 if (la < lb) 57 if (la < lb)
39 if (ly > lb) 58 if (ly > lb)
40 x = [b zeros (1, ly - lb)]; 59 x = [b, zeros (1, ly - lb)];
41 else 60 else
42 x = b; 61 x = b;
43 endif 62 endif
44 y = filter (a, 1, x); 63 y = filter (a, 1, x);
45 else 64 else
46 if(ly > la) 65 if(ly > la)
47 x = [a zeros (1, ly - la)]; 66 x = [a, zeros (1, ly - la)];
48 else 67 else
49 x = a; 68 x = a;
50 endif 69 endif
51 y = filter (b, 1, x); 70 y = filter (b, 1, x);
52 endif 71 endif