# compand

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

collapse all in page

## Syntax

`out = compand(in,param,v)
out = compand(in,Mu,v,`'``mu/compressor``'`)
out = compand(in,Mu,v,`'``mu/expander``'`)
out = compand(in,A,v,`'``A/compressor``'`)
out = compand(in,A,v,`'``A/expander``'`)
`

## Description

`out = compand(in,param,v)` implements a µ-law compressor for the input vector `in`. `Mu` specifies µ, and `v` is the input signal's maximum magnitude. `out` has the same dimensions and maximum magnitude as `in`.

`out = compand(in,Mu,v,`'``mu/compressor``'`)` is the same as the syntax above.

`out = compand(in,Mu,v,`'``mu/expander``'`)` implements a µ-law expander for the input vector `in`. `Mu` specifies µ and `v` is the input signal's maximum magnitude. `out` has the same dimensions and maximum magnitude as `in`.

`out = compand(in,A,v,`'``A/compressor``'`)` implements an A-law compressor for the input vector `in`. The scalar `A` is the A-law parameter, and `v` is the input signal's maximum magnitude. `out` is a vector of the same length and maximum magnitude as `in`.

`out = compand(in,A,v,`'``A/expander``'`)` implements an A-law expander for the input vector `in`. The scalar `A` is the A-law parameter, and `v` is the input signal's maximum magnitude. `out` is a vector of the same length and maximum magnitude as `in`.

Note: The prevailing parameters used in practice are µ= 255 and A = 87.6.

## Examples

collapse all

### μ-Law Compression and Expansion

Open This Example

Generate a data sequence.

    data = 2:2:12;

Compress the input sequence using an μ-law compander. The typical value for μ is 255. The data ranges between 8.1 and 12 instead of between 2 and 12.

    compressed = compand(data,255,max(data),'mu/compressor')

    compressed =

        8.1644    9.6394   10.5084   11.1268   11.6071   12.0000

Expand the compressed signal. The expanded sequence is nearly identical to the original.

    expanded = compand(compressed,255,max(data),'mu/expander')

    expanded =

        2.0000    4.0000    6.0000    8.0000   10.0000   12.0000

### A-Law Compression and Expansion

Open This Example

Generate a data sequence.

    data = 1:5;

Compress the input sequence using an A-law compander. The typical value for A is 87.5. The data ranges between 3.5 and 5 instead of between 1 and 5.

    compressed = compand(data,87.6,max(data),'a/compressor')

    compressed =

        3.5296    4.1629    4.5333    4.7961    5.0000

Expand the compressed signal. The expanded sequence is nearly identical to the original.

    expanded = compand(compressed,87.6,max(data),'a/expander')

    expanded =

        1.0000    2.0000    3.0000    4.0000    5.0000

## More About

collapse all

### Algorithms

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

y=V log(1+μx/V)log(1+μ)sgn(x)

where V is the maximum value of the signal x, µ is the µ-law parameter of the compander, log is the natural logarithm, and sgn is the signum function (`sign` in MATLAB).

The output of the A-law compressor is

y=Ax1+log A sgn(x)V(1+log(Ax/V))1+log A sgn(x)for 0 for V A≤x≤V A<x≤V

where A is the A-law parameter of the compander and the other elements are as in the µ-law case.

- Compand a Signal

## References

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

## See Also

`dpcmdeco` | `dpcmenco` | `quantiz`

#### Introduced before R2006a

#### MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Was this topic helpful?
United States
http://www.mathworks.com/includes_content/domainSelect/location.html?action=changeCountry&s_tid=gn_loc_drop
united_states_select

# Select Your Country

Choose your country to get translated content where available and see local events and offers. Based on your location, we recommend that you select: United States.

Select United States

You can also select a location from the following list:

### Americas

- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
  - Deutsch
  - Français
- United Kingdom (English)

### Asia Pacific

- Australia (English)
- India (English)
- New Zealand (English)
- 中国 (简体中文)
- 日本 (日本語)
- 한국 (한국어)

See all countries

- Trial Software
- Product Updates

##### Communications System Toolbox Documentation

- Examples
- Functions and Other Reference
- Release Notes
- PDF Documentation

##### Other Documentation

- MATLAB
- Signal Processing Toolbox
- DSP System Toolbox
- Simulink
- Symbolic Math Toolbox
- All Products

##### Support

- MATLAB Answers
- Installation Help
- Bug Reports
- Product Requirements
- Software Downloads

#### Try MATLAB, Simulink, and Other Products

Get trial now