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} { } fibodeco (@var{code})
19 ## Returns the decoded fibonacci value from the binary vectors @var{code}.
20 ## Universal codes like fibonacci codes Have a useful synchronization property,
21 ## only for 255 maximum value we have designed these routines. We assume
22 ## user has partitioned the code into several unique segments based on
23 ## the suffix property of unique strings "11" and we just decode the
24 ## parts. Partitioning the stream is as simple as identifying the
25 ## "11" pairs that occur, at the terminating ends. This system implements
26 ## the standard binaary Fibonacci codes, which means that row vectors
27 ## can only contain 0 or 1. Ref: @url{http://en.wikipedia.org/wiki/Fibonacci_coding}
31 ## fibodeco(@{[0 1 0 0 1 1]@}) %decoded to 10
32 ## fibodeco(@{[1 1],[0 1 1],[0 0 1 1],[1 0 1 1]@}) %[1:4]
38 function num=fibodeco(code)
40 ## generate fibonacci series table.
45 ## while ((f(end-1)+f(end)) < 256)
46 ## val=(f(end-1)+f(end));
51 ##all numbers terminate with 1 except 0 itself.
54 ##f= [75025 46368 28657 17711 10946 6765 4181 2584 \
55 ## 1597 987 610 377 233 144 89 55 \
56 ## 34 21 13 8 5 3 2 1];
58 ##f= [ 233 144 89 55 34 21 13 8 5 3 2 1];
60 f= [ 1 2 3 5 8 13 21 34 55 89 144 233];
64 error("Usage:fibodec(cell-array vectors), where each vector is +ve sequence of numbers ...
70 ##discard the terminating 1.
73 num(j)=sum(word.*f(1:L));
79 %! assert(fibodeco({[1 1],[0 1 1],[0 0 1 1],[1 0 1 1]}),[1:4])
80 %! assert(fibodeco({[0 1 0 0 1 1]}),10)