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} {} ricedeco (@var{code}, @var{K})
19 ## Returns the Rice decoded signal vector using @var{code} and @var{K}.
20 ## Compulsory K is need to be specified.
21 ## A restrictions is that a signal set must strictly be non-negative.
22 ## The value of code is a cell array of row-vectors which have the
23 ## encoded rice value for a single sample. The Rice 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{riceenco}.
28 ## Reference: Solomon Golomb, Run length Encodings, 1966 IEEE Trans Info' Theory
30 ## An exmaple of the use of @code{ricedeco} is
33 ## ricedec(riceenco(1:4,2),2)
42 ##! /usr/bin/octave -q
43 ##A stress test routine
45 ## sig=abs(randint(1,10,[0,255]));
46 ## [code,k]=riceenco(sig)
47 ## sig_d=ricedeco(code,k)
48 ## if(isequal(sig_d,sig)~=1)
49 ## error('Some mistake in ricedeco/enco pair');
53 function sig_op=ricedeco(code,K)
54 if ( nargin < 2 ) || (strcmp(class(code),"cell")~=1)
55 error('usage: ricedeco(code,K)');
63 power_seq=[2.^((K-1):-1:0)];
68 sig_op(j)=val*K_pow_2 + sum(word(idx+1:end).*power_seq);
72 sig_op(j)=sum(code{j});
79 %! assert(ricedeco(riceenco(1:4,2),2),[1:4])