Embedded DSP: Introduction To Digital Filters
Embedded DSP: Introduction To Digital Filters
Digital filters are a important part of DSP. In fact their extraordinary performance is one of the keys that DSP has become so popular.
Audio processing Speech processing (detection, compression, reconstruction) Modems Motor control algorithms Video and image processing
Historically, electronic designers implemented filters with analog components, as resistors, capacitors and inductors. With the develpment of special DSP processor (>1980), designers have a alternative: filter implementation by software on DSPs. Since the last 10 years, the designers can choose between the implementation on several technologies as
General purpose DSP Gate-Arrays
Digital filters:
DSP filters are programmable. The transfer function of the filter can be changed by exchanging coefficiants in the memory. One hardware design can implement many different, loadable filters by executing a software development process. The charachteristics of DSP filters are predictible. Filter design software packages can accurately evaluate the performance of a filter by simulation before it is implemented in hardware. Alternative digital designs are available by tools to adapt the filter to the application.
Every linear filter has an Impulse response Step response Frequency response Each of these responses contain the same information about the filter, but in different form. All representations are important because they describe how the filter will react under various circumstances.
FFT
Step response
Integrate The step response can be evaluated by discrete integration of the impulse response. The frequency response can be found from the impulse response by using the FFT (Fast Fourier Transformation).
Overshoot: Overshoot is generally a real distortion of the signal, and must therefore be eliminated or at least decreased. Overshoot changes the amplitude of the signal !. Linear phase: Often symmetry is necessary: rising edges looking similar to the falling edges.
Poor results
Good results
Overshoot
No overshoot
Nonlinear phase
Linear phase
10
Low-pass
11
General Guidelines for Frequency Domain Parameters To separate closely spaced frequencies, the filter must have a fast roll-off. For the passband frequencies it is important, that no passband ripple exists. To prevent the stop-band frequencies, it is necessary to have a good stop-band attenuation. The phase is not really important for the most applications in the frequency domain.
Example: The phase of an audio signal is completely random. If the phase is important in the application, we need a filter with a perfect phase response.
12
Poor results
Slow roll-off
Fast roll-off
Good results
Ripple in pass-band
Flat in pass-band
13
Frequency domain filtering : when the information is contained in amplitude, frequency and phase of the component sinusoids.
Separation of different frequency bands.
Custom filtering: when a special action is required and not realizable by the basic filters (low-pass, high-pass, band-pass and band-stop).
14
15
the moving average filter operates by averaging a number of points from the input signal to produce each point in the output signal. In equation form, this is written
M-1
y [ i ]= 1 /M x [ i+ j ]
j=0
Worst filter concerning frequency encoded signals (no frequency separation capabilities !) Relatives of the moving average filter include Gaussian and Blackman.
16
-1 0 2
0 2 4
1 4
14/3
2 6 2
3 4 3
4 2 5
5 0 0
x[n] 6 4
y[n] 6 4
Smoother
-4 -3 -2 -1
-9
-4 -3 -2 -1
-9
17
Symmetrical averaging requires that M be an odd number ! An unsymmetrical filter produces an time offset of the output ! Moving average is a convolution using a simple filter kernel: For 5-points the kernel is ....0, 0, 1/5, 1/5, 1/5, 1/5, 1/5, 0, 0, .... (a rectangular pulse)
18
Processing time ++
19
Processing time ++
3 point Gaussian filter 11 point 31 point Blackman filter
20
Multiple-pass averaging filter: passing the input data several times through a moving average filter.
Step response
1 pass 4 pass
1 pass
21
Y[31]= x[27] + x[28] + x[29] + x[30] + x[31] + x[32] + x[33] + x[34] + x[35] x[27] to x[34] must be calculated for y[30] and y[31] ! If y[27] has already been calculated the most efficient way for y[31] is: y[31] = y[30] + x[35] - x[26] y[i] = y[i-1] + x[i+p] - x[i-q]; with: p = (M - 1) / 2, q = p + 1
22
Windowed-sinc filters are used to separate different bands of frequencies. Features are:
stable very good overall performance in the frequency domain. but therefore --> poor performance in time domain. if done by standard convolution: needs much computation power. less execution time necessary when realized by FFT-programm.
The basic is the sinc function which is first cutted in time and then smothed with a special time window (Hamming or Blackman).
23
*
Blackmann or Hamming window Windowed-sinc filter kernel Windowed-sinc frequency response
24
25
Hamming Hamming
Balckmann
Blackmann
Hamming
Blackmann
Hamming
26
x(n-k) is a previous history of inputs y(n) is the filter output at time n bk is the vector of filter coefficients y(n) = b0 x(n) + b1x(n-1)+ b2x(n-2) + ... + bMx(n-m-1) For linear phase FIR filters, all coefficients are real and symmetrical FIR filters are easy to realize in either hardware (FPGA) or DSP software FIR filters are inherently stable ) x [n-k ] FIR filtering is a convolution in time: y[n ] = h(k
k=0
27
Unit Delay
Unit Delay
Unit Delay
x[n-3]
b0
b1
b2
b3
y[n]
28
FIR filters are always stable, because they are made only of zeros in the complex plane. Overflow errors are not problematic because the sum of products operation is realized ona finite set of data. FIR filters are easy to understand and implement. FIR filter costs computation time (dependant from filter length !)
29
Passband ripple Stopband ripple Sampling frequency Cutoff frequencys Desired amplitude
30
31
32
33
Store the output sample from the accumulator to a output buffer Store the output sample from the output buffer to the DAC
34
// Main programm for FIR.ASM #define SAMPLES 512 #define TAPS 16 .EXTERN fir; .VAR coefs[TAPS]; .VAR dline[TAPS]; .VAR inbuf[SAMPLES]; .VAR outbuf[SAMPLES]; L0=TAPS; B0=dline; M0=1; I1=0; B1=inbuf; I2=0; B2=outbuf; L8=TAPS; B8=coefs; call init_fir (db); M8=1; R0=TAPS; lcntr=SAMPLES, do filter until ce; call fir(db); R1=TAPS-1; F0=dm(i1,1); filter: dm(i2,1)=F0; .... ....
/* /* /* /*
circular buffer coefficients */ circular buffer that holds dline */ buffer coefficients */ buffer that holds dline */
/* input sample passed in F0, output returned in F0 */ /* actual data sample */ /* result to outbuf */
35
FIR.ASM
The pointer is post modified when the input sample moves to the delay buffer. The coefficients array must rearranged so thet the coefficients assocoiated mit K=max is the first element in the array. Use a tricky XOR to reset R12. The modify instructions moves the delay line pointer to the oldest value in the delay line. The multiplication works on the operands fetched in the previous cycle. The operands for the addition are the results of the multiplication; valid operands for the addition are not generated until the loop executes twice. For the first two iterations of the loop, the code uses dummy operands of zero. The third time through the loop and after, the multiplication produces two valid operands for the addition.
36
.GLOBAL ___fir; ___fir: R12=R12 xor R12, dm(i0,m0)=F0; /* set r12 =0 and store input sample in dline */ R8=R8 xor R8, F0=dm(i0,m0), F4=pm(i8,n8); /* set r8 = 0 and take data from dline and coef */ LCNTR=R1, DO macs UNTIL LCE; F12=F0*F4, F8=F8+F12, F0=DM(i0,m0), F2=PM(i8,m8); rts; F12=FF0*F4, F8=F8+F12; F8=F8+F12; .ENDSEG;
macs:
/* Multifunctions !!! */
/* perform mult on last pieces of data and 2nd last */ /* perform last add and store result in F0*/
Dline
K=0 newest sample
Coefs
K=4
I8
I0
K=3
K=2
K=02
K=1
K=1
K=0
37
IIR Filters
H(z) = b0 + b1z-1 + b2z-2 + ... + bMz-M 1 + a1z-1 + a2z-2 + ... + aNz-N
Advantages Fewer coefficients for sharp cutoff filters. Able to calculate coefficients for standard filter (Bessel, Butterworth, DolphTschebyscheff, Elliptic ....). Disadvantages Existing non-linear phase response. Filter can be unstable: precision of coefficients is important, adaptive filters are difficult to realize.
38
y[n]
b0
Unit Delay Unit Delay X Unit Delay + + X
x[n-1]
y[n-1]
Unit Delay
b1
a1
x[n-2]
X X
y[n-2]
b2
a2
39
6th order IIR (Bessel) IIR filter has strong cutoff but extreme non-linear phase the 180 phase jumps comes when the response changes sign
40
Reference: The Scientiest and Engineers Guide to Digital Signal Processing Second Edition by Steve Smith www.DSPguide.com
41