Huffman dictionary provided does not have the codes for all the input signals
2 views (last 30 days)
Show older comments
I seem to be having a problem passing the string and dictionary through the huffmanenco function. I've tried almost everything, but the I keep getting the error that the Huffman dictionary does not have all the input codes. Yet I'm positive it does.
%%HUFFMAN TEST
clear all; close all; clc;
sig = ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j';...
'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't';...
'u'; 'v'; 'w'; 'x'; 'y'; 'z'; ':'; ' '; ','; '.'];
% Get probability
char_count = zeros(30,1);
for i = 1:30
for c = sig(i)
char_count(i,1) = length(find(sig == c));
end
end
sym_prob = char_count / sum(char_count);
% Huffman Dictionary
% symbols = cellstr(symbols); % Still doesn't work in huffmandict, so try manually typing out again with curly braces
sig = {'a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'; 'i'; 'j';...
'k'; 'l'; 'm'; 'n'; 'o'; 'p'; 'q'; 'r'; 's'; 't';...
'u'; 'v'; 'w'; 'x'; 'y'; 'z'; ':'; ' '; ','; '.'};
[dict, aveLength] = huffmandict(sig, sym_prob);
% Process signal
str = 'A technique is developed to construct a representation of planar objects undergoing a general affine transformation. The representation can be used to describe planar or nearly planar objects in a three-dimensional space, observed by a camera under arbitrary orientations.';
str_int = bin2dec(dec2bin(str));
sig = cell(size(str));
for i = 1:length(str)
sig{i} = char(str_int(i));
end
% Encode & Decode
sig_enco = huffmanenco(sig, dict);
dsig = huffmandeco(sig_enco, dict);
0 Comments
Answers (0)
See Also
Categories
Find more on Source Coding in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!