2303
|
1 ### Copyright (C) 1996 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 |
|
7 ### the Free Software Foundation; either version 2, or (at your option) |
|
8 ### any later version. |
|
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 |
|
16 ### along with Octave; see the file COPYING. If not, write to the Free |
|
17 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ### 02111-1307, USA. |
1025
|
19 |
2311
|
20 ## usage: conv (a, b) |
|
21 ## |
|
22 ## Convolve two vectors. |
|
23 ## |
|
24 ## y = conv (a, b) returns a vector of length equal to length (a) + |
|
25 ## length (b) -1. |
|
26 ## |
|
27 ## If a and b are polynomial coefficient vectors, conv returns the |
|
28 ## coefficients of the product polynomial. |
|
29 ## |
|
30 ## SEE ALSO: deconv, poly, roots, residue, polyval, polyderiv, polyinteg |
|
31 |
787
|
32 function y = conv (a, b) |
|
33 |
2303
|
34 ## Written by Tony Richardson (amr@mpl.ucsd.edu) June 1994. |
787
|
35 |
|
36 if (nargin != 2) |
1025
|
37 usage ("conv(a, b)"); |
787
|
38 endif |
|
39 |
1025
|
40 if (is_matrix (a) || is_matrix (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 |