Main Content

dpcmenco

Encode using differential pulse code modulation

Description

indx = dpcmenco(sig,codebook,partition,predictor) returns an index indx by encoding the signal sig using differential pulse code modulation (DPCM).

example

[indx,quants] = dpcmenco(sig,codebook,partition,predictor) returns the quantization of the signal, quants based on the quantization parameters.

Examples

collapse all

Use DPCM encoding and decoding to quantize the difference between the value of the current signal sample and the value of the previous sample. For this example, you use a predictor y(k)=x(k-1). Then, encode a sawtooth signal, decode it, plot both the original and the decoded signals, and compute the mean square error between the original and decoded signals.

partition = [-1:.1:.9];
codebook = [-1:.1:1];
predictor = [0 1];      % y(k)=x(k-1)
t = [0:pi/50:2*pi];     % Time samples
x = sawtooth(3*t);      % Original signal

Quantize x using DPCM encoding.

encodedx = dpcmenco(x,codebook,partition,predictor);

Recover x from the modulated signal by using DPCM decoding. Plot the original signal and the decoded signal. The solid line is the original signal, while the dashed line is the recovered signal.

decodedx = dpcmdeco(encodedx,codebook,predictor);
plot(t,x,t,decodedx,'-')

Figure contains an axes object. The axes object contains 2 objects of type line.

Compute the mean square error between the original signal and the decoded signal.

distor = sum((x-decodedx).^2)/length(x)
distor = 
0.0327

To optimize a DPCM-encoded and -decoded sawtooth signal, use the dpcmopt function with the dpcmenco and dpcmdeco functions. Testing and selecting parameters for large signal sets with a fine quantization scheme can be tedious. One way to produce partition, codebook, and predictor parameters easily is to optimize them according to a set of training data. The training data should be typical of the kinds of signals to be quantized with dpcmenco.

This example 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. The mean square distortion for optimized DPCM is much less than the distortion with nonoptimized DPCM parameters.

Define variables for a sawtooth signal and initial DPCM parameters.

t = [0:pi/50:2*pi];
x = sawtooth(3*t);
partition = [-1:.1:.9];
codebook = [-1:.1:1];
predictor = [0 1];      % y(k)=x(k-1)

Optimize the partition, codebook, and predictor vectors by using the dpcmopt function and the initial codebook and order 1. Then generate DPCM encoded signals by using the initial and the optimized partition and codebook vectors.

[predictorOpt,codebookOpt,partitionOpt] = dpcmopt(x,1,codebook);
encodedx = dpcmenco(x,codebook,partition,predictor);
encodedxOpt = dpcmenco(x,codebookOpt,partitionOpt,predictorOpt);

Recover x from the modulated signal by using DPCM decoding. Compute the mean square error between the original signal and the decoded and optimized decoded signals.

decodedx = dpcmdeco(encodedx,codebook,predictor);
decodedxOpt = dpcmdeco(encodedxOpt,codebookOpt,predictorOpt);
distor = sum((x-decodedx).^2)/length(x);
distorOpt = sum((x-decodedxOpt).^2)/length(x);

Compare mean square distortions for quantization with the initial and optimized input arguments.

[distor, distorOpt]
ans = 1×2

    0.0327    0.0009

Input Arguments

collapse all

Signal to encode, specified as a vector.

Data Types: double

Partition interval endpoints, specified as a vector.

Data Types: double

Value for each partition in the quantization, specified as a vector. The length of the codebook input exceeds the length of partition input by 1.

Data Types: double

Predictive transfer function, specified as a vector. If the transfer function has predictive order M, then the predictor has length M+1 and an initial entry of 0. In general, an Mth order transfer function numerator has the form of [0, n1, n2, ... nM]. If predictor is an order-one transfer function, the modulation is a delta modulation.

Data Types: double

Note

For more about the format of the predictor input, see Differential Pulse Code Modulation. For a description of the formats of the partition input and codebook input, see Quantization.

Output Arguments

collapse all

Quantization index of the encoded signal, returned as a vector.

Data Types: double

Quantization of the signal, based on quantization parameters, specified as a vector of the same size as the signal vector.

Data Types: double

References

[1] Kondoz, A. M. Digital Speech. Chichester, England: John Wiley & Sons, 1994.

Version History

Introduced before R2006a