1025
|
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 |
787
|
19 function y = conv (a, b) |
|
20 |
1025
|
21 # usage: conv (a, b) |
|
22 # |
904
|
23 # Convolve two vectors. |
1025
|
24 # |
904
|
25 # y = conv (a, b) returns a vector of length equal to length (a) + |
|
26 # length (b) -1. |
1025
|
27 # |
904
|
28 # If a and b are polynomial coefficient vectors, conv returns the |
|
29 # coefficients of the product polynomial. |
|
30 # |
|
31 # SEE ALSO: deconv, poly, roots, residue, polyval, polyderiv, polyinteg |
787
|
32 |
1025
|
33 # Written by Tony Richardson (amr@mpl.ucsd.edu) June 1994. |
787
|
34 |
|
35 if (nargin != 2) |
1025
|
36 usage ("conv(a, b)"); |
787
|
37 endif |
|
38 |
1025
|
39 if (is_matrix (a) || is_matrix (b)) |
787
|
40 error("conv: both arguments must be vectors"); |
|
41 endif |
|
42 |
|
43 la = length (a); |
|
44 lb = length (b); |
|
45 |
|
46 ly = la + lb - 1; |
|
47 |
|
48 # Ensure that both vectors are row vectors. |
|
49 if (rows (a) > 1) |
|
50 a = reshape (a, 1, la); |
|
51 endif |
|
52 if (rows (b) > 1) |
|
53 b = reshape (b, 1, lb); |
|
54 endif |
|
55 |
|
56 # Use the shortest vector as the coefficent vector to filter. |
|
57 if (la < lb) |
|
58 if (ly > lb) |
1025
|
59 x = [b, zeros (1, ly - lb)]; |
787
|
60 else |
|
61 x = b; |
|
62 endif |
|
63 y = filter (a, 1, x); |
|
64 else |
|
65 if(ly > la) |
1025
|
66 x = [a, zeros (1, ly - la)]; |
787
|
67 else |
|
68 x = a; |
|
69 endif |
|
70 y = filter (b, 1, x); |
|
71 endif |
|
72 |
|
73 endfunction |