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: deconv (y, a) |
|
21 ## |
|
22 ## Deconvolve two vectors. |
|
23 ## |
2325
|
24 ## [b, r] = deconv (y, a) solves for b and r such that |
2311
|
25 ## y = conv(a,b) + r |
|
26 ## |
|
27 ## If y and a are polynomial coefficient vectors, b will contain the |
|
28 ## coefficients of the polynomial quotient and r will be a remander |
|
29 ## polynomial of lowest order. |
|
30 ## |
|
31 ## SEE ALSO: conv, poly, roots, residue, polyval, polyderiv, |
2325
|
32 ## 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 |
2716
|
44 if (! (is_vector (y) && is_vector (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 b = polyreduce (b); |
|
62 |
|
63 lc = la + length (b) - 1; |
|
64 if (ly == lc) |
|
65 r = y - conv (a, b); |
|
66 else |
1337
|
67 r = [(zeros (1, lc - ly)), y] - conv (a, b); |
787
|
68 endif |
|
69 |
|
70 r = polyreduce (r); |
|
71 |
|
72 endfunction |