100% found this document useful (1 vote)
31 views

Swapnil. S. Desai Student ID: 1001418334 Email: Assignment 2: Golomb Coding

The document describes encoding a sequence of 10 values using Golomb coding with parameter m=5. It provides the MATLAB code to perform the encoding and displays the input sequence, Golomb codewords for each value, and encoded prediction sequences. The code takes the previous value in the sequence as the prediction and encodes the differences between actual and predicted values.

Uploaded by

Swapnil Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
31 views

Swapnil. S. Desai Student ID: 1001418334 Email: Assignment 2: Golomb Coding

The document describes encoding a sequence of 10 values using Golomb coding with parameter m=5. It provides the MATLAB code to perform the encoding and displays the input sequence, Golomb codewords for each value, and encoded prediction sequences. The code takes the previous value in the sequence as the prediction and encodes the differences between actual and predicted values.

Uploaded by

Swapnil Desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Swapnil. S.

Desai
Student ID: 1001418334
Email: swapnilsanjay.desai@mavs.uta.edu
Assignment 2: Golomb Coding

Question: Write a program to encode the following sequence of 10 values using the
Golomb code with parameter m=5
32, 33, 35, 38, 39,50,58,60, 67, 80,
For prediction use the previous value in the sequence
y i yi 1 and assume a
prediction of zero for the first element of the sequence. Print out the coded sequence.
Solution: Please refer the below code for solution and results:
MATLAB Code:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
% Name: Swapnil Desai
% Student ID: 1001418334
% Email: swapnilsanjay.desai@mavs.uta.edu
% Golomb code
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%
% Clear command window, workspace and close all figure files
bdclose all;
clear all;
close all;
clc;
% Inputs
m= input('Enter the value of m:');
n= input('Enter the number of values in sequence');
%n= [32, 33, 35, 38, 39,50,58,60, 67, 80];
length= length(n);
%
log(m) to the base 2
Upper= ceil(log2(m));
Lower= floor(log2(m));
range= (2^Upper - m);
% Golomb code for input sequence
for i=1:length
quotient= floor(n(i)/m);
remain= n(i)-quotient*m;
if (remain< Lower)
remain= dec2bin(remain, Lower);
else
remain= dec2bin(remain+3,Upper);
end

if quotient==0
q_code='';
else
q_code='1';
for j=1: quotient-1
ones='1';
zeros=0;
q_code=strcat(ones,q_code);
end
end
q_code=strcat(q_code,'0');
codeword= strcat(q_code,remain);
Input= [num2str(n(i)) '' '----> Codeword ---->'];
disp([Input,codeword]);

end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialising prediction sequence
preseq=zeros(1,length);
for i = 1: length
q(i) = floor(n(i)/m);% for quotient
r(i) = mod(n(i),m); % for remainder
if ( i == 1)
preseq(i) = n(i) - 0;
else
preseq(i) = n(i) - n(i-1);
end
if(q(i)==0)
qseq(1)=0;
qseq(2)=0;
else
for j = 1: q(i)
qseq(j) = 1;
end
qseq(j + 1) = 0;
end
end
for i = 1:length
q(i) = floor(preseq(i) / m);
r(i) = mod(preseq(i), m);
if (q(i) == 0)
qseq(1) = 0;
qseq(2) = 0;
else
for j = 1: q(i)
qseq(j) = 1;
end
qseq(j + 1) = 0;
end
if (mod(m, 2) ~= 0)
if ((r(i) >= 0) && (r(i)<range))
t = Lower;

rcode = de2bi(r(i),t, 'left-msb');


else
t = Upper;
rcode = de2bi ( r(i) + t, t, 'left-msb') ;
end
else
rcode = de2bi(r(i),t, 'left-msb');
end
qcode= mat2str(qseq);
rcode= mat2str(remain);
disp (preseq(i));
disp (strcat(qcode, rcode));
end

Results:
Input values:

Output sequence:
Enter the value of m:5
Enter the number of values in sequence[32 33 35 38 39 50 58 60 67 80]
32----> Codeword ---->1111110101
33----> Codeword ---->1111110110
35----> Codeword ---->1111111000
38----> Codeword ---->11111110110
39----> Codeword ---->11111110111
50----> Codeword ---->1111111111000
58----> Codeword ---->111111111110110
60----> Codeword ---->111111111111000
67----> Codeword ---->11111111111110101
80----> Codeword ---->1111111111111111000
32
[1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
1

[0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
2
[0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
3
[0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
1
[0 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
11
[1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
8
[1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
2
[0 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
7
[1 0 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
13
[1 1 0 1 1 1 0 1 1 1 1 1 1 1 1 1 0]'00'
>>
MATLAB snap:

You might also like