Optimize quantization parameters using Lloyd algorithm
Optimize Quantization Parameters Using Lloyd Algorithm
Create a sinusoidal signal to use as training data.
t = 0:1000; training_set = sin(t*pi/500);
Set a codeword length of eight. This length corresponds to transmission via a 3-bit channel.
len = 8;
Optimize the quantization parameters. Use the optimized parameters to quantize a different sinusoidal signal. Plot the signal and the quantized signal.
[partition,codebook] = lloyds(training_set,len); signal = cos(t*pi/250); [index,quants] = quantiz(signal,partition,codebook); plot(t,signal,t,quants,'.')
training_set — Training data
Training data, specified as a vector.
The function optimizes for the data in
training_set should be similar to the data that
you plan to quantize.
initcodebook — Initial codebook guess
Initial codebook guess, specified as vector. The length of the vector must be at least 2. Specify this input to provide an initial value for the iterative process described in Algorithms.
len — Initial codebook length
Initial codebook length, specified as a positive integer. Specify this input when you want the function to generate an initial value for the iterative process described in Algorithms.
tol — Relative distortion tolerance
10-7 (default) | scalar
Relative distortion tolerance, specified as a scalar. The Lloyd algorithm terminates once the relative change in distortion between iterations is less than this value.
partition — Distinct endpoints of different ranges
codebook — Quantization value for each partition
Quantization value for each partition, returned as a row vector. This output
prescribes a common value for each partition in a scalar quantization. The length of
this vector is equal to the length of
or the value of
depending on which input you specify. The data type is the same as that of
distor — Final mean square distortion
Final mean square distortion, returned as a positive scalar. The function calculates the mean square distortion at each step of the Lloyd algorithm.
reldistor — Final relative change in mean square distortion
lloyds function uses an iterative process to minimize the
mean square distortion. Optimization processing ends when either:
 Lloyd, S.P., “Least Squares Quantization in PCM,” IEEE Transactions on Information Theory, Vol. IT-28, March, 1982, pp. 129–137.
 Max, J., “Quantizing for Minimum Distortion,” IRE Transactions on Information Theory, Vol. IT-6, March, 1960, pp. 7–12.
Introduced before R2006a