]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/@galois/deconv.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / @galois / deconv.m
1 ## Copyright (C) 2002 David Bateman
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {} deconv (@var{y}, @var{a})
18 ## Deconvolve two Galois vectors.
19 ##
20 ## @code{[b, r] = deconv (y, a)} solves for @var{b} and @var{r} such that
21 ## @code{y = conv (a, b) + r}.
22 ##
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.
26 ## @end deftypefn
27 ## @seealso{conv}
28
29 function [b, r] = deconv (y, a)
30
31
32   if (nargin != 2)
33     usage ("deconv(a, b)");
34   endif
35
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");
44   endif
45   
46   if (min(size(a)) > 1 || min(size(y)) > 1)
47     error("deconv: both arguments must be vectors");
48   endif
49
50   la = length (a);
51   ly = length (y);
52
53   lb = ly - la + 1;
54
55   ## Ensure that both vectors are row vectors.
56   if (rows (a) > 1)
57     a = reshape (a, 1, la);
58   endif
59   if (rows (y) > 1)
60     y = reshape (y, 1, ly);
61   endif
62   
63   if (ly > la)
64     b = filter (y, a, [1, (zeros (1, ly - la))]);
65   elseif (ly == la)
66     b = filter (y, a, 1);
67   else
68     b = gf(0, y.m, y.prim_poly);
69   endif
70
71   lc = la + length (b) - 1;
72   if (ly == lc)
73     r = y - conv (a, b);
74   else
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);
78   endif
79
80 endfunction