# compand

Source coding mu-law or A-law compressor or expander

## Description

performs mu-law compression on the input data sequence. The `out`

= compand(`in`

,`param`

,`v`

)`param`

input
specifies the mu-law compression value and must be set to a mu value for mu-law compressor
computation (a mu-law value of 255 is used in practice). `v`

specifies
the peak magnitude of the input data sequence.

performs mu-law or A-law compression or expansion on the input data sequence.
`out`

= compand(`in`

,`param`

,`v`

,`method`

)`param`

specifies the mu-law compander or A-law compander value (a
mu-law value of 255 and an A-law value of 87.6 are used in practice).
`method`

specifies the type of compressor or expander computation for
the function to perform on the input data sequence.

## Examples

## Input Arguments

## Output Arguments

## Algorithms

In certain applications, such as speech processing, using a logarithmic computation
(called a compressor) before quantizing the input data is common. The inverse operation of a
compressor is called an *expander*. The combination of a
compressor and expander is called a *compander*.

For a given signal, *x*, the output of the (*µ*-law)
compressor is

$$y=\frac{\mathrm{log}(1+\mu \left|x\right|)}{\mathrm{log}(1+\mu )}\mathrm{sgn}(x).$$

*µ* is the µ-law parameter of the compander, `log`

is
the natural logarithm, and `sgn`

is the signum function (`sign`

in MATLAB^{®}).

µ-law expansion for input signal *x* is given by the inverse function
*y*^{-1},

$${y}^{-1}=\mathrm{sgn}(y)\left(\frac{1}{\mu}\right)\left({\left(1+\mu \right)}^{\left|y\right|}-1\right)\text{for-1}\le y\le 1$$

For a given signal, *x*, the output of the (*A*-law)
compressor is

$$y=\{\begin{array}{cc}\begin{array}{c}\frac{A\left|x\right|}{1+\mathrm{log}A}\mathrm{sgn}(x)\\ \frac{(1+\mathrm{log}(A\left|x\right|))}{1+\mathrm{log}A}\mathrm{sgn}(x)\end{array}& \begin{array}{c}\text{for}0\le \left|x\right|\le \frac{1}{A}\\ \text{for}\frac{1}{A}\left|x\right|\le 1\end{array}\end{array}$$

*A* is the A-law parameter of the compander, `log`

is
the natural logarithm, and `sgn`

is the signum function (`sign`

in MATLAB).

A-law expansion for input signal *x* is given by the inverse function
*y*^{-1},

$${y}^{-1}=\mathrm{sgn}(y)\{\begin{array}{cc}\begin{array}{c}\frac{\left|y\right|\left(1+\mathrm{log}\left(A\right)\right)}{A}\\ \frac{\mathrm{exp}\left(\left|y\right|\left(1+\mathrm{log}\left(A\right)\right)-1\right)}{A}\end{array}& \begin{array}{c}\text{for}0\le \left|y\right|\frac{1}{1+\mathrm{log}\left(A\right)}\\ \text{for}\frac{1}{1+\mathrm{log}\left(A\right)}\le \left|y\right|1\end{array}\end{array}$$

## References

[1] Sklar, Bernard. *Digital Communications: Fundamentals and Applications*. Englewood Cliffs, NJ: Prentice-Hall, 1988.

## Version History

**Introduced before R2006a**