System elements and implementation
Adder, gain and memory: with those three pieces any system can be built. How they are arranged is not a matter of indifference, and that is why no high-order digital filter is implemented in direct form.
01Three pieces and nothing else
Any LTI system, however complicated, is built from three elements. There is no fourth:
| Element | What it does | In continuous time | In discrete time |
|---|---|---|---|
| Adder | \( y = x_1 + x_2 \) | A node, or a summing amplifier | An addition |
| Gain | \( y = a\,x \) | A resistive divider, a stage | A multiplication |
| Memory | Stores the past | An integrator: capacitor or inductor | A delay \( z^{-1} \): a register |
The memory row is the important one. Without it, a system can only respond to the present value —it would be static— and there would be neither filters nor dynamics. In an analog circuit that memory is the energy stored in a capacitor; in a processor, a memory location that holds the previous sample.
02From the diagram to the filter
The same transfer function can be built in several ways, and they are not equivalent in the number of components or in numerical behavior. The lab draws the structure, counts the pieces and shows what filter results.
Choose the structure and look at the diagram: the squares are delays, the triangles gains and the circles adders. Below, the resulting impulse response and magnitude.
03The structures, and why there is more than one
| Structure | Delays | Advantage | Problem |
|---|---|---|---|
| Direct form I | \( M + N \) | Comes straight from the equation | Uses twice the memory |
| Direct form II | \( \max(M,N) \) | The minimum number of delays | Sensitive to quantization if the order is high |
| Cascade | Same as II | Robust: each section has its own poles | You have to factor and order the sections |
| Parallel | Same | Errors do not accumulate between branches | Requires partial fractions |
Direct form II is also called canonical because it uses the smallest possible number of memory elements, and it is the one implemented by almost all libraries. Its problem appears at high orders.
The coefficients of a real filter are stored with a finite number of bits. In direct form, the denominator coefficients are those of the complete polynomial, and rounding them moves all the roots at once: in an eighth-order filter, a tiny error in one coefficient can push a pole outside the unit circle and make it unstable.
In cascade, on the other hand, the filter is built from second-order sections, each with its two poles. Rounding the coefficients of one section moves only those two, and only slightly. That is why no high-order digital filter is implemented in direct form: it is factored into second-order sections, which in the jargon are called biquads.
04FIR and IIR
| FIR | IIR | |
|---|---|---|
| Feedback | None: \( a_k = 0 \) | Yes |
| Impulse response | Finite: it dies out on its own | Infinite |
| Stability | Always stable | The poles must be checked |
| Linear phase | Obtained with symmetric coefficients | No, unless an all-pass is added |
| Order for the same selectivity | High: tens or hundreds | Low: just a few |
| Analog equivalent | None | Resembles an RLC |
The trade-off is straightforward: an FIR is safer and can have linear phase, but it needs many more coefficients; an IIR achieves the same with a low order, in exchange for keeping an eye on stability and for not being able to have linear phase. For real-time audio, where latency matters, the IIR usually wins; for block processing where phase matters, the FIR.
A 200-coefficient FIR needs to store 200 past samples and perform 200 multiplications for each output sample. A fourth-order IIR that does something similar needs 4. On a small microcontroller that difference decides whether the filter fits or not, and it is the reason why the filters in embedded instrumentation are almost always cascaded biquads.
05In the lab
For \( H(z) = \dfrac{1 + 2z^{-1} + z^{-2}}{1 - 0.5z^{-1} + 0.3z^{-2}} \), draw the direct forms I and II, and count the delays, multipliers and adders of each.
Program a second-order section in direct form II on a microcontroller, measure how many cycles it takes per sample and calculate the maximum sampling frequency it supports.
Design an 8th-order IIR low-pass, round its coefficients to 8 bits in direct form and calculate where the poles end up. Repeat by factoring into four biquads and compare how much they moved in each case.
06Common mistakes
- Implementing a high order in direct form. Coefficient quantization can make it unstable.
- Forgetting the sign of the feedback. The \( a_k \) enter subtracted in the difference equation.
- Confusing order with number of coefficients. An FIR of order \( M \) has \( M+1 \) coefficients.
- Expecting linear phase from an IIR. It does not have it, unless an all-pass is added to correct it.
- Not initializing the delay registers. At startup, a filter with garbage inside delivers a transient that can last a long time.
07Self-assessment
What are the three elements of an LTI system?
Adder, gain and memory: an integrator in continuous time, a delay in discrete time.
Why is direct form II called canonical?
Because it uses the smallest possible number of memory elements: \( \max(M,N) \).
Why are high-order filters implemented in cascade?
Because rounding the coefficients in direct form moves all the roots at once; in cascade each section has its own poles and the error stays bounded.
What is a biquad?
A second-order section. High-order filters are built by chaining several of them.
Why is an FIR always stable?
Because it has no feedback: its impulse response has a finite number of terms.
When is an IIR the right choice?
When selectivity is needed with few resources and phase is not critical. It achieves with order 4 what an FIR would need tens of coefficients for.
08Further reading
- John G. Proakis and Dimitris G. Manolakis. Digital Signal Processing: Principles, Algorithms, and Applications. 4th ed. (Spanish edition, “Tratamiento digital de señales”), Prentice Hall, 2006. All the structures with their diagrams, and the analysis of finite-precision arithmetic effects.
- Alan V. Oppenheim and Ronald W. Schafer. Discrete-Time Signal Processing. 3rd ed. (Spanish edition, “Tratamiento de señales en tiempo discreto”), Prentice Hall, 2010. The chapter on structures and the one on coefficient quantization effects.
- Richard G. Lyons. Understanding Digital Signal Processing. 3rd ed., Prentice Hall, 2010. The clearest one for real implementation: biquads, scaling and rounding errors.