Skip to content
Engineering
CompletedDigital Signal Processing · Experiment

Audio Quantization and Reconstruction in Python

A signal-processing experiment: map audio amplitudes to discrete levels, reconstruct the audio from them, and listen to how much of the original survives.

  • Python
  • Digital signal processing
  • Quantization
  • Audio reconstruction

Overview

This experiment implements quantization in Python: audio amplitudes are mapped onto a finite set of discrete levels, the audio is reconstructed from those levels, and the result is played back next to the original for comparison. The reconstructed audio sounded close to the original.

Workflow

Original audio is read as samples, amplitudes are quantized to discrete levels, audio is reconstructed, then played and compared with the original.Original audiorecordingSamplesamplitudesQuantizediscrete levelsReconstructrebuild signalCompareby ear

What quantization is

A sound wave is continuous — at any instant it can take any amplitude. A digital system cannot store that, because each sample must be one of a finite set of values. Quantization is the step that makes that choice: every sample is rounded to the nearest available level.

In the general uniform case, with a signal range split into levels, the step between adjacent levels is:

and each sample is mapped to the nearest one:

The difference between the original sample and its quantized value is the quantization error, and across a whole signal that error is what we hear as quantization noise.

These equations describe the general uniform scheme, not necessarily the exact parameters used in my implementation — the specific resolution and library are listed as not yet documented above, and I would rather leave them blank than state them from memory.

Observations

Played back against the original, the reconstructed audio was clearly recognisable and close in character. That is the result worth noting, and also the limit of what I can claim: the comparison was done by ear, not by measurement.

What I took away

Writing the mapping myself made the trade-off concrete in a way that reading about bit depth did not. Quantization is a deliberate loss of information, and the interesting question is not whether information is lost but how much can be discarded before a listener notices. Answering that properly needs the measurements listed under future work — a quality curve across resolutions, and the error signal examined on its own rather than inferred from how the result sounds.

Objectives

  • Implement quantization directly instead of taking it on trust from a textbook.
  • Hear what discarding amplitude resolution actually does to a recording.
  • Build intuition for the step between a continuous signal and its digital representation.

Known limitations

  • Comparison was perceptual — I listened to both versions rather than measuring the difference.
  • No error metric (SNR or MSE) was calculated, so "close to the original" is a judgement, not a number.
  • Only one quantization setting was tried, so there is no curve showing where quality breaks down.

Proposed future work

  • Repeat at several resolutions and find the point where degradation becomes audible.
  • Plot original and reconstructed waveforms on the same axes.
  • Isolate the quantization error signal and listen to it on its own.
  • Calculate signal-to-noise ratio and mean squared error across resolutions.
  • Compare uniform quantization with a non-uniform scheme.