1 ## Copyright (C) 2002 David Bateman
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {} deconv (@var{y}, @var{a})
18 ## Deconvolve two Galois vectors.
20 ## @code{[b, r] = deconv (y, a)} solves for @var{b} and @var{r} such that
21 ## @code{y = conv (a, b) + r}.
23 ## If @var{y} and @var{a} are polynomial coefficient vectors, @var{b} will
24 ## contain the coefficients of the polynomial quotient and @var{r} will be
25 ## a remander polynomial of lowest order.
29 function [b, r] = deconv (y, a)
33 usage ("deconv(a, b)");
36 if (!isgalois (y) && !isgalois (a))
37 error("deconv: at least one argument must be a galois variable");
38 elseif (!isgalois (y))
39 y = gf(y, a.m, a.prim_poly);
40 elseif (!isgalois (a))
41 a = gf(a, y.m, y.prim_poly);
42 elseif (a.m != y.m && a.prim_poly != y.prim_poly)
43 error("deconv: both vectors must be in the same galois field");
46 if (min(size(a)) > 1 || min(size(y)) > 1)
47 error("deconv: both arguments must be vectors");
55 ## Ensure that both vectors are row vectors.
57 a = reshape (a, 1, la);
60 y = reshape (y, 1, ly);
64 b = filter (y, a, [1, (zeros (1, ly - la))]);
68 b = gf(0, y.m, y.prim_poly);
71 lc = la + length (b) - 1;
75 ## Can't concatenate galois variables like this yet
76 ## r = [(zeros (1, lc - ly)), y] - conv (a, b);
77 r = gf([(zeros (1, lc - ly)), y], y.m, y.prim_poly) - conv (a, b);