Function File: qidx = dpcmenco (sig, codebook, partition, predictor)
Function File: [qidx, q] = dpcmenco (sig, codebook, partition, predictor)
Function File: [qidx, q, d] = dpcmenco (…)

Encode using differential pulse code modulation (DPCM).

qidx = dpcmenco (sig, codebook, partition, predictor)

Determine position of the prediction error in a strictly monotonic table (partition). The predictor vector describes a m-th order prediction for the output according to the following equation y(k) = p(1)sig(k-1) + p(2)sig(k-2) + ... + p(m-1)sig(k-m+1) + p(m)sig(k-m) , where the predictor vector is given by predictor = [0, p(1), p(2), p(3),..., p(m-1), p(m)].

[qidx, q] = dpcmenco (sig, codebook, partition, predictor)

Also return the quantized values.

[qidx, q, d] = dpcmenco (...)

Also compute distortion: mean squared distance of original sig from the corresponding quantized values.

See also: dpcmdeco, dpcmopt, quantiz.

Demonstration 1

The following code

 predictor = [0 1];
 nbits = 4;
 delta = 2^(-nbits+1);
 codebook = [-1+delta/2 : delta : 1-delta/2];
 partition = (codebook(1:end-1) + codebook(2:end))/2;
 t = linspace (0, 2*pi, 128);
 x = sawtooth (2*t, 0.25);
 [idx, xq, distor] = dpcmenco (x, codebook, partition, predictor);
 xr = dpcmdeco (idx, codebook, predictor);
 plot (t, x, 'k--','linewidth',1, t, xr, 'b-','linewidth',1);
 xlim ([0 2*pi]);
 xlabel ('t'); ylabel ('x(t)');
 legend ('original', 'dpcm');
 title ( sprintf ('distortion = %.3f', distor) );

Produces the following figure

Figure 1

Package: communications