You are on page 1of 2

MATLAB ASSIGNMENT 3

DATE OF SUBMISSION: 07-10-16


NAME: SIDDHANT ROHELA

ROLL NUMBER: 14690

n = 2;

%number of bits

g = 1;

%counter for storing the convergent values of MSE

sat = zeros(1, 6);

% array for storing the convergent values of MSE

while n <= 64

%main loop

COURSE: EE320

A = zeros(n, 10000);

%array assigned for each subdivision in -10 to 10

q = zeros(1, n);

%counter to tell where the last non zero entry is in every row of A

L = -10:(20/n):10;

%making the divisions (i.e. their borders)

v = zeros(1, n);

%initializing the values of the array of quantization levels

MSE = zeros(1, 100);

%initializing the values of the array of MSE

plotter = 1:100;

%X-axis for plotting MSE v/s iterations

%////////CODE FOR ARRANGING THE SAMPLES OF THE SIGNAL INTO SUITABLE SUBDIVISIONS////////

for major=1:100

%loop for running iterations; major is the the counter of iterations

q = zeros(1,n);

%resetting the counter 'q' for a new iteration

for i=1:10000

%reading the samples of signal

for p=1:n

%pth subdivision

if ((L(p)<=X(i))&&((X(i)<L(p+1))))

%checking whether the ith sample lies in a given

subdivision
q(p)=q(p)+1;
A(p, q(p))=X(i);

%if yes, then increase the counter 'q' by 1,


%and fill the corresponding element of A with that sample

else
end
end
end

%////////CODE FOR CALCULATING THE QUANTIZATION LEVELS AND THE MEAN SQUARED ERROR////////

MSE(major)=0;

%initializing the MSE for 'major'th iteration

for p=1:n

%pth subdivision

if (q(p)==0)

%if there is no sample of signal within a group then,

v(p)=(L(p)+L(p+1))/2; %assume the level for that group as the average of the L and U limits
else
tempsum=0;
for z=1:q(p)

%intitialize the counter for tempsum

tempsum = tempsum + A(p, z);


end
v(p) = tempsum/q(p);

%optimal pth level is the av. of all samples in the pth sub division

for z=1:q(p)
MSE(major) = MSE(major) + ((v(p)-A(p, z))*(v(p)-A(p, z)));

%building the MSE

end
end
end

MSE(major) = (MSE(major))/10000;

%final value of MSE for that iteration

for y=2:n

%corresponding to the calculated values of quantization levels,

L(y) = (v(y-1)+v(y))/2;

%calculate the new set of subdivisions (i.e. their borders)

end

end

sat(g) = MSE(100);

%filling in the converged value of MSE for every resolution

%////////CODE FOR PLOTTING MSE v/s NUMBER OF ITERATIONS////////

hold on
plot (plotter, MSE)
xlabel('Number of Iterations');
ylabel('Mean Squared Error');
title('MSE v/s Number of Iterations');

end

g = g+1;

%proceeding with the counter 'g'

n = (2*n);

%proceeding with the counter 'n'

You might also like