how to decode to get the symbol number ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I'm currently constructing a code for truncated Huffman.I already encoded the program, but I don't know how to decode it back. Below is my encode coding. Supposedly, the output from huff will be decoded back to get the symbol number just like the table I provide. Please help me
clear all
clc
%decode truncated
input = [ 1 7 6 2 5];
huff = [];
for i=1:length(input)
if input(i) < 3 %level1
k = 1; %dec
h1 = 0 ;
h1 = dec2bin(h1,1);
t = input(i)-k ;
t1 = dec2bin(t,1);
elseif input(i) < 7 %level2
k = 3;
h1 = 2 ;
h1 = dec2bin(h1,2);
t = input(i)-k ;
t1 = dec2bin(t,2);
elseif input(i) < 15 %level3
k = 7;
h1 = 6 ;
h1 = dec2bin(h1,3);
t = input(i)-k ;
t1 = dec2bin(t,3);
elseif input(i)< 31 %level4
k= 15;
h1= 14;
h1 = dec2bin(h1,4);
t = input(i)-k ;
t1 = dec2bin(t,4);
huff_t4 = [h1 t1];
elseif input(i)< 63 %level5
k= 31;
h1= 30;
h1 = dec2bin(h1,5);
t = input(i)-k ;
t1 = dec2bin(t,5);
elseif input(i)< 127 %level6
k= 63;
h1= 62;
h1 = dec2bin(h1,6);
t = input(i)-k ;
t1 = dec2bin(t,6);
elseif input(i)< 255 %level7
k= 127;
h1= 126;
h1 = dec2bin(h1,7);
t = input(i)-k ;
t1 = dec2bin(t,7);
elseif input(i)< 511 %level8
k= 255;
h1= 254;
h1 = dec2bin(h1,8);
t = input(i)-k ;
t1 = dec2bin(t,8);
else
k= 511; %level9
h1= 510;
h1 = dec2bin(h1,9);
t = input(i)-k ;
t1 = dec2bin(t,9);
end
huff = [huff h1 t1];
end
disp(huff)
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Large Files and Big Data en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!