787
|
1 function [b, r] = deconv (y, a) |
|
2 |
|
3 # Deconvolve two vectors. |
|
4 # |
|
5 # [b, r] = deconv (y, a) solves for b and r such that |
|
6 # y = conv(a,b) + r |
|
7 # |
|
8 # If y and a are polynomial coefficient vectors, b will contain the |
|
9 # coefficients of the polynomial quotient and r will be a remander |
|
10 # polynomial of lowest order. |
|
11 # |
|
12 # SEE ALSO: conv, poly, roots, residue, polyval, polyderiv, |
|
13 # polyinteg |
|
14 |
|
15 # Author: |
|
16 # Tony Richardson |
|
17 # amr@mpl.ucsd.edu |
|
18 # June 1994 |
|
19 |
|
20 if (nargin != 2) |
|
21 error ("usage: deconv (y,a)"); |
|
22 endif |
|
23 |
|
24 if (is_matrix (y) || is_matrix (a)) |
|
25 error("conv: both arguments must be vectors"); |
|
26 endif |
|
27 |
|
28 la = length (a); |
|
29 ly = length (y); |
|
30 |
|
31 lb = ly - la + 1; |
|
32 |
|
33 if (ly > la) |
|
34 b = filter (y, a, [1 zeros (1, ly - la)]); |
|
35 elseif (ly == la) |
|
36 b = filter (y, a, 1); |
|
37 else |
|
38 b = 0; |
|
39 endif |
|
40 |
|
41 b = polyreduce (b); |
|
42 |
|
43 lc = la + length (b) - 1; |
|
44 if (ly == lc) |
|
45 r = y - conv (a, b); |
|
46 else |
|
47 r = [ zeros(1, lc - ly) y] - conv (a, b); |
|
48 endif |
|
49 |
|
50 r = polyreduce (r); |
|
51 |
|
52 endfunction |