Mercurial > forge
changeset 2556:016d1bf54ec9 octave-forge
Fibonacci code split-stream sequence function to enable, easy decoding
author | gnumuthu |
---|---|
date | Mon, 02 Oct 2006 17:41:34 +0000 |
parents | 4546b7731be1 |
children | 710773a097c4 |
files | main/comm/INDEX main/comm/inst/fibodeco.m main/comm/inst/fiboenco.m main/comm/inst/fibosplitstream.m |
diffstat | 4 files changed, 97 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/main/comm/INDEX Mon Oct 02 11:53:18 2006 +0000 +++ b/main/comm/INDEX Mon Oct 02 17:41:34 2006 +0000 @@ -30,6 +30,7 @@ ricedeco fiboenco fibodeco + fibosplitstream Block Interleavers intrlv algintrlv
--- a/main/comm/inst/fibodeco.m Mon Oct 02 11:53:18 2006 +0000 +++ b/main/comm/inst/fibodeco.m Mon Oct 02 17:41:34 2006 +0000 @@ -17,9 +17,9 @@ ## ## -*- texinfo -*- -## @deftypefn {Function File} {@var{sig} = } fibodeco (@var{code}) +## @deftypefn {Function File} { } fibodeco (@var{code}) ## -## Returns the decoded fibonacci value from the binary vectors @var{code} . +## Returns the decoded fibonacci value from the binary vectors @var{code}. ## Universal codes like fibonacci codes Have a useful synchronization property, ## only for 255 maximum value we have designed these routines. We assume ## user has partitioned the code into several unique segments based on @@ -27,9 +27,7 @@ ## parts. Partitioning the stream is as simple as identifying the ## "11" pairs that occur, at the terminating ends. This system implements ## the standard binaary Fibonacci codes, which means that row vectors -## can only contain 0 or 1. -## -## Ref: http://en.wikipedia.org/wiki/Fibonacci_coding +## can only contain 0 or 1. Ref: http://en.wikipedia.org/wiki/Fibonacci_coding ## ## @example ## @group
--- a/main/comm/inst/fiboenco.m Mon Oct 02 11:53:18 2006 +0000 +++ b/main/comm/inst/fiboenco.m Mon Oct 02 17:41:34 2006 +0000 @@ -1,5 +1,4 @@ ## Copyright (C) 2006, Oct 2nd, Muthiah Annamalai,<muthiah.annamalai@uta.edu> -## Copyright (C) 2006, March 28,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 @@ -17,19 +16,20 @@ ## ## -*- texinfo -*- -## @deftypefn {Function File} {@var{op} = } fiboenco (@var{num}) +## @deftypefn {Function File} {} fiboenco (@var{num}) ## -## Returns the cell-array of encoded fibonacci value from the column vectors @var{num,val} . -## Universal codes like fibonacci codes have a useful synchronization property, -## only for 255 maximum value we have designed these routines. We assume +## Returns the cell-array of encoded fibonacci value from the column vectors @var{num}. +## Universal codes like fibonacci codes have a useful synchronization +## property, only for 255 maximum value we have designed these routines. We assume ## user has partitioned the code into several unique segments based on -## the suffix property of unique strings "11" and we just decode the -## parts. Partitioning the stream is as simple as identifying the -## "11" pairs that occur, at the terminating ends. This system implements +## the suffix property of unique elements [1 1] and we just decode the +## parts. Partitioning the stream is as simple as identifying the [1 1] +## pairs that occur, at the terminating ends. This system implements ## the standard binaary Fibonacci codes, which means that row vectors -## can only contain 0 or 1. -## -## Ref: http://en.wikipedia.org/wiki/Fibonacci_coding +## can only contain 0 or 1. Ref: http://en.wikipedia.org/wiki/Fibonacci_coding +## Ugly O(k.N^2) encoder.Ref: Wikipedia article accessed March, 2006. +## http://en.wikipedia.org/wiki/Fibonacci_coding, UCI Data Compression +## Book, http://www.ics.uci.edu/~dan/pubs/DC-Sec3.html,(accessed October 2006) ## ## @example ## @group @@ -40,14 +40,6 @@ ## @end deftypefn ## @seealso{fibodeco} -% -% -% Ugly O(k.N^2) encoder. -% -% Ref: Wikipedia article accessed March, 2006. http://en.wikipedia.org/wiki/Fibonacci_coding -% UCI Data Compression Book, http://www.ics.uci.edu/~dan/pubs/DC-Sec3.html, -% (accessed October 2006) -% function op_num=fiboenco(num) % % generate fibonacci series table.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/comm/inst/fibosplitstream.m Mon Oct 02 17:41:34 2006 +0000 @@ -0,0 +1,82 @@ +## Copyright (C) 2006, Oct 2nd, Muthiah Annamalai,<muthiah.annamalai@uta.edu> +## +## 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 2 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, write to the Free Software +## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +## + +## -*- texinfo -*- +## @deftypefn {Function File} { } fibosplitstream (@var{code}) +## +## Returns the split data stream at the word boundaries. +## Assuming the stream was originally encoded using @code{fiboenco} +## and this routine splits the stream at the points where '11' +## occur together & gives us the code-words which +## can later be decoded from the @code{fibodeco} This however doesnt +## mean that we intend to verify if all the codewords are correct, +## and infact the last symbol in th return list can or can-not be +## a valid codeword. +## +## A example use of @code{fibosplitstream} would be +## @example +## @group +## +## fibodeco(fibosplitstream([fiboenco(randint(1,100,[0 255])){:}])) +## fibodeco(fibosplitstream([fiboenco(1:10){:}])) +## +## @end group +## @end example +## @end deftypefn +## @seealso{fiboenco,fibodeco} +function symbols=fibosplitstream(stream) + if nargin < 1 + error('usage: fibosplitstream(stream); see help') + end + + symbols={}; + itr=1; + L=length(stream); + + % + % Plain & Simple Algorithm. O(N) + % Walk till marker '11' or find it. + % Then split & save. A little tricky to + % handle the edge case_ without tripping over. + % + idx=[]; + mark=1; + prev_bit=stream(1); + just_decoded=0; + + for i=2:L + if(~just_decoded && (stream(i)+prev_bit)==2 ) + symbols{itr}=[stream(mark:i)]; + mark=i+1; + prev_bit=0; + just_decoded=1; + itr=itr+1; + else + prev_bit=stream(i); + just_decoded=0; + end + + end + if(mark < L) + symbols{itr}=stream(mark:end); + end + + return +end +%! +%!assert(fibodeco(fibosplitstream([fiboenco(1:10)){:}]),[1:10]) +%! \ No newline at end of file