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} {} fiboenco (@var{num})
19 ## Returns the cell-array of encoded fibonacci value from the column vectors @var{num}.
20 ## Universal codes like fibonacci codes have a useful synchronization
21 ## property, 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 elements [1 1] and we just decode the
24 ## parts. Partitioning the stream is as simple as identifying the [1 1]
25 ## 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: http://en.wikipedia.org/wiki/Fibonacci_coding
28 ## Ugly O(k.N^2) encoder.Ref: Wikipedia article accessed March, 2006.
29 ## @url{http://en.wikipedia.org/wiki/Fibonacci_coding}, UCI Data Compression
30 ## Book, @url{http://www.ics.uci.edu/~dan/pubs/DC-Sec3.html}, (accessed
35 ## fiboenco(10) #= code is @{[ 0 1 0 0 1 1]@}
36 ## fiboenco(1:4) #= code is @{[1 1],[0 1 1],[0 0 1 1],[1 0 1 1]@}
42 function op_num=fiboenco(num)
44 % generate fibonacci series table.
49 % while ((f(end-1)+f(end)) < 256)
50 % val=(f(end-1)+f(end));
53 % f=sort(f(2:end),"descend");
56 %f= [75025 46368 28657 17711 10946 6765 4181 2584 \
57 % 1597 987 610 377 233 144 89 55 \
58 % 34 21 13 8 5 3 2 1];
60 if(nargin < 1) || (min(num) <= 0 || max(num) > 608)
61 error("Usage:fiboenco(num), where num is +ve sequence of numbers ...
62 and less than equal to 608");
64 f= [ 233 144 89 55 34 21 13 8 5 3 2 1];
74 %create Fibonacci encoding of a number
75 for i=find(f<=N):LEN_F
88 %!assert(fibodeco(fiboenco(1:600)),[1:600])