Digital Filter : by Madhuchhanda Mitra
Filter :
Filtering is a process by which the frequency spectrum of a signal can be modified,
reshaped or manipulated according to some desired specification.
Use :
1. To eliminate signal contamination such as noise.
2. To remove signal distortion.
3. To separate two or more distinct signals which are purposely mixed in order to
maximize channel utilization.
4. To resolve signal into their frequency components (DWT).
5. To band limit signals.
Digital filter is a digital system that can be used to filter discrete time signals. It can be
implemented by means of software or by means of dedicated hardware.
Digital Filter advantages :
1. They do not drift – Unlike analog filters, the performance of digital filters does not
vary with environmental changes, for example thermal variation. This eliminates the
need to calibrate periodically.
2. They can handle low frequency signals. Digital filters can be designed for very low
frequency – for example in Biomedical applications, where the use of analog filters is
impractical. Also, digital filters can be made to work over a wide range of frequencies
by a mere change to the sample frequency.
3. Frequency response characteristics can be made to approximate closely to the ideal.
4. Linear phase characteristics are possible.
5. Both filtered and unfiltered data can be saved for further use.
6. The performance of digital filter is repeatable unit to unit.
7. They can be made to have no insertion loss.
8. Digital word length may be controlled by the filter designer and therefore the
accuracy of filter may be precisely controlled.
9. Advantage can be readily taken of the tremendous advancement in VLSI Technology
to fabricate digital filter and to make them small in size, to consume less power and to
keep the cost down.
Digital Filter disadvantages :
1. Speed limitation -The maximum bandwidth of signal that digital filters can handle, in
real time, is much lower than that for analog filters. In real time situation the analog –
digital – analog conversion process introduce a speed constrain on the digital filter
performance. The conversion time of ADC and the settling time of DAC limit the
highest frequency that can be processed. Further, the speed of operation of a digital filter
depends on the speed of digital processor used and on the number of arithmetic
operation that must be performed for the filter algorithm.
2. Finite word length effect – Digital filters are subject to ADC noise resulting from
quantizing a continuous signal and round off noise incurred during computation.
3. Long design and development time – The design and development time for digital
filters specially for hardware filters can be much longer than for analog filters.
Block diagram of a real time digital filter :
Input ADC with Output Analog
Analog band Sample and Digital smoothing output y(t)
signal limiting Hold Processor DAC filter
filter
The band limited analog signal is sampled periodically and converted into a series of
digital samples x(n) n= 0,1,2,---. The digital processor implements the filtering operation
– mapping of the input sequence x(n) into the output sequence y(n) in accordance with a
computational algorithm for the filter. DAC converts the digitally filtered output into
analog values which are then analog filtered to remove unwanted high frequency
components from output .
There are two common types of digital filters, Recursive filters and Non recursive
filters. The filter pulse transfer function has the form
N M
H(z) = Y(z)/X(z) = ∑ anz / ∑ bm z-m
-n
n=0 m=0
The recursive filter contains both feed forward and feedback path. So in case of
recursive filter, both
an ≠ 0 and bm ≠ 0
Non recursive filters contain only feed forward path. So in case of non recursive filter
an ≠ 0 but bm= 0
Impulse response :
Recursive filtere
H(z) = (a0 + a1z-1) / (b0 + b1z-1)
Y(z) / X(z) = (a0 + a1z-1) / (b0 + b1z-1)
Y(z) = A0X(z) + A1X(z)z-1 – B1Y(z)z-1 [ A0 = a0/b0 and so on]
y(n)T = A0x(n)T + A1x(n-1)T – B1y(n-1)T
For impulse type input
x(1)T=1
x(2)T = x(3)T = x(4)T --- = x(n)T = 0
y(1)T = A0
y(2)T = A1 – B1A0
y(3)T = B1(A1 – B1A0)
----
So for unit impulse type input we get infinite number of output terms. So recursive filter
is Infinite Impulse Response (IIR) type filter
Non Recursive filtere
H(z) = (a0 + a1z-1)
Y(z) / X(z) = (a0 + a1z-1)
Y(z) = a0X(z) + a1X(z)z-1
y(n)T = a0x(n)T + a1x(n-1)T
For impulse type input
x(1)T=1
x(2)T = x(3)T = x(4)T --- = x(n)T = 0
y(1)T = A0
y(2)T = A1
y(3)T = y(4)T = --- =y(n)T = 0
So for impulse input we get a finite number of output term and width of the output pulse
depends on the order of the filter. So non recursive filter is Finite Impulse Response
(FIR) filter.
Choosing between FIR and IIR filters :
1. FIR filters can have exactly linear phase response.
2. FIR filters are always stable. The stability of IIR filters can not always guaranteed.
3. FIR requires more coefficients for sharp cut off filters than IIR. Thus for a given
amplitude response specification, more processing time and storage will be required for
FIR implementation.
4. Analog filters can be readily transformed into equivalent IIR digital filters. This is not
possible with FIR filters.
5. In general, FIR is algebraically more difficult to synthesize.
IIR filter design :
There are five main stages.
1. Filter specification – Designer gives the function of the filter ( for example low pass)
and the desired performance.
2. Approximation – Appropriate transfer function order selection and coefficient
calculation.
3. Realization – To convert the transfer function into a suitable filter structure or finite
difference equation.
4. Analysis of error – Effect of finite word length.
5. Implementation – Building the hardware or writing software codes and real time
testing of filter.
Approximation – May be direct or indirect.
In indirect approach we will firstly obtain a suitable transfer function G(s) and then
derive the corresponding pulse transfer function G(z). using z transform methods.
In direct approach we determine G(z) directly from the filter specification.
We select indirect approach to design IIR digital filter.
Butterworth low pass filter
For a butterworth filter to approximate to the ideal lowpass characteristics the following
relation is used
| G(jω)| 2 = 1/ [1+ (ω/ωc)2n] = 1/[1+(-1)ns2n] (s=jω/ ωc) ----- (1)
Where | G(jω)| 2 is the squared magnitude of the filter transfer function, n is the order of
the filter and
ωc is the corner frequency .
If n →∞
then if (ω/ωc) < 1 | G(jω)| 2 = 1
(ω/ωc) > 1 | G(jω)| 2 =0
Ideal characteristics.
Ideal lowpass filter is one that will pass only low frequency components. The frequency
range from 0 to ωc and ωc to ∞ are the passband and stopband. ωc is the cutoff
frequency.
A practical lowpass filter differs from the ideal one that the passband loss is not zero and
stopband loss is not infinite and the transition between passband and stopband is
gradual. The cut off frequency is a hypothetical boundary between passband and
stopband which may be 3 dB frequency.
[ If ω = ωc , | G(jω)| 2 = 0.5
dB = 20log|G(jω)| = 10log| G(jω)| 2 = -3 dB ]
A filter transfer function must satisfy the following constrains :
1. It must be a rational function of s with real coefficients.
2. Its pole must lie in the left half s plane.
3. The degree of numerator polynomial must be equal to or less than that of denominator
polynomial.
In equation (1) the roots of the denominator term [1+(-1) ns2n] correspond to the poles of
the filter which lie equally spaced on the circumference of a unit circle in the s plane.
Letting the angle of the kth root be denoted by Φk where
k = 0, 1, 2, ---- (2n – 1) then
Φk = kπ / n for n odd
Φk = (k+(1/2)π) / n for n even ---- (2)
For a stable Butterworth filter the transfer function G(s) is rational function having
numerator equal to unity and denominator determined by selecting the roots of [1+(-
1)ns2n] that are located in the left half s plane. Mirror images of poles of G(s) exist in the
right half s plane and we associate this with G(-s).
Example :
Suppose that to meet a given filter specification the order of the filter must be n=3.
Derive the corresponding transfer function for a Butterworth lowpass continuous filter.
Solution :
Since k=0, 1, 2, ---- (2n-1), There are six poles on the circumference of the unit circle in
the s plane. Their angular positions being determined by equation (2) and corresponding
s plane representation is shown in figure.
P2, P3 and p4 are the poles in left half s plane.
Φ2 = 2π/3
P2 = cos (2π/3) +jsin(2π/3) = (-1/2) +j(√3/2)
Φ3 = π
P3 = -1 +j0 = -1
Φ4 = 4π/3
P4 = cos (4π/3) +jsin(4π/3) = (-1/2) -j(√3/2)
G(s) = 1 / [(s+1){s+ 1/2- j(√3/2)}{s+ 1/2 + j(√3/2)}]
= 1/ [(s+1)(s2 + s +1)]
In the example it was assumed that the value of n was known, however in practice the
order of the filter complexity, n, would have to be determined using the data of the filter
specification.
Attenuation -X dB = 10log10|G(jω)|2 ---- (3)
-X dB = 10log10[1 / {1+ (ω/ωc)2n}]
-X dB = 10log1 – 10log10[ 1+ (ω/ωc)2n]
X dB = 10log10[ 1+ (ω/ωc)2n] --- (4)
Value of n is determined from attenuation X, ω and ωc
Example :
The specification for a Butterworth lowpass continuous filter reads as follows :
a) Cut off frequency fc = 50 Hz
b) Amplitude response to be at least 20 dB down when f = 200 Hz.
Determine the value of n that will satisfy the given specification.
Solution :
Using equation (4)
20 = 10log[1 + (200/50)2n]
antilog(2) = 1 + (4)2n
99 = (4)2n or n = 1.657 (approx)
or n = 2
Assignment : If n=2 determine transfer function G(s)
Hints : If n= 2, k = 0, 1, 2, 3
Φ0 = π/4
Φ1 = 3π/4
Φ2 = 5π/4
Φ3 = 7π/4
P1 and P2 lie in the left half s plane.
S plane to z plane mapping – Bilinear z transform :
The bilinear z transform is characteristically band limiting in nature. This band limiting
property arises when the s plane representation of the prototype continuous filter transfer
function G(s) is replaced by an equivalent R plane representation where s = σ + jω and
R = u + jv and
s = (2/T) tanh(RT/2)
s = (2/T)[ sinh(RT/2) / cosh(RT/2)]
s = (2/T) [(eRT/2 – e-RT/2) / (eRT/2+ e-RT/2)
s = (2/T) [(eRT – 1) / (eRT+ 1)
If z= eRT then
z = (2/T) [(z-1)/(z+1)]
Thus G(s) may be transformed to G(z) via the bilinear z transform. Hence it is seen that
the entire left half of the s plane transform into strips in the R plane which have a width
equal to 2π/T rad/s ( a band limited region) and is seen that if z = e RT then strips in left
half of the R plane transform to cover the area contained inside the unit circle in the z
plane.
Mapping properties of Bilinear z transformation :
s = (2/T)[(z-1) / (z+1)]
or s / (2/T) =(z-1)/(z+1)
z = (2/T + s) / (2/T – s)
If s = s = σ + jω and z = R ejϴ
R ejϴ = [(2/T +σ )+ jω ] / [(2/T σ ) jω ]
R = [{(2/T +σ )2 + ω2} / {(2/T- σ )2 + ω2} ]1/2
ϴ = tan-1(ω/(2/T + σ)) + tan-1(ω/(2/T - σ))
If σ > 0 R > 1
If σ < 0 R < 1
If σ = 0 R = 1
Therefore bilinear transformation maps
1. The open right half s plane onto the region exterior to the unit circle |z| = 1 .
2. The j axis of the s plane onto the unit circle |z| = 1.
3. The open left half s plane onto the interior of the unit circle |z| = 1.
For σ = 0 R = 1 ϴ = 2tan-1(ωT /2) . Hence
ϴ = 0 for ω = 0
ϴ = π for ω = +∞
ϴ = -π for ω = -∞
The origin of s plane maps onto the point (1,0) of the z plane and the positive and
negative j axis of the s plane maps onto the upper and lower semicircles |z| = 1
respectively.
Therefore bilinear transformation maps the entire jω axis in the s plane to one revolution
of the unit circle in the z plane. In bilinear z transform, s plane to z plane mapping is one
to one mapping. Since -∞ ≤ ω ≤ ∞ maps onto -π ≤ ϴ ≤ π the transformation between
continuous time and discrete time frequency variables must be nonlinear – frequency
warping.
Properties :
1. Stable continuous time filter maps into stable discrete time filters and numerator
degree can not exceed the denominator degree. Therefore H(z) is a realizable transfer
function.
2. Passband and stopband in the analog filter translate into passband or stopband in the
digital filter.
3. As in bilinear transformation s is a linear function of z and z is a linear function of s
order of the analog filter remain unchanged in digital filter.
The main disadvantage of bilinear z transform is warping of the frequency scale exists.
The problem of warping is overcome by pre warping the corner frequencies.
Let ωca and ωcd represent frequency variable in the analog filter and derived digital filter.
Then s= j ωca and z = ejωcd
j ωca = (2/T)(ejωcd – 1) / (ejωcd + 1)
j ωca = (2/T)[(ejwcdT/2 – e-jwcdT/2) / (ejwcdT/2 + e-jwcdT/2)]
j ωca = (2/T)[ 2jsin(ωcdT/2) / 2cos(ωcdT/2)]
ωca = (2/T)tan(ωcdT/2)
The relationship between ωca and ωcd is shown in figure.
Example :
Using the bilinear z transform derive the digital equivalent of a second order
Butterworth lowpass filter which has the following specification :
1. Digital filter cut off frequency fcd = 100 Hz
2. sampling period T = 1.6 ms
The prototype continuous filter is given by
G(s) = 1 / (s2 + √2s + 1)
ωca = (2/T)tan(ωcdT/2)
= (2/T) tan( 200πx1.6x10-3 /2)
= (2/T)x0.55
Transformation from normalized lowpass to lowpass filter is achieved by substituting (s/
ωca) for s
Then G(s)new = 1 / [({s2/(2x0.55/T)2} +{√2s/(2x0.55)/T} +1]
s=(2/T)[(z-1)/(z+1)]
G(z) = 1 / [{(z-1)/(z+1)}2x1/0.3} + {2.57x(z-1)/(z+1)} +1]
G(z) = (z2 + 2z +1)/(6.9z2 -4.66z +1.76)
G(z) = (a0z2 +a1z +a2) / (b0z2 +b1z +b2)
Y(z)/X(z) = (A0 + A1z-1 +A2z-2) / (1 + B1z-1 +B2z-2) [ divide numerator and denominator
by b0z2 ]
Y(z) = A0X(z) + A1X(z) z-1 +A2X(z) z-2 - B1Y(z)z-1 – B2Y(z)z-2
y(n)T = A0x(n)T + A1x(n-1)T +A2x(n-2)T - B1y(n-1)T – B2y(n-2)T
This is the linear difference equation of the filter.
Filter algorithm :
x(t) ADC Processor
Filter
y(t) DAC Algorithm
1. Initialize I/O port.
2. Initialize six memory location M1 to M6 [ The value of x(n)T, x(n-1)T, x(n-2)T,
y(n)T, y(n-1)T, y(n-2)T are to be stored in M1, M2, M3, M4, M5 and M6 ]
3. Input the value of x(n)T
4. store the value of x(n)T in M1.
5. Perform the operation
y(n)T = A0x(n)T + A1x(n-1)T +A2x(n-2)T - B1y(n-1)T – B2y(n-2)T
6. Store the result in M4.
7. Out the result through I/O port.
8. Move data from M2 → M3 and from M1 → M2 [ x(n-1)T becomes x(n-2)T and
x(n)T becomes x(n-1)T for the next cycle.]
9. Move data from M5 → M6 and from M4 → M5 [ y(n-1)T becomes y(n-2)T and
y(n)T becomes y(n-1)T for the next cycle.]
10 Go to step 3
FIR filter :
Moving average filter :
Most elementary form of FIR filter
N −1
y(n)T = (1/N) ∑ x ( n− k ) T
k=0
If N=2
y(n)T = (1/2)[x(n)T + x(n-1)T]
Y(z) = (½) [ X(z) + X(z)z-1]
H(z) = Y(z) / X(z) = (½) [ 1 + z-1] = (z+1) / 2z
Therefore zero at z = -1 and pole at z=0
Now ωs = 2π/T
ωT = 2πω / ωs
The highest frequency content in the signal is ωs /2 [ sampling theorem]
If ω = 0 ωT = 0
If ω = ωs /2 ωT = π
If ωT = 0 |H(z)| = 1
If ωT = π |H(z)| = 0 [ z = ejωT = cos(ωT) + jsin(ωT) ]
Therefore two point moving average filter is equivalent to fist order FIR lowpass filter.
Now, if y(n)T = (½) [x(n)T – x(n-1)T]
Y(z)/X(z) = H1(z) = (1/2)(1-z-1)
H1(z) = (z-1) / (2z)
Now, if ωT = 0 |H1(z)| = 0
ωT = π |H1(z)| = 1
This is first order high pass filter of the form
M− 1
H1(z) = (1/M) ∑ ( −1 )nz-n
n=0
General moving average N point filtered
N −1
y(n)T = (1/N) ∑ x ( n− k ) T
k=0
For hardware realization of moving average filter the input samples x(n)T are passed
through a series of buffer register s (labeled z -1 , corresponding to the z transform
representation of a delay element). Say we wish to develop 4 point moving average filter
then,
y(n)T = (1/4)x(n)T + (1/4)x(n-1)T + (1/4)x(n-2)T + (1/4)x(n-3)T
There are four taps corresponding to a four point moving average filter. Each sample is
multiplied by 0.25 and results are added to yield the final moving average output y(n)T.
Cut off frequency decreases when the no. of tap increases.
Total number of maximum and minimum points equals to the number of taps.
|H(z)| = 0 for ωT = 0 always
For even number of taps, |H(z)| = 0 at ωT = π
For odd number of taps, |H(z)| = max at ωT = π
For 11 point moving average filter,
Number of maximum points = 6
Number of minimum points = 5
Now if fs = 1 KHz Ts = 1 ms
Average of any sinusoidal signal over a complete cycle is zero
for 3 point MA filter Tc = 3 ms
Therefore fc = 1/(3 ms) = 0.33 KHz
Therefore for 3 point MA filter cut off frequency is 0.33 KHz.
For 10 point MA filter Tc = 10 ms
Therefore fc = 0.1 KHz = 100
Therefore for 10 point MA filter cut off frequency is 0.1 KHz.
Q. If sampling frequency is 1 KHz, to eliminate 50 Hz power line noise , determine the
no. of tap points required for MA filter.
fs = 1 KHz Ts = 1 ms
for power line noise fc = 50 Hz therefore Tc = 20 ms
Therefore no. of required tap is 20.