Function File: [table, codes] = lloyds (sig, init_codes)
Function File: [table, codes] = lloyds (sig, len)
Function File: [table, codes] = lloyds (sig, …, tol)
Function File: [table, codes] = lloyds (sig, …, tol, type)
Function File: [table, codes, dist] = lloyds (…)
Function File: [table, codes, dist, reldist] = lloyds (…)

Optimize the quantization table and codes to reduce distortion. This is based on the article by Lloyd

S. Lloyd Least squared quantization in PCM, IEEE Trans Inform Theory, Mar 1982, no 2, p129-137

which describes an iterative technique to reduce the quantization error by making the intervals of the table such that each interval has the same area under the PDF of the training signal sig. The initial codes to try can either be given in the vector init_codes or as scalar len. In the case of a scalar the initial codes will be an equi-spaced vector of length len between the minimum and maximum value of the training signal.

The stopping criteria of the iterative algorithm is given by

abs(dist(n) - dist(n-1)) < max(tol, abs(eps*max(sig))

By default tol is 1.e-7. The final input argument determines how the updated table is created. By default the centroid of the values of the training signal that fall within the interval described by codes are used to update table. If type is any other string than "centroid", this behavior is overridden and table is updated as follows.

table = (code(2:length(code)) + code(1:length(code-1))) / 2

The optimized values are returned as table and code. In addition the distortion of the optimized codes representing the training signal is returned as dist. The relative distortion in the final iteration is also returned as reldist.

See also: quantiz.

Package: communications