changeset 8159:ccf38fc1057f

deconv.m: Fix row/col orientation & length of output
author Ben Abbott <bpabbott@mac.com>
date Mon, 29 Sep 2008 13:36:17 -0400
parents 15e4a450bf84
children 436438954797
files scripts/ChangeLog scripts/polynomial/deconv.m
diffstat 2 files changed, 29 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Mon Sep 29 09:33:06 2008 -0400
+++ b/scripts/ChangeLog	Mon Sep 29 13:36:17 2008 -0400
@@ -1,5 +1,7 @@
 2008-09-29  Ben Abbott <bpabbott@mac.com>
 
+	* polynomial/deconv.m: Fix row/col orientation & length of output.
+
 	* polynomial/conv.m: Correct row/col orientation of output.
 
 2008-09-26  David Bateman  <dbateman@free.fr>
--- a/scripts/polynomial/deconv.m	Mon Sep 29 09:33:06 2008 -0400
+++ b/scripts/polynomial/deconv.m	Mon Sep 29 13:36:17 2008 -0400
@@ -49,6 +49,11 @@
 
   lb = ly - la + 1;
 
+  ## Ensure A is oriented as Y.
+  if (diff (size (y)(1:2)) * diff (size (a)(1:2)) < 0)
+    a = permute (a, [2, 1]);
+  endif
+
   if (ly > la)
     b = filter (y, a, [1, (zeros (1, ly - la))]);
   elseif (ly == la)
@@ -61,7 +66,16 @@
   if (ly == lc)
     r = y - conv (a, b);
   else
-    r = [(zeros (1, lc - ly)), y] - conv (a, b);
+    ## Respect the orientation of Y"
+    if (size (y, 1) <= size (y, 2))
+      r = [(zeros (1, lc - ly)), y] - conv (a, b);
+    else
+      r = [(zeros (lc - ly, 1)); y] - conv (a, b);
+    endif
+    if (ly < la)
+      ## Trim the remainder is equal to the length of Y.
+      r = r(end-(length(y)-1):end);
+    endif
   endif
 
 endfunction
@@ -72,13 +86,21 @@
 
 %!test
 %! [b, r] = deconv ([3, 6], [1, 2, 3]);
-%! assert(b == 0 && all (all (r == [0, 3, 6])));
+%! assert(b == 0 && all (all (r == [3, 6])));
 
 %!test
 %! [b, r] = deconv ([3, 6], [1; 2; 3]);
-%! assert(b == 0 && all (all (r == [0, 3, 6])));
+%! assert(b == 0 && all (all (r == [3, 6])));
+
+%!test
+%! [b,r] = deconv ([3; 6], [1; 2; 3]);
+%! assert (b == 0 && all (all (r == [3; 6])))
 
-%!error [b, r] = deconv ([3, 6], [1, 2; 3, 4]);;
+%!test
+%! [b, r] = deconv ([3; 6], [1, 2, 3]);
+%! assert (b == 0 && all (all (r == [3; 6])))
 
-%!error <number of rows must match> [b, r] = deconv ([3; 6], [1, 2, 3]);
+%!error [b, r] = deconv ([3, 6], [1, 2; 3, 4]);
 
+%!error [b, r] = deconv ([3, 6; 1, 2], [1, 2, 3]);
+