Help with Huffman Coding for MPEG Encoder

1 view (last 30 days)
Hello guys, I have a problem with my so-called Huffman encoding MATLAB code. Instead of using the built-in functions (ie huffmandict, huffmanenco, huffmandeco), I am using for-loops to do the encoding and decoding. This is because it will be easier to translate into C later on. I have a predefined table of what each symbol should be. After compiling the code below, the output was all zeros, which made no sense to me. What I'm trying to do is convert 0 into 0, 1 into 10, so on and so forth so that it becomes a bitstream. Am I making any sense? What am I doing wrong here? Any help is greatly appreciated.
Symbol
0 ---> 0
1 ---> 10
2 ---> 110
3 ---> 1110
4 ----> 1111
Here's what I've got so far in terms of loops:-
[M,N] = size(a);
% Where a is the image matrix after quantization
for i = 1:M
for j = 1:N
if(a(i,j)==0)
k(1,j) = 0;
else if (a(i,j)==1)
k(1,j:j+1) = 10;
else if (a(i,j) ==2)
k(1,j:j+2) = 110;
else if (a(i,j) ==3)
k(1,j:j+3) = 1110;
else
k(1,j:j+3) = 1111;
end
end
end
end
end
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!