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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
2313
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
1025
|
18 |
3368
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} deconv (@var{y}, @var{a}) |
2311
|
21 ## Deconvolve two vectors. |
3426
|
22 ## |
3368
|
23 ## @code{[b, r] = deconv (y, a)} solves for @var{b} and @var{r} such that |
|
24 ## @code{y = conv (a, b) + r}. |
3426
|
25 ## |
3368
|
26 ## If @var{y} and @var{a} are polynomial coefficient vectors, @var{b} will |
|
27 ## contain the coefficients of the polynomial quotient and @var{r} will be |
7001
|
28 ## a remainder polynomial of lowest order. |
5642
|
29 ## @seealso{conv, poly, roots, residue, polyval, polyderiv, polyinteg} |
3368
|
30 ## @end deftypefn |
787
|
31 |
3202
|
32 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
33 ## Created: June 1994 |
|
34 ## Adapted-By: jwe |
787
|
35 |
2312
|
36 function [b, r] = deconv (y, a) |
787
|
37 |
|
38 if (nargin != 2) |
6046
|
39 print_usage (); |
787
|
40 endif |
|
41 |
4030
|
42 if (! (isvector (y) && isvector (a))) |
787
|
43 error("conv: both arguments must be vectors"); |
|
44 endif |
|
45 |
|
46 la = length (a); |
|
47 ly = length (y); |
|
48 |
|
49 lb = ly - la + 1; |
|
50 |
|
51 if (ly > la) |
1337
|
52 b = filter (y, a, [1, (zeros (1, ly - la))]); |
787
|
53 elseif (ly == la) |
|
54 b = filter (y, a, 1); |
|
55 else |
|
56 b = 0; |
|
57 endif |
|
58 |
|
59 lc = la + length (b) - 1; |
|
60 if (ly == lc) |
|
61 r = y - conv (a, b); |
|
62 else |
1337
|
63 r = [(zeros (1, lc - ly)), y] - conv (a, b); |
787
|
64 endif |
|
65 |
|
66 endfunction |