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} {} shannonfanoenco (@var{hcode},@var{dict})
19 ## Returns the Shannon Fano encoded signal using @var{dict}.
20 ## This function uses a @var{dict} built from the @code{shannonfanodict}
21 ## and uses it to encode a signal list into a shannon fano code.
22 ## Restrictions include a signal set that strictly belongs in the
23 ## @code{range [1,N]} with @code{N=length(dict)}. Also dict can only be
24 ## from the @code{shannonfanodict()} routine.
25 ## An example use of @code{shannonfanoenco} is
29 ## hd=shannonfanodict(1:4,[0.5 0.25 0.15 0.10])
30 ## shannonfanoenco(1:4,hd) # [ 0 1 0 1 1 0 1 1 1 0]
34 ## @seealso{shannonfanodeco, shannonfanodict}
37 function sf_code=shannonfanoenco(sig,dict)
39 error('usage: huffmanenco(sig,dict)');
41 if (max(sig) > length(dict)) || ( min(sig) < 1)
42 error("signal has elements that are outside alphabet set ...
49 %! assert(shannonfanoenco(1:4, shannonfanodict(1:4,[0.5 0.25 0.15 0.10])),[ 0 1 0 1 1 0 1 1 1 0],0)