% Project 1
% Andy Doran
%
% This programs quantizes and plots "in" to "X" bits
% assuming uniform distribution

function out = dquant(in, Lmax, Lmin, bits)

% Get L quantization levels
L = 2^bits;

% size(tk) = L+1, with points evenly spaced between endpoints
tk = linspace(Lmin,Lmax,L+1);

% size(rk) = L, where each rk is the average of tk & t(k+1)
delta = (tk(2) - tk(1))/2;
rk = linspace(Lmin+delta, Lmax-delta, L);

[r,c]=size(in);

tmp=reshape(in,1,r*c);
for i = 1: r*c,
  out(i) = rk( tmp(i)+1 );
end

out = reshape(out,r,c);
