notesonly.in

One notebook for every subject — open it anywhere.

Log in

Sampling and Quantization: Complete Beginner's Guide

Sampling and quantization are the two steps that turn the smooth, continuous real world into the blocky numbers computers can store. Sampling measures a signal's height at regular instants (like photographing a runner at fixed intervals); quantization rounds each measurement to the nearest of a fixed set of levels (like rounding heights to whole centimetres).

These two operations are the doorway into all of digital audio, video, and communications: your voice on a phone call, a song on Spotify, and a photo on your phone all began as samples forced through a quantizer. Get the rules wrong and you get aliasing ghosts or grainy quantization noise; get them right and the digital copy is indistinguishable from the original.

Key Concepts

  • Sampling rate (fs): samples per second, in Hz; audio CDs use 44.1 kHz, phone calls 8 kHz.
  • Nyquist rate: the minimum sampling rate, 2× the signal's highest frequency — sample slower and high frequencies fold back as aliasing.
  • Quantization levels (L): the number of allowed output values, L = 2ⁿ for an n-bit quantizer.
  • Step size (Δ): the gap between neighbouring levels, Δ = full-scale range / 2ⁿ.
  • Quantization error: the rounding difference, always between −Δ/2 and +Δ/2 — it sounds like background hiss.
  • SQNR: signal-to-quantization-noise ratio, roughly 6 dB per bit — each extra bit quadruples the precision.

Formulas

  • Nyquist criterion: fs ≥ 2·fmax — the signal's top frequency fmax must be below half the sampling rate.
  • Levels and step: L = 2ⁿ; Δ = VFS/2ⁿ, with VFS the full-scale voltage range.
  • Max quantization error: |e| ≤ Δ/2.
  • SQNR: ≈ 6.02n + 1.25 dB for a full-scale sine wave — so 16-bit audio gives ≈ 98 dB.
  • Assumptions: uniform quantizer, signal spans the full range, and the sampling theorem assumes a strictly band-limited signal.

Worked Example

Digitise a sensor signal spanning 0–5 V with a 4-bit quantizer. Step 1: levels L = 2⁴ = 16, step Δ = 5/16 = 0.3125 V. Step 2: a true reading of 2.00 V rounds to the nearest level, 1.875 V or 2.1875 V — 1.875 V wins, error = 0.125 V (within Δ/2 = 0.156 V, as promised). Step 3: SQNR ≈ 6.02×4 + 1.25 ≈ 25.3 dB — fine for a thermometer, hopeless for music. Step 4: sampling — if the sensor's fastest wiggle is 100 Hz, Nyquist demands fs ≥ 200 Hz; sampling at 150 Hz would fold a 100 Hz tone down to a phantom 50 Hz (aliasing), so the designer picks 500 Hz plus a 200 Hz anti-aliasing filter. Numbers in, numbers out — but only the Nyquist rule keeps them honest.

Common Misconceptions

  • "More bits always sound better." Not beyond the point where quantization noise drops below the room's background noise — 24-bit audio's ≈146 dB SQNR exceeds what any speaker or ear can use.
  • "Sampling loses the in-between moments forever." Wrong (for band-limited signals): the sampling theorem proves the original wave can be rebuilt perfectly from its samples if fs ≥ 2·fmax.
  • "Aliasing can be fixed in software later." Wrong: once a high frequency has folded onto a low one, the two are inseparable — prevention with an analog filter is the only cure.

Real-World Applications

  • CDs (44.1 kHz, 16-bit) and studio recording (96 kHz, 24-bit) are pure sampling-plus-quantization.
  • Phone networks sample voice at 8 kHz with 8-bit quantization (64 kbps per call).
  • Digital cameras sample light spatially (pixels) and quantize brightness (8–14 bits per channel).
  • Every ADC chip in oscilloscopes, medical sensors, and IoT devices lives by these two rules.

Sampling freezes time into snapshots — take at least two per wiggle or impostor frequencies appear. Quantization freezes amplitude into steps — each bit buys about 6 dB of cleanliness. Together they are the toll booth every analog signal pays to enter the digital world.