0
0
RosConceptBeginner · 3 min read

Signal to Quantization Noise Ratio (SQNR): Definition and Example

The Signal to Quantization Noise Ratio (SQNR) measures how much stronger a signal is compared to the noise introduced by quantization in digital systems. It is the ratio of signal power to quantization noise power, often expressed in decibels (dB), showing the quality of digital representation.
⚙️

How It Works

Imagine you are trying to copy a smooth curve using only a limited number of steps or levels, like drawing a mountain with only a few shades of gray. This process is called quantization, where continuous signals are rounded to fixed levels. The difference between the original smooth signal and the stepped version is called quantization noise.

The Signal to Quantization Noise Ratio (SQNR) tells us how clear the copied signal is compared to the noise caused by this rounding. A higher SQNR means the signal is much clearer and the noise is less noticeable, just like a photo with many shades looks smoother than one with few shades.

💻

Example

This example calculates the SQNR for a simple sine wave quantized with different bit depths. It shows how increasing bits improves SQNR.

python
import numpy as np

def calculate_sqnr(bits: int) -> float:
    # Generate a sine wave signal
    fs = 1000  # sampling frequency
    t = np.linspace(0, 1, fs, endpoint=False)
    signal = 0.5 * np.sin(2 * np.pi * 50 * t)  # 50 Hz sine wave with amplitude 0.5

    # Quantization parameters
    q_levels = 2 ** bits
    q_step = 1 / (q_levels - 1)

    # Quantize the signal
    quantized_signal = np.round(signal / q_step) * q_step

    # Calculate signal power and noise power
    signal_power = np.mean(signal ** 2)
    noise_power = np.mean((signal - quantized_signal) ** 2)

    # Calculate SQNR in dB
    sqnr = 10 * np.log10(signal_power / noise_power)
    return sqnr

# Calculate SQNR for 2, 4, and 8 bits
sqnr_2bit = calculate_sqnr(2)
sqnr_4bit = calculate_sqnr(4)
sqnr_8bit = calculate_sqnr(8)

print(f"SQNR for 2 bits: {sqnr_2bit:.2f} dB")
print(f"SQNR for 4 bits: {sqnr_4bit:.2f} dB")
print(f"SQNR for 8 bits: {sqnr_8bit:.2f} dB")
Output
SQNR for 2 bits: 12.04 dB SQNR for 4 bits: 25.98 dB SQNR for 8 bits: 50.06 dB
🎯

When to Use

SQNR is important when converting analog signals to digital form, such as in audio recording, image processing, and communication systems. It helps engineers decide how many bits to use for quantization to balance quality and data size.

For example, in music streaming, higher SQNR means clearer sound but larger file sizes. In wireless communication, SQNR helps ensure signals are strong enough compared to noise for reliable data transfer.

Key Points

  • SQNR measures the ratio of signal power to quantization noise power.
  • It is usually expressed in decibels (dB) to show signal quality.
  • Higher SQNR means better digital signal quality with less noise.
  • Increasing quantization bits improves SQNR but increases data size.
  • SQNR guides design choices in digital audio, video, and communication systems.

Key Takeaways

SQNR quantifies how much stronger a signal is compared to quantization noise.
Higher SQNR values indicate clearer digital signals with less distortion.
Increasing the number of quantization bits improves SQNR and signal quality.
SQNR helps balance signal quality and data size in digital systems.
It is widely used in audio, image, and communication signal processing.