Communications Toolbox | ![]() ![]() |
Companding a Signal
In certain applications, such as speech processing, it is common to use a logarithm computation, called a compressor, before quantizing. The inverse operation of a compressor is called an expander. The combination of a compressor and expander is called a compander.
The compand
function supports two kinds of companders: µ-law and A-law companders. Its reference page lists both compressor laws.
Example: A µ-Law Compander
The code below quantizes an exponential signal in two ways and compares the resulting mean square distortions. First, it uses the 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 finally 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
itself.
Mu = 255; % Parameter for mu-law compander sig = -4:.1:4; sig = exp(sig); % Exponential signal to quantize V = max(sig); % 1. Quantize using equal-length intervals and no compander. [index,quants,distor] = quantiz(sig,0:floor(V),0:ceil(V)); % 2. Use same partition and codebook, but compress % before quantizing and expand afterwards. compsig = compand(sig,Mu,V,'mu/compressor'); [index,quants] = quantiz(compsig,0:floor(V),0:ceil(V)); newsig = compand(quants,Mu,max(quants),'mu/expander'); distor2 = sum((newsig-sig).^2)/length(sig); [distor, distor2] % Display both mean square distortions. ans = 0.5348 0.0397
![]() | Optimizing DPCM Parameters | Arithmetic Coding | ![]() |