I am working on compressing an arbitrary vector with MATLAB, which provides factory methods for Huffman Coding: huffmandict, huffmanenco, huffmandeco.
The huffmandict function produces a lookup table mapping each symbol in the signal we want to encode to its corresponding codeword which is needed to encode and then decode the signal.
It is trivial to generate the dictionary when you know the input vector. But say I'm compressing to send from Alice to Bob - I can't assume Bob knows the dictionary too - so Alice needs to send the dictionary along with the huffman code!
Is there a way in MATLAB of generating a bitstream representation of the dictionary to be prepended to our huffman code to allow for it to be decoded at the other end?
What I'm thinking is the resulting code looks like if N is the length of the encoded dictionary:
(N encoded as 8 bits)(huffman dict encoded in N bits)(huffman code)
It seems odds that MATLAB provides quite powerful factory methods for the encoding but then does not even bother to make it actually usable in digital transmission with a lot of extra work.
I understand that in the theory, a huffman tree is often built - is there a way to generate this in MATLAB, and then convert such tree back to a dictionary?