Mercurial > hg > octave-lyh
annotate scripts/polynomial/deconv.m @ 14200:64d9f33313cc stable rc-3-6-0-1
3.6.0-rc1 release candidate
* configure.ac (AC_INIT): Version is now 3.6.0-rc1.
(OCTAVE_RELEASE_DATE): Now 2012-01-12.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 12 Jan 2012 14:31:50 -0500 |
parents | 72c96de7a403 |
children | f3d52523cde1 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
14104
diff
changeset
|
1 ## Copyright (C) 1994-2012 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
1025 | 18 |
3368 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} deconv (@var{y}, @var{a}) | |
2311 | 21 ## Deconvolve two vectors. |
3426 | 22 ## |
3368 | 23 ## @code{[b, r] = deconv (y, a)} solves for @var{b} and @var{r} such that |
24 ## @code{y = conv (a, b) + r}. | |
3426 | 25 ## |
3368 | 26 ## If @var{y} and @var{a} are polynomial coefficient vectors, @var{b} will |
27 ## contain the coefficients of the polynomial quotient and @var{r} will be | |
7001 | 28 ## a remainder polynomial of lowest order. |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
13963
diff
changeset
|
29 ## @seealso{conv, residue} |
3368 | 30 ## @end deftypefn |
787 | 31 |
3202 | 32 ## Author: Tony Richardson <arichard@stark.cc.oh.us> |
2312 | 33 ## Created: June 1994 |
34 ## Adapted-By: jwe | |
787 | 35 |
2312 | 36 function [b, r] = deconv (y, a) |
787 | 37 |
38 if (nargin != 2) | |
6046 | 39 print_usage (); |
787 | 40 endif |
41 | |
4030 | 42 if (! (isvector (y) && isvector (a))) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10224
diff
changeset
|
43 error("deconv: both arguments must be vectors"); |
787 | 44 endif |
45 | |
46 la = length (a); | |
47 ly = length (y); | |
48 | |
49 lb = ly - la + 1; | |
50 | |
8159
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
51 ## Ensure A is oriented as Y. |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
52 if (diff (size (y)(1:2)) * diff (size (a)(1:2)) < 0) |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
53 a = permute (a, [2, 1]); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
54 endif |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
55 |
787 | 56 if (ly > la) |
10740
6cc789b3f0e3
scripts/polynomial/deconv.m: ensure that the orientation of the third input to 'filter' matches the orientation of 'y'.
Soren Hauberg <hauberg@gmail.com>
parents:
10635
diff
changeset
|
57 x = zeros (size (y) - size (a) + 1); |
6cc789b3f0e3
scripts/polynomial/deconv.m: ensure that the orientation of the third input to 'filter' matches the orientation of 'y'.
Soren Hauberg <hauberg@gmail.com>
parents:
10635
diff
changeset
|
58 x (1) = 1; |
6cc789b3f0e3
scripts/polynomial/deconv.m: ensure that the orientation of the third input to 'filter' matches the orientation of 'y'.
Soren Hauberg <hauberg@gmail.com>
parents:
10635
diff
changeset
|
59 b = filter (y, a, x); |
787 | 60 elseif (ly == la) |
61 b = filter (y, a, 1); | |
62 else | |
63 b = 0; | |
64 endif | |
65 | |
66 lc = la + length (b) - 1; | |
67 if (ly == lc) | |
68 r = y - conv (a, b); | |
69 else | |
8159
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
70 ## Respect the orientation of Y" |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
71 if (size (y, 1) <= size (y, 2)) |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
72 r = [(zeros (1, lc - ly)), y] - conv (a, b); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
73 else |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
74 r = [(zeros (lc - ly, 1)); y] - conv (a, b); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
75 endif |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
76 if (ly < la) |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
77 ## Trim the remainder is equal to the length of Y. |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
78 r = r(end-(length(y)-1):end); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
79 endif |
787 | 80 endif |
81 | |
82 endfunction | |
7411 | 83 |
84 %!test | |
85 %! [b, r] = deconv ([3, 6, 9, 9], [1, 2, 3]); | |
86 %! assert(all (all (b == [3, 0])) && all (all (r == [0, 0, 0, 9]))); | |
87 | |
88 %!test | |
89 %! [b, r] = deconv ([3, 6], [1, 2, 3]); | |
8159
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
90 %! assert(b == 0 && all (all (r == [3, 6]))); |
7411 | 91 |
92 %!test | |
93 %! [b, r] = deconv ([3, 6], [1; 2; 3]); | |
8159
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
94 %! assert(b == 0 && all (all (r == [3, 6]))); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
95 |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
96 %!test |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
97 %! [b,r] = deconv ([3; 6], [1; 2; 3]); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
98 %! assert (b == 0 && all (all (r == [3; 6]))) |
7411 | 99 |
8159
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
100 %!test |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
101 %! [b, r] = deconv ([3; 6], [1, 2, 3]); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
102 %! assert (b == 0 && all (all (r == [3; 6]))) |
7411 | 103 |
10740
6cc789b3f0e3
scripts/polynomial/deconv.m: ensure that the orientation of the third input to 'filter' matches the orientation of 'y'.
Soren Hauberg <hauberg@gmail.com>
parents:
10635
diff
changeset
|
104 %!test |
6cc789b3f0e3
scripts/polynomial/deconv.m: ensure that the orientation of the third input to 'filter' matches the orientation of 'y'.
Soren Hauberg <hauberg@gmail.com>
parents:
10635
diff
changeset
|
105 %! assert (deconv ((1:3)',[1, 1]), [1; 1]) |
6cc789b3f0e3
scripts/polynomial/deconv.m: ensure that the orientation of the third input to 'filter' matches the orientation of 'y'.
Soren Hauberg <hauberg@gmail.com>
parents:
10635
diff
changeset
|
106 |
8159
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
107 %!error [b, r] = deconv ([3, 6], [1, 2; 3, 4]); |
7411 | 108 |
8159
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
109 %!error [b, r] = deconv ([3, 6; 1, 2], [1, 2, 3]); |
ccf38fc1057f
deconv.m: Fix row/col orientation & length of output
Ben Abbott <bpabbott@mac.com>
parents:
7411
diff
changeset
|
110 |