MATLAB: Does the LLOYDS function in Communications Toolbox 3.1 (R14SP2) give incorrect partitions and codewords

communicationsCommunications Toolboxlloyds

Comparing the Lloyd max algorithm described in the literature (implemented in C code) to lloyds.m shows that lloyds.m does not calculate the partitions correctly. All literature on this topic says that the partitions are the points in the middle between the codebook entries. In the script below, the for-loop should be left out.
Excerpt from the lloyds.m:
% using the codebook as a fixed value, use the nearest neighbor condition
% to form the nearest neightbor cell.
partition = (codebook(2 : ini_codebook) + codebook(1 : ini_codebook-1)) / 2;
for i = 1 : ini_codebook-1
tmp = training_set(find(training_set >= codebook(i)));
tmp = tmp(find(tmp <= odebook(i+1)));
if isempty(tmp)
partition(i) = (codebook(i+1) + codebook(i)) / 2;
else
partition(i) = mean(tmp);
end
end

Best Answer

This bug has been fixed in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
This is a bug in the LLOYDS function within the Communications Toolbox 3.1(R14SP2) in the way it calculates the partitions.
There are no workarounds.