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 |
|
29 ## a remander polynomial of lowest order. |
|
30 ## @end deftypefn |
5053
|
31 ## |
3457
|
32 ## @seealso{conv, poly, roots, residue, polyval, polyderiv, and polyinteg} |
787
|
33 |
3202
|
34 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312
|
35 ## Created: June 1994 |
|
36 ## Adapted-By: jwe |
787
|
37 |
2312
|
38 function [b, r] = deconv (y, a) |
787
|
39 |
|
40 if (nargin != 2) |
1025
|
41 usage ("deconv (y, a)"); |
787
|
42 endif |
|
43 |
4030
|
44 if (! (isvector (y) && isvector (a))) |
787
|
45 error("conv: both arguments must be vectors"); |
|
46 endif |
|
47 |
|
48 la = length (a); |
|
49 ly = length (y); |
|
50 |
|
51 lb = ly - la + 1; |
|
52 |
|
53 if (ly > la) |
1337
|
54 b = filter (y, a, [1, (zeros (1, ly - la))]); |
787
|
55 elseif (ly == la) |
|
56 b = filter (y, a, 1); |
|
57 else |
|
58 b = 0; |
|
59 endif |
|
60 |
|
61 lc = la + length (b) - 1; |
|
62 if (ly == lc) |
|
63 r = y - conv (a, b); |
|
64 else |
1337
|
65 r = [(zeros (1, lc - ly)), y] - conv (a, b); |
787
|
66 endif |
|
67 |
|
68 endfunction |