AI Glossary / Natural language and speech / Intermediate

Mu-law

Definition

Mu-law, written μ-law, is a nonlinear companding method used to represent audio amplitudes with relatively fine resolution near zero and coarser resolution at larger magnitudes. It is associated with telephony and also appears in discrete audio representations used by machine-learning systems.

What it means

Uniformly spaced amplitude levels devote the same absolute step size to quiet and loud parts of a waveform. Mu-law changes that allocation: small amplitudes are expanded on a compressed scale before quantization, giving them more representational detail relative to their size.

“Companding” combines compression and expansion. The encoder applies a nonlinear amplitude transformation; the decoder applies the corresponding inverse transformation after reading the stored levels. Here compression concerns amplitude range and coding precision, not automatically a particular file-size reduction.

The continuous mathematical curve and a complete codec are distinct. G.711 specifies a telephony coding system, including concrete coding details. A library that applies the mu-law formula and emits integer categories should not automatically be treated as producing interchangeable G.711 bytes.

How it works

For a normalized sample x between -1 and 1, a common continuous transformation is y = sign(x) × ln(1 + μ|x|) / ln(1 + μ), with μ greater than zero. It preserves sign, maps the endpoints to -1 and 1, and allocates more scale near small amplitudes.

A discrete implementation then maps y to a finite set of levels. The reviewed torchaudio function sets μ to one less than the number of quantization channels and outputs integers from zero to that number minus one. Decoding reverses the level mapping and applies the inverse curve.

Quantization makes the full process lossy: multiple nearby input amplitudes can receive the same code. The continuous curve alone is invertible in ideal arithmetic, but the rounded integer representation cannot retain every original value.

Three practical examples

  • Audio data preparation: convert a normalized waveform into discrete amplitude categories for a model designed to predict such categories.
  • Speech tooling: decode mu-law audio with a codec implementation that matches its actual storage format before sending it to a recognizer.
  • Quality evaluation: compare reconstruction errors for quiet and louder waveform segments rather than assuming all amplitudes receive identical resolution.

Think of it this way

Think of using closely spaced marks near the bottom of a measuring scale and wider marks farther up. Small readings receive finer distinctions. The analogy is limited because mu-law follows a specified nonlinear equation and encoding convention; it does not adaptively decide which spoken words or background sounds matter.

Worked example

Take x = 0.01 and μ = 255. The continuous transformation gives ln(3.55) / ln(256), approximately 0.228477. This is a transformed coordinate, not a claim that the physical signal became more than twenty times louder.

Using torchaudio's illustrated 256-level mapping, q = integer((y + 1) × 255 / 2 + 0.5), the resulting code is 157. Mapping that code back gives a reconstructed normalized amplitude of approximately 0.0102253. The difference from 0.01 is about 0.0002253, demonstrating quantization loss.

For comparison, x = 0.5 maps to approximately 0.875703 before quantization. Both calculations use the same nonlinear curve. These are checked arithmetic examples for the stated library-style convention; they are not a byte-level G.711 conformance test and should not be used as one.

Illustrative case study

Fictional case: Clear Call imports archived audio into a speech-analysis workflow. A developer mistakes encoded eight-bit values for ordinary linear waveform samples. Playback sounds distorted, and the transcript becomes unreliable.

The team checks the file's encoding metadata, uses the matching decoder, and compares a known sample with expected playback before processing the archive. It also records the sample rate separately. The scenario illustrates an interoperability check, not a claim that mu-law itself improves recognition accuracy.

Common misconceptions and mistakes

Mu-law is not a mel-frequency scale. It transforms sample amplitudes, whereas the mel scale concerns frequency representation. It is not noise removal, encryption, or a method for recovering information that the recording never captured.

Do not confuse the number of quantization channels with stereo audio channels. In the cited function, 256 channels means 256 possible amplitude categories. Nor does an eight-bit value imply that it can be interpreted as signed linear PCM. The bit pattern's meaning depends on the coding specification.

Business use

When integrating audio systems, record codec, sample rate, channel count, bit representation, and normalization assumptions. Use a decoder appropriate to the actual format, and avoid silently applying a second companding stage to already encoded data.

Test a short known waveform through the complete pipeline. Check endpoints, quiet segments, and reconstruction, along with audible results where appropriate. If a model expects mu-law categories, verify its code ordering and quantization convention. Similar terminology does not guarantee that training data, inference input, and output playback use compatible representations.

People also ask

Is mu-law lossless?

The ideal continuous curve is invertible, but finite-level quantization generally loses amplitude detail.

Does it change sample rate?

The amplitude transformation itself does not. Resampling is a separate operation.

Are all mu-law encoders byte compatible?

No. A mathematical companding function and a standardized codec can differ in discrete coding conventions. Follow the specific interface or standard.

Check your understanding

A library accepts normalized floating-point samples and returns integers from 0 to 255. Can those integers automatically be sent as a standards-compliant telephony stream?

Answer: No. The transport, codec bit mapping, sample rate, and other format requirements must match. The range of integer values alone is insufficient.

Related terms

  • Companding
  • Audio codec
  • quantization
  • pulse-code modulation
  • G.711
  • waveform
  • sample rate
  • mel scale

Learn next

plot the continuous transformation and its inverse, then add a specified quantizer and inspect reconstruction error. Compare that experiment with the documented codec interface used by your audio files. Keep mathematical behavior and byte-format compatibility as separate checks.

More in Natural language and speech

  • Morphological pattern - A morphological pattern is a recurring way in which word forms are built or related.
  • Morphological typology - Morphological typology compares languages and constructions according to how words are structured and how grammatical information is expressed.
  • Morphology - Morphology is the study of word structure and the systematic relationships between word forms.
  • MUC F-measure - MUC F-measure is a coreference evaluation score that combines MUC precision and recall.
  • Multi-document summarization - Multi-document summarization is the task of producing a concise account from information in several source documents.
  • Multilingual notation - Multilingual notation, in the lexical-resource sense used here, is a way of representing correspondences among lexical information in different languages.

Sources

Sources: Torchaudio, mu_law_encoding documentation: https://docs.pytorch.org/audio/main/generated/torchaudio.functional.mu_law_encoding.html ; implementation, encoding and decoding functions: https://docs.pytorch.org/audio/main/_modules/torchaudio/functional/functional.html . ITU-T, G.711 official recommendation listing: https://www.itu.int/rec/T-REC-G.711/en . The listing establishes the standard reference; no full G.711 conformance audit is claimed. Numerical examples were calculated for the stated convention.

Previous: MTD(f) Next: MUC F-measure

  • Home
  • Daily AI Updates
  • Blog
  • AIFBL Academy
  • AI Glossary
  • Products and Tools
  • Store
  • Free CFO AI Prompt Pack
  • About Shihan Sheriff
  • Privacy Policy
  • Terms of Use
  • Refund Policy
  • Cookie Policy
  • Earnings Disclaimer