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 |
|
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 ## |
2325
|
30 ## SEE ALSO: deconv, poly, roots, residue, polyval, polyderiv, polyinteg |
2311
|
31 |
2312
|
32 ## Author: Tony Richardson <amr@mpl.ucsd.edu> |
|
33 ## Created: June 1994 |
|
34 ## Adapted-By: jwe |
|
35 |
787
|
36 function y = conv (a, b) |
2325
|
37 |
787
|
38 if (nargin != 2) |
1025
|
39 usage ("conv(a, b)"); |
787
|
40 endif |
|
41 |
2716
|
42 if (! (is_vector (a) && is_vector (b))) |
787
|
43 error("conv: both arguments must be vectors"); |
|
44 endif |
|
45 |
|
46 la = length (a); |
|
47 lb = length (b); |
|
48 |
|
49 ly = la + lb - 1; |
|
50 |
2303
|
51 ## Ensure that both vectors are row vectors. |
787
|
52 if (rows (a) > 1) |
|
53 a = reshape (a, 1, la); |
|
54 endif |
|
55 if (rows (b) > 1) |
|
56 b = reshape (b, 1, lb); |
|
57 endif |
|
58 |
2303
|
59 ## Use the shortest vector as the coefficent vector to filter. |
787
|
60 if (la < lb) |
|
61 if (ly > lb) |
1337
|
62 x = [b, (zeros (1, ly - lb))]; |
787
|
63 else |
|
64 x = b; |
|
65 endif |
|
66 y = filter (a, 1, x); |
|
67 else |
|
68 if(ly > la) |
1337
|
69 x = [a, (zeros (1, ly - la))]; |
787
|
70 else |
|
71 x = a; |
|
72 endif |
|
73 y = filter (b, 1, x); |
|
74 endif |
|
75 |
|
76 endfunction |