1 ## Copyright (C) 2006 Muthiah Annamalai <muthiah.annamalai@uta.edu>
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} {} golombdeco (@var{code}, @var{m})
19 ## Returns the Golomb decoded signal vector using @var{code} and @var{m}.
20 ## Compulsory m is need to be specified. A restrictions is that a
21 ## signal set must strictly be non-negative. The value of code
22 ## is a cell array of row-vectors which have the encoded golomb value
23 ## for a single sample. The Golomb algorithm is,
24 ## used to encode the 'code' and only that can be meaningfully
25 ## decoded. @var{code} is assumed to have been of format generated
26 ## by the function @code{golombenco}. Also the parameter @var{m} need to
27 ## be a non-zero number, unless which it makes divide-by-zero errors.
28 ## This function works backward the Golomb algorithm see
29 ## @code{golombenco} for more detials on that.
30 ## Reference: Solomon Golomb, Run length Encodings, 1966 IEEE Trans Info' Theory
32 ## An exmaple of the use of @code{golombdeco} is
35 ## golombdeco(golombenco(1:4,2),2)
39 ## @seealso{golombenco}
41 ##! /usr/bin/octave -q
42 #A stress test routine
44 # sig=abs(randint(1,10,[0,255]));
46 # code=golombenco(sig,k);
47 # assert(golombdeco(code,k),sig)
51 # assert(golombdeco(golombenco(4:10,k),k),[4:10]);
54 function sig_op=golombdeco(code,m)
55 if ( nargin < 2 ) || (strcmp(class(code),"cell")~=1 || m<=0)
56 error('usage: golombdeco(code,m)');
61 partition_limit=2**C-m;
64 power_seq=[2.^(ceil(log2(m))-1:-1:0)];
65 power_seq_mod=power_seq(2:end);
74 word_tail=word(idx+1:end);
76 if(length(word_tail) == C)
77 r=sum(word_tail.*power_seq);
78 r=r-(partition_limit);
80 r=sum(word_tail.*power_seq_mod);
91 %! assert(golombdeco(golombenco(1:4,2),2),[1:4])