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