Code covered by the BSD License

# MatLab Solutions: "Introduction to Digital Signal Processing: A Computer Laboratory Textbook".

### Ilias Konsoulas (view profile)

29 Oct 2012 (Updated )

These files are the MatLab solutions of exercises contained in the above DSP lab textbook.

uniform_quantizer(x,L,max_level,min_level)
function xq = uniform_quantizer(x,L,max_level,min_level)
% This function implements a uniform quantizer of L levels.
% Input signal x comes as a vector. L is the number of reproducer values.
% When min_level = -max_level and L is odd, this function implements a "midtread" quantizer.
% The midtread quantizer has the advantage of including the zero value in the reproducer values.
% When min_level = -max_level and L is even, this function implements a "midriser" quantizer.
% The number of decision levels is L + 1 and the number of reproducer values is L.

N = length(x);
xq = zeros(1,N);
Delta = (max_level - min_level)/L;

% Calculate Decision Levels and Reproducer Values:
dec_lev = min_level + Delta*(0:L);
rep_val  = min_level + Delta/2 + Delta*(0:L-1);

% Uniform quantizer operation:
for k=1:N
for level=1:L
if x(k) >= dec_lev(level) && x(k) < dec_lev(level+1)
xq(k) = rep_val(level);
elseif x(k) > dec_lev(L)
xq(k) = rep_val(L);
elseif x(k) < dec_lev(1)
xq(k) = rep_val(1);
end
end
end