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 |
1315
|
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1025
|
18 |
787
|
19 function [b, r] = deconv (y, a) |
|
20 |
1025
|
21 # usage: deconv (y, a) |
|
22 # |
904
|
23 # Deconvolve two vectors. |
|
24 # |
|
25 # [b, r] = deconv (y, a) solves for b and r such that |
|
26 # y = conv(a,b) + r |
|
27 # |
|
28 # If y and a are polynomial coefficient vectors, b will contain the |
|
29 # coefficients of the polynomial quotient and r will be a remander |
|
30 # polynomial of lowest order. |
|
31 # |
|
32 # SEE ALSO: conv, poly, roots, residue, polyval, polyderiv, |
|
33 # polyinteg |
787
|
34 |
1025
|
35 # Written by Tony Richardson (amr@mpl.ucsd.edu) June 1994. |
787
|
36 |
|
37 if (nargin != 2) |
1025
|
38 usage ("deconv (y, a)"); |
787
|
39 endif |
|
40 |
|
41 if (is_matrix (y) || is_matrix (a)) |
|
42 error("conv: both arguments must be vectors"); |
|
43 endif |
|
44 |
|
45 la = length (a); |
|
46 ly = length (y); |
|
47 |
|
48 lb = ly - la + 1; |
|
49 |
|
50 if (ly > la) |
1337
|
51 b = filter (y, a, [1, (zeros (1, ly - la))]); |
787
|
52 elseif (ly == la) |
|
53 b = filter (y, a, 1); |
|
54 else |
|
55 b = 0; |
|
56 endif |
|
57 |
|
58 b = polyreduce (b); |
|
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 r = polyreduce (r); |
|
68 |
|
69 endfunction |