MATLAB: Regarding Huffman Encoding and Decoding

huffman coding

I want to encode and decode a signal sing Huffman coding. After partition and codebook formation, I quantize the signal using MATLAB in-built function 'quantiz'. Then dictionary, encoding and decoding are being done using MATLAB in-built functions 'huffmandict','huffmanenco','huffmandeco'.
My question is that is it necessary to send the dictionary information i.e. index values with encoded binary data for each index too during transmission to the receiver side OR only the encoded binary stream.

Best Answer

Information about the dictionary must be sent whenever it changes.
It is permitted to encode multiple signals with the same dictionary and to only send the dictionary once for the group. Any one dictionary might not be completely optimal for any one signal, but the cost of sending a complete new dictionary might be high enough to make it worth re-using the less-efficient dictionary.
It is also permitted to encode a dictionary number as part of the encoded signal, and to have sent multiple dictionaries, with the dictionary number referring back to any of the previously-sent dictionaries that are certain to still be present on the receiving side. The receiving side would not have persistent storage enough to hold an indefinite number of dictionaries (possibly only room for a few), so the rule would be to resend any particular dictionary that is needed if you are not certain that the receiver still has it in current storage. If communications between the systems is two-way and not of long latency, then it could be worthwhile to implement a "query present dictionaries" protocol -- or perhaps when the receiver acknowledges receipt of the previous signal, it could send back a list of current dictionaries along with the ACK or NAK.
You can see, though, that the most straight-forward method is just to transmit the dictionary every time, which is what is often done.
When you are calculating data compression ratios, you do need to include the cost of sending the dictionary -- but if you can re-use the dictionary, it is fair to divide the cost of sending the dictionary amongst all of the signals that the dictionary gets reused for.
Related Question