ms13
Newbie level 1
i have code matlab of this compression but i have a probleme in the party of lloyd max ? i need for ur help plz
i put only the party of max lloyd quantification
i put only the party of max lloyd quantification
Code:
% Lloyd-max algorithm using signal values
% Signal : Signal Vector
% tol : Tolerance
% Initial : Sampling levels
% dist : distortion
% quant : Sampled values
% breakpoints : Breakpoints
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Declarations %
t = 0:.1:2*pi; %
Signal = sin(t); %exemple of signal
Initial=125;
tol=1e-5;
L = length(Initial); % Number of quantization levels
breakpoints = zeros(L-1,1); % Breakpoints for levels
Old_Initial = -Initial ; % Old Initial for iterations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Max - Lloyd Algorithm %
while (norm(Initial-Old_Initial)/norm(Initial)) > tol
% Updating breakpoints %
breakpoints = 0.5*(Initial(1:end-1)+Initial(2:end));
% Updating levels
Old_Initial = Initial;
% Avoid getting zero %
if sum( Signal , breakpoints(1) )>=1
Initial(1) = mean(Signal(Signal , breakpoints(1)));
end
for i = 2: 1 : L-1,
if sum(Signal > breakpoints(i-1) & Signal <breakpoints(i))>=1
Initial(i) = mean(Signal(Signal>breakpoints(i-1) & Signal<breakpoints(i)));
end
end
if sum(Signal>breakpoints(L-1))>=1
Initial(L) = mean(Signal(Signal>breakpoints(L-1)));
end
end
% Quantizing with new levels %
[indx, quant, dist] = quantiz(Signal,breakpoints,Initial);