This project implements Huffman coding and decoding in MATLAB without using any built-in Huffman functions. The program constructs a Huffman tree, assigns binary codes, encodes an input sequence, and verifies correctness by decoding it back.
- Huffman Encoder (hcode.m)
- Huffman Decoder (hdecode.m)
- Main script to run the program (m_asim.m)
- Manual Huffman tree construction (no huffmanenco())
- Depth-first search code assignment
- Displays:
- Number of unique symbols
- Average bits per symbol
- Compression ratio
- Symbol-to-code mapping
- Round-trip validation (decoded output equals input)
- Open MATLAB
- Add the project folder to the MATLAB path
- Run the main script:
run('src/m_asim.m')
- When prompted, enter a vector of integers between 1 and 100, for example:
x = [5 5 5 2 7 3 3]
Huffman coding complete.
Unique symbols : 4
Input length (N) : 7
Avg bits/symbol : 1.8571
Encoded bits : 13
7-bit baseline : 49
Compression ratio: 0.2653
symbol= 5 code=0
symbol= 2 code=110
symbol= 7 code=111
symbol= 3 code=10
Encoded bitstring: 011011111010
Decoded sequence: [5 5 5 2 7 3 3]
Round-trip check: 1
- MATLAB (any modern version)
- No toolbox dependencies
- Input must consist of integers in the range 1 to 100
Mohammad Asim