Implementation of Basic Digital Filter Structures R C
Implementation of Basic Digital Filter Structures R. C. Maher ECEN 4002/5002 DSP Laboratory Spring 2003
Digital Filters • DSP ALUs designed to do fast MACs • Use Harvard architecture: place filter state in X memory, filter coefficients in Y memory • Try to avoid truncation until after all MACs ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 2
FIR Filter Review x[n] Z-1 h 0 Z-1 h 1 Z-1 h 2 + y[n] x[n-1] x[n-2] x[n-3] ECEN 4002 Spring 2003 h 3 Filter Implementation R. C. Maher 3
FIR Setup X Memory Modulo N Buffer Memory Input ECEN 4002 Spring 2003 Y Memory Filter state Coefficients (delay line) Accumulator Filter Implementation Modulo N Buffer Memory Output R. C. Maher 4
FIR Code for 56300 • Filter order ‘n’ • Input and Output in accumulator ‘a’ • r 0: samples, r 4: coefs, m 0 & m 4: n-1 move clr rep macr a, x(r 0) a #n-1 x 0, y 0, a ECEN 4002 Spring 2003 x: (r 0)+, x 0 y: (r 4)+, y 0 x: (r 0)+, x 0 (r 0)- y: (r 4)+, y 0 Filter Implementation R. C. Maher 5
IIR Filters • IIR (infinite impulse response) filters allow zeros and poles; FIR allow zeros only. IIR can be more selective for a given filter order • IIR also called recursive filters: output depends on past inputs and past outputs • IIR designs are not guaranteed to be stable • IIR filters can be particularly sensitive to coefficient quantization ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 6
IIR Issues: Stability and Sensitivity • Finite precision of coefficients can lead to several issues: – In order to be unconditionally stable and causal, all system poles must be inside the unit circle (|z|<1). Coefficient roundoff may inadvertently move a pole outside unit circle – Finite coefficient precision “quantizes” pole locations: may change frequency response from ideal case even if still stable ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 7
Overflow Issues • Gain from input to storage nodes in the filter may exceed unity. This can cause filter state to be saturated (clipped), resulting in distortion • Typically must scale down (attenuate) the input signal, then scale up (amplify) by an equal amount on the output ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 8
Second-Order Sections • High-order filter polynomials involve terms that are products and sums involving many poles and zeros. Small roundoff errors when implementing filter can lead to large response errors • As with analog filters, it is typical to reduce sensitivity by using second-order sections ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 9
Implementing nd 2 Order Sections • 2 nd Order (bi-quad) expression • Numerator implements 2 zeros, denominator implements 2 poles (real or complex conj. ) ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 10
Direct Form Bi-Quad x[n] Z-1 b 0 y[n] + Z-1 y[n-1] x[n-1] Z-1 b 1 -a 1 x[n-2] b 2 ECEN 4002 Spring 2003 Filter Implementation Z-1 y[n-2] -a 2 R. C. Maher 11
IIR Code for 56300 • Direct Form II, with equations: w(n)=x(n)-ai 1 w(n-1)-ai 2 w(n-2) y(n)=w(n)+bi 1 w(n-1)+bi 2 w(n-2) • Since ai 1 and bi 1 may be > 1, need to divide all coefs by 2, then use special scaling mode for 2 on read from accumulator: ori #$08, MR sets “scale up”: 1 -bit left shift on acc read ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 12
IIR for 56300 (cont. ) • N = number of second-order sections • Filter state (w) in X memory: r 0 • Filter coefs (a, b) in Y memory: r 4 – Coefs stored in order: • a 12/2, a 11/2, b 12/2, b 11/2, a 22/2, … b. N 2/2 – State (data) stored in order: • w 1(n-2), w 1(n-1), w 2(n-2), w 2(n-1), … w. N(n-1) • m 0 = 2*N-1, m 4 = 4*N-1 • Initial gain in y 1, input in y 0, output in ‘a’ ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 13
IIR for 56300 (cont. ) mpy y 0, y 1, a x: (r 0)+, x 0 y: (r 4)+, y 0 do #N, end_cell mac -x 0, y 0, a x: (r 0)-, x 1 y: (r 4)+, y 0 macr -x 1, y 0, a x 1, x: (r 0)+ y: (r 4)+, y 0 mac x 0, y 0, a a, x: (r 0)+ mac x 1, y 0, a x: (r 0)+, x 0 y: (r 4)+, y 0 end_cell ECEN 4002 Spring 2003 Filter Implementation rnd a y: (r 4)+, y 0 R. C. Maher 14
Other Filter Structures • • Direct Form I and Direct Form II Cascade and Parallel Realizations Transpose Forms Lattice Forms ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 15
EVM Note: External Memory • To use external memory on EVM, need to program the bus control register and the address attribute register 0 (see 56300 Family Manual) movep #$040821, x: M_AAR 0 movep #$012421, x: M_BCR ; Compare 8 most significant bits ; Look for a match with address ; Y: 0000 0100 xxxx ; No pack, no mux, Y enabled ; P and X disabled ; AAR 0 pin active low ; One ext. wait state • Access to external memory is slower than internal memory: wait state stalls processor ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 16
Conclusion • DSP chips (including the DSP 563 xx) are designed specifically for fast digital filter implementations • Care must be taken to ensure that the practical details are addressed: – Coefficient quantization – Overflow and scaling – Computational complexity ECEN 4002 Spring 2003 Filter Implementation R. C. Maher 17
- Slides: 17