Bird
Raised Fist0
Signal Processingdata~20 mins

Quantization process in Signal Processing - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Quantization Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Quantization Error

What is the main cause of quantization error in the quantization process?

AThe noise introduced by the analog-to-digital converter hardware
BThe difference between the input signal and the nearest quantization level
CThe rounding of digital values to the nearest integer
DThe loss of signal amplitude due to filtering before quantization
Attempts:
2 left
💡 Hint

Think about what happens when a continuous signal is mapped to discrete levels.

❓ data_output
intermediate
2:00remaining
Quantizing a Signal Array

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?

Signal Processing
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)
A[0.0, 0.33, 0.66, 1.0]
B[0.33, 0.33, 0.66, 0.66]
C[0.0, 0.0, 0.66, 1.0]
D[0.0, 0.33, 0.33, 1.0]
Attempts:
2 left
💡 Hint

Each value is replaced by the closest quantization level.

❓ visualization
advanced
3:00remaining
Visualizing Quantization Levels

Which plot correctly shows the quantization of a sine wave with 3-bit uniform quantization?

Signal Processing
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()
AA smooth sine curve with a stepped line approximating it at 8 levels
BA sine curve with random noise added
CA sine curve with a continuous line shifted upwards
DA flat line at zero with no variation
Attempts:
2 left
💡 Hint

Quantization creates discrete steps approximating the original signal.

🔧 Debug
advanced
2:00remaining
Identifying the Bug in Quantization Code

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)
ATypeError: 'int' object is not callable
B[0, 1, 2]
CAttributeError: 'numpy.ndarray' object has no attribute 'index'
DValueError: min() arg is an empty sequence
Attempts:
2 left
💡 Hint

Check the method used on a numpy array.

🚀 Application
expert
3:00remaining
Calculating Signal-to-Quantization-Noise Ratio (SQNR)

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?

AApproximately 20 dB
BApproximately 46 dB
CApproximately 10 dB
DApproximately 36 dB
Attempts:
2 left
💡 Hint

Use the formula SQNR ≈ 6.02 * b + 1.76 dB, where b is bits per sample. Calculate bits from step size and signal range.

Practice

(1/5)
1. What is the main purpose of the quantization process in signal processing?
easy
A. To amplify the signal strength
B. To increase the frequency of the signal
C. To convert continuous signal values into discrete levels
D. To remove noise from the signal

Solution

  1. Step 1: Understand quantization definition

    Quantization converts continuous amplitude values into a limited set of discrete levels.
  2. Step 2: Compare options with definition

    Only To convert continuous signal values into discrete levels describes this process correctly; others describe different signal operations.
  3. Final Answer:

    To convert continuous signal values into discrete levels -> Option C
  4. Quick Check:

    Quantization = Discrete levels [OK]
Hint: Quantization means mapping continuous to fixed steps [OK]
Common Mistakes:
  • Confusing quantization with filtering
  • Thinking quantization increases signal frequency
  • Assuming quantization amplifies signals
2. Which of the following is the correct syntax to represent a uniform quantizer with 4 levels in Python using NumPy?
easy
A. np.quantize_uniform(min_val, max_val, 4)
B. np.arange(min_val, max_val, 4)
C. np.quantize(min_val, max_val, 4)
D. np.linspace(min_val, max_val, 4)

Solution

  1. Step 1: Recall NumPy function for uniform levels

    NumPy's linspace creates evenly spaced values between min and max.
  2. Step 2: Check options for correct function

    Only np.linspace(min_val, max_val, 4) correctly creates 4 quantization levels.
  3. Final Answer:

    np.linspace(min_val, max_val, 4) -> Option D
  4. Quick Check:

    Uniform levels = linspace [OK]
Hint: Use linspace for uniform quantization levels [OK]
Common Mistakes:
  • Using arange which steps by interval, not count
  • Using non-existent np.quantize functions
  • Confusing parameters order
3. Given the code below, what is the output array after quantization?
import numpy as np
signal = np.array([0.1, 0.4, 0.6, 0.9])
levels = np.linspace(0, 1, 4)
quantized = np.digitize(signal, levels) - 1
print(quantized)
medium
A. [0 1 1 2]
B. [1 1 2 2]
C. [0 0 1 2]
D. [0 1 2 2]

Solution

  1. Step 1: Understand levels and digitize

    Levels are [0.0, 0.3333..., 0.6666..., 1.0]. np.digitize assigns bins: values <0.3333 -> bin 1, <0.6666 -> bin 2, else bin 3.
  2. Step 2: Assign bins to each signal value

    0.1 <0.3333 -> bin 1; 0.4 <0.6666 -> bin 2; 0.6 <0.6666 -> bin 2; 0.9 >=0.6666 -> bin 3. Subtract 1: [0,1,1,2].
  3. Final Answer:

    [0 1 1 2] -> Option A
  4. Quick Check:

    Bins assigned correctly = [0 1 1 2] [OK]
Hint: Remember digitize bins start at 1, subtract 1 for zero-based [OK]
Common Mistakes:
  • Not subtracting 1 from digitize output
  • Misunderstanding bin edges in digitize
  • Confusing levels array values
4. Identify the error in the following quantization code snippet:
import numpy as np
signal = np.array([0.2, 0.5, 0.7])
levels = np.linspace(0, 1, 3)
quantized = np.digitize(signal, levels)
print(quantized)
medium
A. The levels array should have one more element
B. The digitize output should be adjusted by subtracting 1
C. The signal array must be integers
D. np.linspace should use 4 instead of 3

Solution

  1. Step 1: Understand np.digitize output

    np.digitize returns bin indices starting at 1, not zero.
  2. Step 2: Check code for zero-based indexing

    To use quantized indices as zero-based, subtract 1 from digitize output.
  3. Final Answer:

    The digitize output should be adjusted by subtracting 1 -> Option B
  4. Quick Check:

    Subtract 1 from digitize for zero-based bins [OK]
Hint: Subtract 1 from digitize output for zero-based indexing [OK]
Common Mistakes:
  • Ignoring zero-based indexing in digitize
  • Thinking signal must be integer for quantization
  • Assuming levels array length is incorrect
5. You have a signal ranging from -2 to 2 and want to quantize it into 5 uniform levels. Which set of quantization levels correctly represents this?
hard
A. [-2, -1, 0, 1, 2]
B. [-2, -0.8, 0.4, 1.6, 2]
C. [-2, -1.5, -1, -0.5, 0]
D. [-2, -1, 0, 1]

Solution

  1. Step 1: Calculate uniform step size

    Range is 4 (2 - (-2)). For 5 levels, step = 4 / (5 - 1) = 1.
  2. Step 2: Generate levels starting at -2

    Levels: -2, -1, 0, 1, 2 (each step +1).
  3. Final Answer:

    [-2, -1, 0, 1, 2] -> Option A
  4. Quick Check:

    Uniform steps of 1 from -2 to 2 [OK]
Hint: Divide range by (levels-1) for uniform steps [OK]
Common Mistakes:
  • Incorrect step size calculation
  • Choosing wrong number of levels
  • Confusing range endpoints
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard