Hello! Welcome to the next lesson in our course.
In our last session, we explored the STFT and the Uncertainty Principle, a fundamental theoretical limit on time-frequency resolution. We learned that a signal cannot be simultaneously "sharp" in both time and frequency. Today, we shift from theoretical limits to one of the most important practical limits in all of digital signal processing: the fact that we have to represent all our numbers—signal samples, filter coefficients, intermediate calculations—using a finite number of bits.
This leads us to the topic of quantization. Our learning outcome for this lesson is to analyze the effects of fixed-point and floating-point quantization on digital filter coefficients and signal representation. We will explore how these two different ways of representing numbers lead to different types of errors and design trade-offs.
1. The Landscape of Quantization Effects
When we implement a digital filter on a processor or a specialized chip like an FPGA, we are forced to move from the infinite precision of mathematics to the finite precision of hardware. This constraint introduces several types of errors.
Quantization Effects in Digital Filters
The technical report 'Quantization Effects in Digital Filters' by Clifford Weinstein and Alan V. Oppenheim is a classic text in this field. Its introduction perfectly frames the problem by dividing quantization effects into four main categories.
Please read the 'ABSTRACT' on the first page. As you read, identify the four main categories of quantization effects mentioned.
As the report outlines, we can classify these effects into four groups:
- Coefficient Quantization: The coefficients of our filter (e.g., the multipliers in a difference equation) are designed with ideal values but must be stored using a finite number of bits. This means the filter we build is slightly different from the one we designed.
- A/D Conversion Error: The initial process of converting an analog signal to a digital one involves quantization. This is an unavoidable source of error at the system's input.
- Arithmetic Roundoff Error: When we perform arithmetic operations like multiplication, the result often requires more bits than we have available. We must round or truncate the result, introducing a small error.
- Overflow: The finite number of bits also limits the maximum value a number can represent. If a calculation exceeds this range, it "overflows," causing a large, non-linear error.
To understand these effects, we must first understand the two primary ways numbers are represented in DSP systems: floating-point and fixed-point.
2. Number Representations: Floating-Point vs. Fixed-Point
You are likely familiar with floating-point numbers from general-purpose programming. They are the standard float and double types in languages like C++ or Python.
A floating-point number uses a certain number of bits for a mantissa (which determines precision) and the remaining bits for an exponent (which determines the scale or range). This allows it to represent both very large and very small numbers.
Actual floating point only uses half of each range
This figure from the Rane note 'Second-Order Digital Filters Done Right' illustrates the floating-point concept. The number line is divided into different scales (determined by the exponent), and the mantissa specifies a value within that scale. Notice that the spacing between representable numbers gets larger as the magnitude of the number increases.
In contrast, many specialized DSP chips and FPGAs use fixed-point arithmetic for reasons of speed, cost, and power efficiency.
Fixed-point math is better than floating point (sometimes)
The video 'Fixed-point math is better than floating point (sometimes)' by Low Byte Productions gives an excellent conceptual and visual introduction to what makes fixed-point different.
Please watch from 02:53 to 07:05. Pay close attention to the visual comparison of the floating-point and fixed-point number lines. Note how fixed-point offers uniform, linear spacing between numbers.
As the video illustrates, a fixed-point number representation has a constant step size between adjacent values. It's essentially an integer that is scaled by a fixed amount. The "binary point" (the equivalent of a decimal point) is in a fixed position.
Let's formalize this. A fixed-point number is defined by its word length (total number of bits) and its fraction length (how many of those bits come after the binary point).
Fixed-Point Made Easy for FPGA Programming
The MATLAB video 'Fixed-Point Made Easy' provides a very clear, practical explanation of how fixed-point numbers are represented and manipulated.
Watch from 02:49 to 05:31. Focus on the concepts of the 'stored integer', 'real-world value', 'word length', and 'fraction length'. The demonstration shows how an underlying integer is scaled by 2^{-\text{fraction length}} to get the actual value.
For example, a signed 16-bit number with a fraction length of 15 (often denoted Q15) uses 1 bit for the sign and 15 bits for the fractional part. The underlying signed 16-bit integer ranges from -32768 to +32767. To get the real-world value, we multiply by . This means the number can represent values from up to .
The key takeaway is that in fixed-point, the programmer must choose the allocation of bits between the integer part (which sets the dynamic range) and the fractional part (which sets the precision).
3. Effect on Signal Representation and Arithmetic
The difference between these representations directly impacts the nature of the quantization error that occurs during A/D conversion and arithmetic operations.
Fixed-Point Quantization Error
In a fixed-point system, the gap between any two representable numbers is constant, equal to the value of the Least Significant Bit (LSB), which is . When we round a real value to the nearest representable number, the error is additive.
The error, , is typically modeled as a random variable. If we use rounding-to-nearest, the error is bounded:
This error is independent of the signal's magnitude. A signal with a value of 0.9 and a signal with a value of 0.1 are both quantized with the same absolute error bound.
A very useful rule of thumb in signal processing connects the number of bits to the dynamic range or Signal-to-Noise Ratio (SNR).
Fixed-Point Made Easy for FPGA Programming
Let's return to the MATLAB video, which derives this important rule of thumb.
Watch from 05:42 to 07:29. The video explains the error characteristics for different rounding modes and introduces the famous '6 dB per bit' rule.
The "6 dB per bit" rule states that each additional bit of quantization improves the maximum possible SNR by approximately 6 decibels. For an -bit quantizer, the SNR is roughly dB. This is a fundamental guideline in DSP system design.
Floating-Point Quantization Error
In a floating-point system, the quantization error is more complex. Because the step size between representable numbers depends on the exponent, the absolute error is larger for larger numbers. The error is best described as multiplicative or relative.
When a real value is represented as a floating-point number fl(x), the result can be modeled as:
where is the relative error. The magnitude of is bounded by the precision of the mantissa (e.g., for a t-bit mantissa, ).
This means the quantization error is proportional to the signal itself. A large signal will have a large absolute error, while a small signal will have a small absolute error.
Test your understanding!
A system needs to represent two signals. Signal A has a magnitude of approximately 1000, and Signal B has a magnitude of approximately 0.1.
- In a fixed-point system, how does the absolute quantization error for Signal A compare to that of Signal B?
- In a floating-point system, how does the absolute quantization error for Signal A compare to that of Signal B?
Show answer
- In a fixed-point system, the absolute quantization error is constant, determined by the LSB value. Therefore, the absolute error for Signal A and Signal B is approximately the same. The relative error for Signal B, however, is much larger.
- In a floating-point system, the absolute quantization error is proportional to the signal's magnitude. Therefore, the absolute error for Signal A will be much larger (about 10,000 times larger) than the error for Signal B. The relative error is approximately the same for both.
4. Effect on Digital Filter Coefficients
The coefficients in a filter's difference equation, like , are calculated to achieve a specific frequency response. These coefficients must also be quantized, which means the filter we actually implement has slightly different coefficients than our design intended. This alters the filter's pole and zero locations, and thus its frequency response.
This effect is most dramatic for filters that require very precise coefficient values, such as low-frequency, high-Q (narrow-bandwidth) filters.
This figure from the Rane note shows a typical consequence of coefficient quantization. The intended response (a sharp, 20 Hz filter) is shown as a thin black line. Due to rounding the coefficients to 24 bits of precision, the actual implemented response (thick blue line) is dramatically different, with the center frequency and shape being incorrect.
Your background in control systems and pole-zero analysis provides a powerful way to visualize this. For a given number of bits in a fixed-point system, there is a finite grid of possible values for the coefficients and . This, in turn, defines a finite grid of possible pole locations in the z-plane.
Grid of allowable pole positions - direct form
This figure from the Weinstein/Oppenheim report shows the grid of realizable pole positions for a second-order filter in the 'direct form' using fixed-point coefficients. Notice how the grid becomes very sparse for poles near z=1 (low frequencies) and for poles with small angles. It may be impossible to place a pole exactly where you want it.
This visualization makes it clear why low-frequency, high-Q filters are so sensitive. In that region of the z-plane (close to on the real axis), the density of realizable poles is low, and a tiny change in a coefficient can cause a large jump in pole location, drastically altering the filter's performance. Floating-point representations create a different, non-uniform grid, but the fundamental problem of finite placement options remains.
5. Summary and Comparison
Let's summarize the trade-offs between fixed-point and floating-point for DSP applications.
| Feature | Fixed-Point | Floating-Point |
|---|---|---|
| Dynamic Range | Limited. Requires careful signal scaling by the programmer to prevent overflow. | Very large. Overflow is rarely a concern. |
| Precision | Uniform absolute precision across the entire range. | Uniform relative precision. Absolute precision decreases as magnitude increases. |
| Error Type | Additive noise, generally independent of signal level. | Multiplicative noise, proportional to signal level. |
| Hardware | Simple, fast, low power. Can be implemented with basic integer arithmetic units. (e.g., in FPGAs, cheap DSPs) | Requires a dedicated Floating-Point Unit (FPU), which is more complex, costly, and power-hungry. |
| Ease of Use | Difficult. Programmer is responsible for scaling, overflow management, and bit allocation. | Easy. The hardware handles scaling automatically via the exponent. |
| Typical Application | Cost-sensitive or power-constrained embedded systems, high-speed hardware implementations (FPGAs). | General-purpose computers, high-end DSPs where development time is more critical than unit cost. |
Ultimately, the choice is an engineering trade-off. Fixed-point offers superior performance and efficiency if you are willing to do the careful numerical analysis required. Floating-point offers convenience and a massive dynamic range at the cost of more complex hardware.
Conclusion
In this lesson, we have seen that moving from theory to practice introduces the critical constraint of finite precision.
Key Takeaways:
- Digital implementation introduces errors from coefficient quantization, arithmetic roundoff, and potential overflow.
- Fixed-point representation uses a fixed binary point, offering uniform absolute precision. Its quantization error is additive and its magnitude is independent of the signal level.
- Floating-point representation uses a mantissa and exponent, offering a vast dynamic range. Its quantization error is multiplicative, meaning the absolute error is proportional to the signal level.
- Quantizing filter coefficients alters the filter's pole-zero locations, leading to errors in the frequency response. This is most severe for low-frequency, high-Q filters.
- The choice between fixed-point and floating-point is a fundamental engineering trade-off between hardware efficiency and ease of development.
Preview of the Next Lesson:
We've characterized the nature of these quantization errors. The next logical step is to analyze their impact. We will learn how to model arithmetic roundoff errors as a source of random noise within the filter structure. This will allow us to derive expressions for the output noise variance and the overall Signal-to-Noise Ratio (SNR) of a digital filter, providing a quantitative way to assess the damage done by finite precision.