X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fcommunications-1.1.1%2Fricedeco.m;fp=octave_packages%2Fcommunications-1.1.1%2Fricedeco.m;h=ddf46fb3b78d75a1d1a7cc428bb6715159f56687;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/communications-1.1.1/ricedeco.m b/octave_packages/communications-1.1.1/ricedeco.m new file mode 100644 index 0000000..ddf46fb --- /dev/null +++ b/octave_packages/communications-1.1.1/ricedeco.m @@ -0,0 +1,80 @@ +## Copyright (C) 2006 Muthiah Annamalai +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {} ricedeco (@var{code}, @var{K}) +## +## Returns the Rice decoded signal vector using @var{code} and @var{K}. +## Compulsory K is need to be specified. +## A restrictions is that a signal set must strictly be non-negative. +## The value of code is a cell array of row-vectors which have the +## encoded rice value for a single sample. The Rice algorithm is +## used to encode the 'code' and only that can be meaningfully +## decoded. @var{code} is assumed to have been of format generated +## by the function @code{riceenco}. +## +## Reference: Solomon Golomb, Run length Encodings, 1966 IEEE Trans Info' Theory +## +## An exmaple of the use of @code{ricedeco} is +## @example +## @group +## ricedec(riceenco(1:4,2),2) +## +## @end group +## @end example +## @end deftypefn +## @seealso{riceenco} + +## +## +##! /usr/bin/octave -q +##A stress test routine +##for i=1:100 +## sig=abs(randint(1,10,[0,255])); +## [code,k]=riceenco(sig) +## sig_d=ricedeco(code,k) +## if(isequal(sig_d,sig)~=1) +## error('Some mistake in ricedeco/enco pair'); +## end +##end +## +function sig_op=ricedeco(code,K) + if ( nargin < 2 ) || (strcmp(class(code),"cell")~=1) + error('usage: ricedeco(code,K)'); + end + + L=length(code); + + K_pow_2=2**K; + + if(K ~= 0) + power_seq=[2.^((K-1):-1:0)]; + for j=1:L + word=code{j}; + idx=find(word==0)(1); + val=sum(word(1:idx)); + sig_op(j)=val*K_pow_2 + sum(word(idx+1:end).*power_seq); + end + else + for j=1:L + sig_op(j)=sum(code{j}); + end + end + + return +end +%! +%! assert(ricedeco(riceenco(1:4,2),2),[1:4]) +%!