[0,1,3]
.quantiz
function also returns a vector that tells which interval each input is in. For example, the output below says that the input entries lie within the intervals labeled 0, 6, and 5, respectively. Here, the 0th interval consists of real numbers less than or equal to 3; the 6th interval consists of real numbers greater than 8 but less than or equal to 9; and the 5th interval consists of real numbers greater than 7 but less than or equal to 8.index
to the quantized signal quants
.quants
is exactly what the quantiz
function uses if you instead phrase the example more concisely as below.lloyds
function optimizes the partition and codebook according to the Lloyd algorithm. The code below optimizes the partition and codebook for one period of a sinusoidal signal, starting from a rough initial guess. Then it uses these parameters to quantize the original signal using the initial guess parameters as well as the optimized parameters. The output shows that the mean square distortion after quantizing is much less for the optimized parameters. The quantiz
function automatically computes the mean square distortion and returns it as the third output parameter.dpcmenco
, dpcmdeco
, and dpcmopt
can help you implement a DPCM predictive quantizer with a linear predictor.y(k)
attempts to predict the value of x(k)
, and p
is an m
-tuple of real numbers. Instead of quantizing x
itself, the DPCM encoder quantizes the predictive error, x-y. The integer m
above is called the predictive order. The special case when m = 1
is called delta modulation.k
th value of the signal x
, based on earlier values of x
, is https://everetc667.weebly.com/blog/diablo-3-how-much-more-dmg-with-mark-of-death.y(k) = x (k - 1)
. The code below implements this scheme. It encodes a sawtooth signal, decodes it, and plots both the original and decoded signals. The solid line is the original signal, while the dashed line is the recovered signals. The example also computes the mean square error between the original and decoded signals.lloyds
function to help find quantization parameters that will minimize signal distortion.dpcmopt
function in conjunction with the two functions dpcmenco
and dpcmdeco
, which first appear in the previous section.dpcmopt
should be typical of the kinds of signals you will actually be quantizing with dpcmenco
.predictor
, partition
, and codebook
in a straightforward but haphazard way, this example uses the same codebook (now called initcodebook
) as an initial guess for a new optimized codebook parameter. This example also uses the predictive order, 1, as the desired order of the new optimized predictor. The dpcmopt
function creates these optimized parameters, using the sawtooth signal x
as training data. The example goes on to quantize the training data itself; in theory, the optimized parameters are suitable for quantizing other data that is similar to x
. Notice that the mean square distortion here is much less than the distortion in the previous example.compand
function supports two kinds of companders: µ-law and A-law companders. Its reference page lists both compressor laws.quantiz
function with a partition consisting of length-one intervals. In the second trial, compand
implements a µ-law compressor, quantiz
quantizes the compressed data, and compand
expands the quantized data. The output shows that the distortion is smaller for the second scheme. This is because equal-length intervals are well suited to the logarithm of sig
, but not well suited to sig
. The figure shows how the compander changes sig
.huffmandict
, huffmanenco
, and huffmandeco
functions support Huffman coding and decoding.p
input argument in the huffmandict
function lists the probability with which the source produces each symbol in its alphabet.huffmanenco
and huffmandeco
functions use the dictionary that huffmandict
created.arithenco
and arithdeco
functions support arithmetic coding and decoding.counts
input argument in the arithenco
and arithdeco
functions lists the frequency with which the source produces each symbol in its alphabet. You can determine the frequencies by studying a set of test data from the source. The set of test data can have any size you choose, as long as each symbol in the alphabet has a nonzero frequency.quantiz
function uses partition
and codebook
to map a real vector, samp
, to a new vector, quantized
, whose entries are either -1, 0.5, 2, or 3.x
's that make up the sine curve with the dots that make up the quantized signal. The vertical coordinate of each dot is a value in the vector codebook
.