Companding a Signal
Section Overview
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.
Back to Top
Example: µ-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 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.
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.
plot(sig); % Plot original signal.
hold on;
plot(compsig,'r--'); % Plot companded signal.
legend('Original','Companded','Location','NorthWest')The output and figure are below.
ans =
0.5348 0.0397

Back to Top
 | Optimizing DPCM Parameters | | Huffman Coding |  |
How much time do you spend on testing to ensure implementation meets system-level requirements?
Learn more