Skip to content

xMohammadAsimx/huffman-coding-matlab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Huffman Coding in MATLAB

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.

Features

  • 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)

How to Run

  1. Open MATLAB
  2. Add the project folder to the MATLAB path
  3. Run the main script:
run('src/m_asim.m')
  1. When prompted, enter a vector of integers between 1 and 100, for example:
x = [5 5 5 2 7 3 3]

Example Output

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

Requirements

  • MATLAB (any modern version)
  • No toolbox dependencies
  • Input must consist of integers in the range 1 to 100

Author

Mohammad Asim

About

Implementation of Huffman coding and decoding in MATLAB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages