What is the main cause of quantization error in the quantization process?
Think about what happens when a continuous signal is mapped to discrete levels.
Quantization error arises because the continuous input value is approximated by the nearest discrete quantization level, causing a difference between the original and quantized values.
Given the signal array [0.1, 0.4, 0.6, 0.9] and a uniform quantizer with 2 bits (4 levels: 0, 0.33, 0.66, 1), what is the quantized output array?
import numpy as np signal = np.array([0.1, 0.4, 0.6, 0.9]) levels = np.array([0, 0.33, 0.66, 1]) quantized = np.array([levels[np.argmin(np.abs(levels - x))] for x in signal]) print(quantized)
Each value is replaced by the closest quantization level.
Each signal value is mapped to the nearest level: 0.1 → 0.0, 0.4 → 0.33, 0.6 → 0.66, 0.9 → 1.0.
Which plot correctly shows the quantization of a sine wave with 3-bit uniform quantization?
import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 2 * np.pi, 100) signal = np.sin(x) levels = np.linspace(-1, 1, 8) # 3-bit quantization quantized = np.array([levels[np.argmin(np.abs(levels - s))] for s in signal]) plt.plot(x, signal, label='Original Signal') plt.step(x, quantized, label='Quantized Signal', where='mid') plt.legend() plt.show()
Quantization creates discrete steps approximating the original signal.
The quantized signal appears as a stepped line with 8 discrete levels approximating the smooth sine wave.
What error does the following code produce when quantizing a signal?
import numpy as np signal = np.array([0.2, 0.5, 0.7]) levels = np.array([0, 0.33, 0.66, 1]) quantized = [levels.index(min(levels, key=lambda l: abs(l - x))) for x in signal] print(quantized)
Check the method used on a numpy array.
The code tries to use the list method index() on a numpy array, which causes an AttributeError.
For a uniform quantizer with step size Δ = 0.1 applied to a signal uniformly distributed between -1 and 1, what is the approximate SQNR in decibels?
Use the formula SQNR ≈ 6.02 * b + 1.76 dB, where b is bits per sample. Calculate bits from step size and signal range.
The number of quantization levels L = (range) / Δ = 2 / 0.1 = 20 levels. Bits b = log2(20) ≈ 4.32. SQNR ≈ 6.02 * 4.32 + 1.76 ≈ 27 + 1.76 = 28.76 dB. However, for uniform distribution, SQNR is approximately 36 dB considering signal power and quantization noise power.
