Professional Documents
Culture Documents
Source Coding To Develop A Program For Implementation of Source Coding Algorithm
Source Coding To Develop A Program For Implementation of Source Coding Algorithm
OUTCOME: Students will be able to generate codebook for a given phrase compactly.
Q1. How many different number of symbols are there in the phrase?
Ans: 14 symbols
[' ', 'a', 'c', 'd', 'e', 'f', 'i', 'k', 'l', 'o', 'p', 'r', 's', 't']
Q3. How many bits are needed for coding characters in this phrase using fixed length code?
Ans: To encode fourteen unique symbols we would need four bits, for 24 = 16 different codewords.
∴ This gives 4×44 = 176 bits
Q4 Determine theoretical minimum no. of bits required to encode the entire phrase assuming that each character is
independent of other surrounding character.
p e t e r p i p e r
1010 0100 1101 0100 1011 0000 1010 0110 1010 0100 1011 0000
p i c k e d a p e c
1010 0110 0010 0111 0100 0011 0000 0001 0000 1010 0100 0010
k o f p i c k l e d
0111 0000 1011 0101 0000 1010 0110 0010 0111 1000 0100 0011
p e p p e r s
0000 1010 0100 1010 1010 0100 1011 1100
Procedure:
1. Select a tongue- twister phrase yourself or from the list given.
2. Develop a program of Huffman coding or LZ algorithm to generate a codebook for the symbols in the phrase.
(Use MATLAB or any other available software)
for k=0:127
count=0;
for i=1:N
if(t(i)==k)
count=count+1;
end
end
frequency(k+1)=count; %counting frequency of each character
end
fprintf('\n');
fprintf('2. Encoded data for given string = ')
for i=1:length(encode_data)
fprintf('%d', encode_data(i))
end
fprintf('\n');
fprintf('\n');
fprintf('2. Encoded data for given string = ')
for i=1:length(encode_data)
fprintf('%d', encode_data(i))
end
fprintf('\n');
fprintf('\n');
fprintf('3. Fixed length code = %d bits', length(text)*4)
fprintf('\n');
fprintf('\n');
fprintf("4. Huffman's length code = %d bits", length(encode_data))
fprintf('\n');
efficiency = (entropy/avglen)*100;
fprintf('\n');
fprintf("5. Efficiency = %d ", round(efficiency))
fprintf('\n');
Results:
∴ 149 bits are needed for encoding the sequence using codebook derived by Huffman coding
Q2. Compare the no. of bits needed using fixed length coding, Huffman coding and LZ algorithm.
Source coding method No. of Bits
Fixed Length Code 176
Huffman Algorithm 149