Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

E713.

3 Laboratory Report

Digital Filter Design Using MATLAB

By:

Aleksandar Lazarevic

Need for signal processing and filtering are as old as electronic engineering itself, but
recent developments in telecommunications, multimedia and modern warfare have
pushed design requirements to before unknown levels. Quest for more bandwidth, better
sound definition and better video compression has fuelled significant new developments
in filter designs. Starting point for any aspiring electronic engineer is learning to use the
industry-standard MATLAB software package and exploring its numerous uses in signal
processing and filter design.

Performed on: 01/02/2000 Tutor: Lionel Sacks


Aleksandar Lazarevic Experiment E713.3

Table of Contents

1 INTRODUCTION................................................................................................................................. 3

2 THEORY ............................................................................................................................................... 4
2.1 SIGNAL SAMPLING ........................................................................................................................... 4
2.2 THE Z TRANSFORM .......................................................................................................................... 6
2.3 Z-PLANE TRANSFER FUNCTION ........................................................................................................ 6
2.4 BILINEAR TRANSFORMATION .......................................................................................................... 7
2.5 IMPULSE INVARIANT POLE MAPPING ............................................................................................... 7
3 EXPERIMENTAL PROCEDURE AND RESULTS ......................................................................... 8
3.1 EQUIPMENT USED ............................................................................................................................ 8
3.2 RAW INPUT SIGNALS AND EXPECTED FILTERED RESULTS ................................................................. 8
3.3 ANALOGUE FILTER DESIGN ............................................................................................................. 9
3.4 DIGITAL FILTER BY NUMERICAL INTEGRATION ............................................................................. 13
3.5 S-PLANE TO Z-PLANE MAPPINGS .................................................................................................... 17
3.6 IMPULSE RESPONSE OF A DIGITAL FILTER ..................................................................................... 18
3.7 FINITE IMPULSE RESPONSE (FIR) AND INFINITE IMPULSE RESPONSE (IIR) FILTERS...................... 19
3.8 FREQUENCY RESPONSE OF A DIGITAL FILTER................................................................................ 21
3.9 DESIGNING A DIGITAL FILTER USING YULE-WALKER METHOD.................................................... 22
3.10 IMPROVING THE DESIGN THROUGH CLUSTERING POLES AND ZEROS ............................................... 26
3.11 CASCADING DIGITAL FILTERS ....................................................................................................... 28
3.12 BATCH FILTERING ......................................................................................................................... 29
4 DISCUSSION ...................................................................................................................................... 32
4.1 ANALOGUE FILTER DESIGN ........................................................................................................... 32
4.2 DIGITAL FILTER DESIGN ................................................................................................................ 32
4.2.1 Design by Numerical Integration.......................................................................................... 32
4.2.2 Digital Filter Impulse Response............................................................................................ 32
4.2.3 FIR and IIR Filters................................................................................................................ 33
4.2.4 Digital Filter Frequency Response ....................................................................................... 33
4.2.5 Digital Filter Synthesis Using Yule-Walker Method ............................................................. 33
4.2.6 Digital Filter with Clustered Poles and Zeros ...................................................................... 33
4.3 CASCADING DIGITAL FILTERS ....................................................................................................... 34
4.4 BATCH DIGITAL FILTERING ........................................................................................................... 34
5 CONCLUSIONS ................................................................................................................................. 35

6 NOMENCLATURE............................................................................................................................ 36

7 REFERENCES.................................................................................................................................... 37

Page 2.
Aleksandar Lazarevic Experiment E713.3

1 Introduction

Arguably the fastest field of development of modern electronic engineering is the filed of

digital signal processing. Enormous demand for telecommunications equipment, real-

time data acquisition and processing and the quest for ever improving voice and video

compression logarithms has fuelled research and development in the filed of dedicated

Digital Signal Processing (DSP) hardware and software. In the last decade signal filtering

and processing debuted into domains of business and economics, analysing complex

patterns of global financial movements and trying to predict future developments. This

new generation of filters relies on advance mathematical models to quickly and precisely

filter the signal and extrapolate any required predictions of future data.

Although digital filters can be designed directly, without reference to any corresponding

analogue function, this experiment followed the chronological developments by firstly

constructing digital filters from an equivalent analogue design. Finally, superiority and

flexibility of “off line” filtering was demonstrated by using a simple batch filtering

process.

Page 3.
Aleksandar Lazarevic Experiment E713.3

2 Theory
2.1 Signal Sampling

Many signals processed by digital filtering are inherently discreet in time, such as
financial data, manufacturing statistics or meteorological measurements. However, a
majority of signals encountered in engineering are originally continuous in time or space.
In order to enable digital manipulation, these signals must be converted to discreet time
by the process of sampling. Although sampling can lead to data loss and signal distortion,
band-limitting the input signal and sampling it at the sufficiently high frequency these
losses can be minimized to a negligible amount. If the input signal is not sampled at a
sufficiently high frequency, aliasing will occur. To ensure that the signal is sampled
properly, each frequency component needs to satisfy the condition:
Ω0 < π , T = sampling period1
T
This condition is the sampling theorem, or Nyquist’s or Shannon’s theorem, stating that
the sampling frequency must be twice the signal bandwidth. Figure 2.1 shows two
periodic cosine waveforms with frequencies symmetrical around half the Nyquist
frequency of fs/2=1Hz.

S am pling of 0.6Hz and 1.4Hz c os ine s ignals @2Hz


1

0.8

0.6

0.4

0.2
A m plitude

-0.2

-0.4

-0.6

-0.8

-1
0 0.5 1 1.5 2 2.5 3
Tim e /s

Figure 2.1. Sampling of two sinusoidals.

It is clear that both waveforms, although with different frequencies, have same values on
each and every sampling instant, as marked on the plot. A periodical sinusoidal waveform

Page 4.
Aleksandar Lazarevic Experiment E713.3

needs to be sampled at least twice per its cycle, which is not the case with 1.4Hz cosine
wave in the above example. This has led to aliasing, and as further proven in Figure 2.2,
has rendered these two signals indistinguishable after sampling.

T = 0.5s
x1 (t ) = cos(2π ⋅ 1,4 ⋅ t )
x2 (t ) = cos(2π ⋅ 0.6 ⋅ t )
x1 (n) = cos(2,8 ⋅ πTt ) = 12 [e j1, 4πn + e− j1, 4πn ]; discrete time sampled
x2 (n) = cos(1,2 ⋅ πTt ) = 12 [e j 0, 6πn + e − j 0, 6πn ]; discrete time sampled

X 1 (e jw ) = π ⋅ ∑ [δ (ω − 1,4π − 2πk ) + δ (ω + 1,4π − 2πk )] ; DTFT
k = −∞

X 2 (e jw ) = π ⋅ ∑ [δ (ω − 0,6π − 2πk ) + δ (ω + 0,6π − 2πk )] ; DTFT
k = −∞

Figure 2.2. Aliasing of two cosine signals.

Observed in frequency domain after sampling these two signals have same spectral
components, as shown in Figure 2.3.

Figure 2.3. Aliasing of two cosine signals.

Page 5.
Aleksandar Lazarevic Experiment E713.3

2.2 The z Transform

The z transform is the discreet-time equivalent of the Laplace (s) transform. Rather than
using convolution for the discreet-time signals themselves, relations between the inputs
and outputs of a system can be obtained by multiplication of the appropriate z transforms.
Using z transform, the frequency response of the system can be readily derived and can
be related to a discrete-time Fourier transform.

The z transform of the sequence x(n) is defined by:



X ( z) = ∑ x( n) z
n = −∞
−n

The signals used in this experiment were sampled signals that have values only at the
sampling instants. The basis functions used to describe sampled signals are sampled
versions of exponential signals. For the casual exponential sequence the z transform is
given as follows2:
x ( n) = a n u ( n)

1 z
X ( z ) = ∑ a n z −n = ∑ (az −1 ) n =−1
= , z>a
n =0 1 − az z−a
It is clear from the equation above that the z transform has a pole at z=a and a zero at
z=0. A first order rational z transform for a sampled exponential signal can be estimated
by MATLAB using an algorithm known as Prony’s method ([b,a]=prony(h,n,k)).
The z operator is often considered as a delay or advance operator. A special example of
this is z-1, referred to as a unit delay operator. The time shifting property of the z
transform has been proved, as shown in Figure 2.4.

Ζ{x[n − n0 ]} = ∑ x[n − n ] ⋅ z
n = −∞
0
−n

substitution : m = n − n0

Ζ{x[n − n0 ]} = ∑ x[m] ⋅ z
m = −∞
−m
⋅ z −n0 = z −n0 X ( z )

Figure 2.4.
From the relationship z=exp(sT), it is clear that the s transform region of convergence
(left-half of the s plane) maps to a z transform region of convergence within a unity circle
centred on the axis origin. Sampled signals with poles within the unity circle are casual
signals from decaying exponentials, while signals whose poles are mapped outside the
unity circle are anticasual, growing signals.

2.3 z-Plane Transfer Function

In discreet-time systems, transfer function is described by a difference equation,


analogous with continuous-time systems whose transfer function is given by a differential
equation. After designing a digital filter, it is necessary to confirm its compliance with
required frequency response specifications. Since the imaginary s-plane axis is
transformed to the circle bounding the unity disc, this involves evaluating the z-plane
transfer function for values of z that lie on this circle. For any given real transfer function,

Page 6.
Aleksandar Lazarevic Experiment E713.3

poles and zeros will either be real or occur in complex conjugate pairs. Therefore, the
frequency response functions will be identical on the circle side above and below the real
z axis, rendering the filter frequency response symmetrical around the Nyquist frequency.

2.4 Bilinear Transformation

Bilinear transformation is a real function transformation that does not increase the order
of the filter and preserves its stability and causality. It is one of the most commonly used
mapping transformations in Infinite Impulse Response (IIR) filter design. The
transformation from s domain into z domain is done using following equations3:

2 z −1 2
+s
s= ⋅ and vice versa : z = T

T z +1 2
T −s
transfer function transformation :

H ( z ) = H bilin ( s ) 2 z −1
s= ⋅
T z +1

2.5 Impulse Invariant Pole Mapping

Impulse Invariant Pole Mapping is another transformation method used for converting
analogue transfer function into digital transfer function. Importantly, impulse invariant
mapping preserves the stability and causality of the filter, the filter order is not increased
and the newly obtained transfer function is real4.

N
Ai
H a (s) = ∑ , analogue transfer function, p - poles
i =1 s − pi
N
ha (t ) = ∑ Ai e pi ⋅t , inverse Laplace transformation
i =1
N
ha (nT ) = h[n] = ∑ Ai e pi ⋅nT
i =1
N
Ai z N ( z)
H ( z) = ∑ =
z − e piT N
i =1
∏(z − e
i =1
piT
)

Page 7.
Aleksandar Lazarevic Experiment E713.3

3 Experimental Procedure and Results


3.1 Equipment used

For the purpose of this experiment, the industry standard MATLAB software by
MathWorks was used. Now in its 5.2 version, MATLAB was first published in 1984.
and ever since became an irreplaceable tool for engineers worldwide. The software has
been ported to a number of platforms, including the most popular versions for Microsoft
Windows platforms and different UNIX systems. MATLAB features a unique scripting
language and its modular implementation of mathematic functions through M-files made
it possible for third parties and users to write their own customized functions and
procedures.

3.2 Raw input signals and expected filtered results

Signals supplied as inputs were simulations of a satellite mounted infrared Earth sensor
detecting the position of the horizon in its field of view. The sensor takes measurements
every four seconds and outputs values proportional to the position of the horizon. Plotted
in Figure 3.1. are the input signals signal1 and signal2. Sample-and-hold circuit was
simulated in the data for signal2 giving rise to the staircase function rather than a series
of spikes.
Inputs s ignal1 and signal2 to be filtered
7

5
Relative pos ition of the horiz ont

-1
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.1. Raw input signals to be filtered.

Page 8.
Aleksandar Lazarevic Experiment E713.3

Data plotted above contains desired sensor data that can be sued to control and adjust the
movement of the satellite, but it also contains an undesirable low frequency component of
0.1Hz. This is the natural frequency of vibrations in the satellite solar panels, or could be
due to the fluctuations in the power supply. The final desired output of this data, after
being sampled at 2Hz and filtered is plotted in Figure 3.2.

Des ired output s ignals want and want2


6

5
Relative pos ition of the horiz ont

0
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.2. Desired output signals after filtering.

Filtered signal would then need further real-time processing in order to obtain the
gradient of the best straight line fit to all the peaks. This information would then be
passed on to control the satellite propulsion systems adjusting its motion.

3.3 Analogue Filter Design

Shown in Figure 3.3. is a simple LC analogue filter. Frequency response of this circuit
has a deep notch at:
ωC = 1L ⋅ C
It can be characterised by following time domain differential equation and s-plane
transfer function:

Page 9.
Aleksandar Lazarevic Experiment E713.3

d2y dy L d 2u
Timedomain : LC + ⋅ + y = LC + u
dt 2 dt R dt 2
Y (s) s 2 LC + 1
s − plane : =
U (s) L
s 2 LC + s + 1
R

L=1H

C=2.53C

R=1omh

Figure 3.3. LC Notch Filter Circuit.


To position the filter notch at 0.1Hz we can calculate the required values of inductor L
and capacitor C using:
2
 10 
LC =  
 2π 
It is clear that for any sensible and practically possible value for one of the components,
the other component would be of enormous value. If a 1H inductor was used, required
capacitance would be 2.53C.
Matlab code shown in Figure 3.4. was used to calculate and plot the frequency response
of the analogue filter.
f=(0:127)*2/128;
w=2*pi*f;
const=(10/(2*pi))^2;
num=[const 0 1];
den=[const 1 1];
cfr=freqs(num,den,w);
mod=abs(cfr);
arg=angle(cfr)*180/pi;
plot(f,mod)
figure
plot(f,arg)
Figure 3.4. MATLAB code for calculating complex frequency response.

The values of inductor L and resistor R were set to 1H and 1Ω respectively. Function
freqs() returns the complex frequency response vector of the filter given the numerator
and denominator coefficients. Before calling this function, numerator values were set to
the values of coefficients multiplying u, while denominator values were coefficients
multiplying y in the time domain differential equation. Obtained results for modulus
(amplitude) and argument (phase) of the frequency response were plotted as in Figures 5.
and 6. respectively.

Page 10.
Aleksandar Lazarevic Experiment E713.3

F requenc y res pons e of LC A nalogue F ilter (am plitude)


1

0.9

0.8
Relative A m plitude

0.7

0.6

0.5

0.4

0.3

0.2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
F requenc y /H z

Figure 3.5. Complex Frequency Response Modulus (amplitude) of LC filter.


F requenc y res pons e of LC A nalogue F ilter (phas e)
80

60

40

20
P has e /degrees

-20

-40

-60

-80
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
F requenc y /Hz

Figure 3.6. Complex Frequency Response Argument (phase) of LC Filter.

Page 11.
Aleksandar Lazarevic Experiment E713.3

Further, using MATLAB code shown in Figure 3.7. and roots() function, series of zeros
and poles of the filter transfer function were found. Function atan2() is an inverse tangent
(arctangent) function operating on all four quadrants.
ps=roots(den);
zs=roots(num);
polar(0,1,' ');
hold
polar(atan2(imag(zs),real(zs)),abs(zs),'o')
polar(atan2(imag(ps),real(ps)),abs(ps),'*')
hold
Figure 3.7. MATLAB code for plotting pole-zero chart of LC filter transfer function.

Plot obtained running the above code has been shown as in Figure 3.8.

90
P ole-Zero P lot of LC Filter Trans fer Function
1
120 60
0.8

0.6
150 30
0.4

0.2

180 0

210 330

240 300

270

Figure 3.8. Pole-Zero Plot of LC Filter Transfer Function.

It was noted that all poles and zeros lie within unity circle thus making this circuit a
stable design.
Finally, raw input signal signal1 was filtered through the LC analogue filter. MATLAB
code shown in Figure 3.9. was run to produce a split screen plot showing the signal
before and after filtering process. Frequency response of the analogue filter (cfr) is
multiplied on term-by-term basis (.*) by the input signal converted to the frequency
domain by Fast Fourier Transform (fft) function. This operation produces an output in the
frequency domain, which was subsequently converted to the time domain by the Inverse
FFT function (ifft).

Page 12.
Aleksandar Lazarevic Experiment E713.3

afsig=ifft(cfr.*fft(signal1,128));
mx=abs(afsig);
subplot(2,1,1),plot(t,signal1)
subplot(2,1,2),plot(t,mx)
Figure 3.9. MATLAB Code for applying analogue filtering to input signal1.

Both signals were then plotted in time domain, as shown in Figure 3.10, clearly indicating
the dampening of the 0.1Hz component.

Signal1 before analogue filtering


6
Relative amplitude

-2
0 10 20 30 40 50 60 70
Signal1 after analogue filtering
6
Relative amplitude

0
0 10 20 30 40 50 60 70
Time /s
Figure 3.10. Unfiltered and Filtered (LC Analogue) Signals.

3.4 Digital Filter by Numerical Integration

In this section of the experiment, a digital filter was simulated using MATLAB filter()
function. This function is based on the standard difference equation using Direct Form II
Transposed implementation. Arguments to the filter() function are two vectors a and b
containing coefficients multiplying y and u values in the difference equation, as shown in
Theory section. MATLAB code shown in Figure 3.11. was used to calculate filter
argument vectors and apply the digital filtering.
L=1
C=(10/(2*pi))^2
a=[ (((L*C)/(T^2))+(1/(2*T))) (1-2*((L*C)/(T^2))) (((L*C)/(T^2))-
(1/(2*T))) ]
b=[ ((L*C)/(T^2)) (1-2*((L*C)/(T^2))) ((L*C)/(T^2)) ]
sigfilt1=filter(b,a,signal1);

Page 13.
Aleksandar Lazarevic Experiment E713.3

fr=faxis(2);
subplot(2,1,1),plot(fr,ampl(fft(signal1)))
subplot(2,1,2),plot(fr,ampl(fft(sigfilt1)))
figure;
subplot(2,1,1),plot(t,signal1)
subplot(2,1,2),plot(t,sigfilt1)
Figure 3.11. MATLAB code for Digital Filtering of signal1.

Figure 3.12. shows split plots of signal1 before and after being filtered. The 0.1Hz
frequency component in the unfiltered signal is very strongly attenuated by the filter and
is hardly noticeable in the filtered signal. Other spectral lines are harmonics of the
fundamental signal with a frequency of 0.25Hz. These components correspond to the
input sensor returning readings and are thus part of the wanted signal. Simulated digital
filter passes these frequency components with very slight attenuation.

Frequenc y Dom ain Unfiltered S ignal


60
Relative A m plitude

40

20

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

Frequenc y Dom ain Filtered S ignal


50
Relative A m plitude

40

30

20

10

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
W rapped round frequenc y /Hz

Figure 3.12. Frequency Domain plots of Digital Filter performance.

Page 14.
Aleksandar Lazarevic Experiment E713.3

The impact of the filtering process is clearly seen in Figure 3.13. showing time domain
plots of the signal before and after filtering. Evidently, the filter operation is increasingly
better as more samples have been processed, explaining poor filter performance in first
10 seconds of operation. During this time, sensor readings are small in value, and are
being overwhelmed by the 0.1Hz component.

Tim e Dom ain Unfiltered S ignal


6
Relative A m plitude

-2
0 10 20 30 40 50 60 70

Tim e Dom ain Filtered S ignal


6
Relative A m plitude

-2
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.13. Time Domain plots of unfiltered and filtered signal.

Page 15.
Aleksandar Lazarevic Experiment E713.3

Ultimately, the difference between the desired output signal want1 and signal filtered
using the digital filter sigfilt1 was examined. Data plotted in Figure 3.14. confirms poorer
performance in first 10 seconds of filter operation.

want1 and s igfilt1 differenc e


0.6

0.4

0.2
Relative A m plitude

-0.2

-0.4

-0.6

-0.8
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.14. Discrepancy between desired signal want1 and filtered signal sigfilt1

MATLAB code listed in Figure 3.15. was used to plot poles and zeros in the z-plane of
the digital filter obtained by numerical integration.
zzn=roots(b);
pzn=roots(a);
polar(0,1,' ')
hold
polar(atan2(imag(zzn),real(zzn)),abs(zzn),'o')
polar(atan2(imag(pzn),real(pzn)),abs(pzn),'*')
hold
Figure 3.15. MATLAB code for z-plane polar plot of digital filter poles and zeros.

Page 16.
Aleksandar Lazarevic Experiment E713.3

Running the above code, a plot as shown in Figure 3.16. was obtained.

P oles -Zero P lot of Digital Filter


120 60
0.8

0.6
150 30
0.4

0.2

210 330

240 300

Figure 3.16. Z-plane plot of digital filter poles and zeros.

3.5 S-plane to Z-plane mappings

In order to transfer function in the s-plane into the function in z-plane, MATLAB
bilinear() function was used. This function requires numerator and denominator
coefficients of the s-plane transfer function, as given previously in explanation with
Figure 3.3. Output of this bilinear transformation is a pair of z-plane transfer function
numerator and denominator coefficients. MATLAB code used for this mapping is given
in Figure 3.17.
const = (10/(2*pi));
num=[const 0 1];
den=[const 1 1];
[numz,denz]=bilinear(num,den,2);
zz=roots(numz);
pz=roots(denz);
polar(0,1,' ');
hold on
polar(atan2(imag(zz),real(zz)),abs(zz),'o')
polar(atan2(imag(pz),real(pz)),abs(pz),'*')
hold off
Figure 3.17. MATLAB code for bilinear s-plane to z-plane mapping.

Page 17.
Aleksandar Lazarevic Experiment E713.3

Poles and zeros of this z-plane transfer function were plotted on polar plot as shown in
Figure 3.18.
90 and z eros plot
P olar z -plane poles
1
120 60
0.8

0.6
150 30
0.4

0.2

180 0

210 330

240 300

270

Figure 3.18. z-plane Pole and Zero Plot obtained by Bilinear transformation.

By comparison with z-plane poles and zeros obtained previously with numerical
integration a small discrepancy was noted, although the filter performance was not
significantly affected.

3.6 Impulse Response of a Digital Filter

The unit sample response uniquely defines the performance of a digital filter. It was
obtained by applying a unit sample sequence defined as:
u[k]={1,0,0,…0,…}
to the filter input, thus exciting the filter while monitoring its output for effects of
“ringing”. In the following MATLAB code for obtaining the unit sample response, Figure
3.21, vectors a and b describing the digital filter were kept from the calculations shown in
Figure 3.11.
u=[1 zeros(1,127)];
impl=filter(b,a,u);
plot(t,impl,'.')
Figure 3.21. MATLAB Code for obtaining unit sample response of a digital filter.

Page 18.
Aleksandar Lazarevic Experiment E713.3

The unit sample response obtained was plotted as shown in Figure 3.22.

Im pulse Res pons e of Digital Filter


1.2

0.8
Relative A m plitude

0.6

0.4

0.2

-0.2
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.22. Unit sample response of a digital filter

3.7 Finite Impulse Response (FIR) and Infinite Impulse Response (IIR)
Filters

To confirm the theory explanation of FIR filters containing only moving average process,
MATLAB code in Figure 3.23. was run. Autoregression part of the difference equation
was set to one, keeping the original moving average part. As expected, the first three
samples of the impulse response matched the filter coefficients in vector b_ma.
a_ma=1;
b_ma=b;
maimp=filter(b_ma,a_ma,u);
maimp(1:5)
b_ma

ans =

10.1321 -19.2642 10.1321 0 0

b_ma =

10.1321 -19.2642 10.1321


Figure 3.23. MATLAB code and results showing FIR filter unit sample response.

Page 19.
Aleksandar Lazarevic Experiment E713.3

Contrary to the finite impulse response filters, MATLAB code in Figure 3.24. describes
an infinite impulse response filter. For this purpose, moving average filter coefficient
vector was set to one, while maintaining the original autoregression part of the difference
equation.
a_ar=a;
b_ar=1;
arimp=filter(b_ar,a_ar,u);
subplot(2,1,1),plot(t,arimp);
subplot(2,1,2),plot(arimp(110:128));
Figure 3.24. MATLAB Code plotting IIR filter unit sample response

Obtaining the plot for the above IIR filter, as shown in Figure 3.25, characteristic ringing
pattern was observed. Second subplot clearly shows that although the impulse response is
decaying and approaching zero, it does so in an asymptotical manner, and even after 128
samples still oscillates with very small amplitude of the order of 10-6.

IIR Filter Unit S am ple Response


0.3
Relative A m plitude

0.2

0.1

-0.1
0 10 20 30 40 50 60 70
Tim e /s
-6
x 10 IIR Res pons e A sy m ptotic ally A pproac hing Zero
10
S am ple V alue

-5
0 2 4 6 8 10 12 14 16 18 20
S am ple num ber 110-128

Figure 3.25. IIR Filter Unit Sample Response.

Page 20.
Aleksandar Lazarevic Experiment E713.3

3.8 Frequency Response of a Digital Filter

In order to assess the performance of the derived digital filter, it was necessary to plot its
frequency response. A deep notch was expected at the frequency of 0.1Hz in order to
eliminate unwanted oscillations from the original signal. It was chosen to use 128 points
located on the unity circle of |z| = 1. Required MATLAB code is shown in Figure 3.26.

f=(0:127)/(128*0.5);
digfr=freqz(b,a,128,'whole');
moddig=abs(digfr);
mod=abs(cfr);
angdig=angle(digfr)*180/pi;
ang=angle(cfr)*180/pi;
subplot(2,1,1),plot(f,moddig);
hold;
plot(f,mod,'r');
hold;
subplot(2,1,2),plot(f,angdig);
hold;
plot(f,ang,'r');
hold;
Figure 3.26. MATLAB Code for frequency response calculations of a digital filter.

Plots showing the frequency and phase responses of both analogue and digital filters were
obtained as shown in Figure 3.27. Using zoom command and closely examining the
frequency response plot, it was noted that the digital filter had slightly higher gain at the
frequencies above the desired notch at 0.1Hz. This gain difference was 0.5% - 0.6%
@1Hz.

Page 21.
Aleksandar Lazarevic Experiment E713.3

Frequenc y and P has e Res pons es of Digital and A nalog Filters


1

Relative A m plitude
0.8

0.6

0.4

0.2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

100
P has e /degrees

50

-50

-100
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequenc y /Hz

Figure 3.27. Frequency and Phase response of digital and analogue filters.

3.9 Designing a Digital Filter Using Yule-Walker Method

Using a more direct approach, a digital filter of a specified frequency response can be
designed without having to derive an analogue prototype. This can usually lead to a better
filter, since it is possible to choose the number of poles and zeros shaping the response
curve in order to give the best fit to the frequency response required. MATLAB code in
Figure 3.28. is using a modification of the Yule-Walker method, in order to design a
digital filter with the frequency response equivalent to the analogue filter previously
constructed in section 3.3. The range of frequencies is truncated to half the sampling
frequency, i.e. 1Hz, the rest of the frequency response being a mirror image to the basic
response.
f1=f(1:64);
fmax=f1(64);
fdes=f1/fmax;
filt=mod(1:64);
plot(f1,filt);
[bh,ah]=yulewalk(8,fdes,filt);
sh8=freqz(bh,ah,128,'whole');
subplot(2,1,1),plot(f,abs(sh8)),hold on;
plot(f,mod,'r'),hold off;
subplot(2,1,2),plot(f,angle(sh8)),hold on;
plot(f,angle(cfr),'r'),hold off;
Figure 3.28. MATLAB Code for Yule-Walker Method of Direct Digital Design.

Page 22.
Aleksandar Lazarevic Experiment E713.3

MATLAB code in Figure 3.28. used the polynomial function of the eight order, with
eight variable a and b coefficients made available for manipulation and fitting to the
desired response curve. As shown in Figure 3.29. this approach resulted in a significantly
worse filter that previously obtained by either analogue design or numerical integration
methods.

Frequenc y and P has e Res pons e Com paris on: A nalogue v. Y ule-W alk er Digital
1
Relative A m plitude

0.8

0.6

0.4

0.2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

100
P has e /degrees

50

-50

-100
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequenc y /Hz

Figure 3.29. Frequency and Phase Comparison of analogue and digital filter designs.

Roots of the filter coefficient vectors ah and bh represent poles and zeros of the transfer
functions respectively. In order to confirm the stability of the filter design, these were
plotted as shown in Figure 3.30.

Page 23.
Aleksandar Lazarevic Experiment E713.3

P oles and Zeros , 8th order polynom ial Y ule-W alk er Digital Filter

0.8

0.6

0.4
Im aginary part

0.2

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1
Real part

Figure 3.30. Bode plot of 8th order Yule-Walker Digital Filter.

Since all zeros and poles lie inside the unit circle, the obtained filter design is numerically
stable. MATLAB code in Figure 3.31. was used to compare the original signal signal1
with the output of two digital filters, one obtained by numerical integration and one by
Yule-Walker Method.
sigyule=filter(bh,ah,signal1);
subplot(3,1,1),plot(t,signal1)
subplot(3,1,2),plot(t,sigfilt1)
subplot(3,1,3),plot(t,sigyule)
figure
subplot(3,1,1),plot(f,ampl(fft(signal1)))
subplot(3,1,2),plot(f,ampl(fft(sigfilt1)))
subplot(3,1,3),plot(f,ampl(fft(sigyule)))
Figure 3.31. MATLAB code comparing performance of different filter designs.

Page 24.
Aleksandar Lazarevic Experiment E713.3

S ignal1 unfiltered
6

-2
0 10 20 30 40 50 60 70
Num eric al Integration Digital Filter
6
Relative A m plitude

-2
0 10 20 30 40 50 60 70
Y ule-W alk er 8th order Digital Filter
6

-2
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.32. Time domain representation of filtered signals.

Figures 32. and 33. clearly indicate superior performance of the digital filter obtained by
numerical integration. Frequency domain analysis show almost complete removal of the
0.1Hz component using this filter design.

Page 25.
Aleksandar Lazarevic Experiment E713.3

S ignal1 unfiltered
60

40

20

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Num eric al Integration Digital Filter
60

40

20

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Y ule-W alk er 8th order Digital Filter
60

40

20

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequency /Hz

Figure 3.33. Frequency domain representation of filtered signals.

3.10 Improving the design through clustering poles and zeros

A motivation behind this approach is to obtain better signal filtering by using a higher
order polynomials in the filter numerator and denominator. This could be implemented by
replacing a single pole or zero by multiple poles or zeros symmetrically placed around
the originals. MATLAB code shown in Figure 3.34. describes a filter with one double
zero and two poles positioned 3o each side of the original pole.
z1=(0.9511+0.3090i)
p1=0.95*(0.9336+0.3584i);
p2=0.95*(0.9659+0.2588i);
numz=poly([z1 z1 conj(z1) conj(z1)]);
denz=poly([p1 p2 conj(p1) conj(p2)]);
frz=freqz(numz,denz,128,'whole');
nnumz=numz/max(abs(frz));
nfrz=freqz(nnumz,denz,128,'whole');
subplot(2,1,1),plot(f,abs(nfrz))
subplot(2,1,2),plot(f,mod)
Figure 3.34. MATLAB code for two pole digital filter

Page 26.
Aleksandar Lazarevic Experiment E713.3

Two P ole Direct Digital Filter Design


1

0.8

0.6

0.4

0.2

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

LC Notc h A nalogue Filter Design


1

0.8

0.6

0.4

0.2
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequenc y /Hz

Figure 3.35. Analogue v. Two Pole Digital Filter Design

It was observed that the newly constructed digital filter has a narrower stop band than its
analogue prototype, as shown in Figure 3.35. Its 0.1Hz component attenuation was found
to be greater that the LC analogue filter, therefore eliminating more of the unwanted
signal. The existence of dual poles not completely cancelled by zeros introduced some
new spectral components around the notch frequency of 0.1Hz. This was clearly observed
in frequency domain plot of signal1 after being filtered using the new filter design
(Figure 3.36).

Page 27.
Aleksandar Lazarevic Experiment E713.3

S ignal1 filtered by two pole digital filter


50

40
S pec tral Density
30

20

10

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequenc y /Hz

6
Relative A m plitude

-2
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.36. Signal1 filtered by two pole digital filter.

3.11 Cascading Digital Filters

One of the advantages of digital filters is that they can be cascaded without the need for
buffering or impedance matching as it is the case with analogue filters. Digital filter
cascading is equivalent to squaring the required frequency response and applying a direct
digital design. MATLAB code shown in Figure 3.37. has been used to filter the original
signal using two cascaded digital filters. Previously defined and used filter coefficients
vectors a and b were squared on the term-by-term basis, and then used as numerator and
denominator vectors for filter design.
mod2=mod.*mod;
subplot(2,1,1),plot(f(1:64),mod(1:64),f(1:64),mod2(1:64),'r')
aa=a.*a;
bb=b.*b;
cas=filter(b,a,signal1);
subplot(2,1,2)
plot(f,ampl(fft(cas)));
Figure 3.37. MATLAB code for Cascaded Digital Filter.

The plots obtained are shown in Figure 3.38. It was confirmed that the notch at the
specified frequency has deepened, but that the stop band has widened. This is the
downside of digital filter cascading and in some applications can lead to unwanted signal
components being present in the output.

Page 28.
Aleksandar Lazarevic Experiment E713.3

Cas c ading Digital Filters


1

Relative A m plitude
0.8

0.6

0.4

0.2

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Frequenc y /Hz
Filtered S ignal S pectrum
50

40
S pectral Denis ty

30

20

10

0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Frequenc y /Hz

Figure 3.38. Cascaded Digital Filter Response.

3.12 Batch Filtering

Batch filtering method relies on the fact that better signal analysis and processing is
possible when the complete set of data has been collected, rather than processing it as it is
being retrieved. Consequently, batch filtering is limited to off-line filtering, and the filter
is considered anticasual. For this part of the experiment, signal2 was used as a primary
input to the filter. This signal is a simulation of a data that a sample and hold circuit could
output given the measurements from the satellite’s infra-red sensor. The ideally filtered
signal would be a linear ramp function of the form:
y(t)=ct
This ramp function is effectively a DC signal, having a double pole at s=0 in the s-plane
plot. Firstly, the spectrum of the input signal2 was calculated and plotted as in Figure
3.39.

Page 29.
Aleksandar Lazarevic Experiment E713.3

S ignal2 S pectrum
400

350

300

250
S pec tral Dens ity

200

150

100

50

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
Frequenc y /Hz

Figure 3.39. signal2 Spectrum before filtering.

MATLAB code shown in Figure 3.40. was used to model a batch filter with an entirely
real transfer function. The zero phase shift throughout the transfer function is a major
advantage of a batch filter. While this phase shift had to be tolerated with casual filters, it
is avoidable in the design of batch filters.
filt3=[mod2(1:6) zeros(1,117) mod2(6:-1:2)];
smoothft=sig2ft.*filt3;
sig2filt=abs(ifft(smoothft));
plot(t, sig2filt);
hold on
plot(t, signal2,'r');
hold off
Figure 3.40. MATLAB code for batch signal filtering.

Further, this filter model was used to filter signal2 trying to recover the wanted ramp
function. Both unfiltered and filtered waveforms were plotted and shown in Figure 3.41.
The performance of the filter was found to be at its best over the middle range of the data
set.

Page 30.
Aleksandar Lazarevic Experiment E713.3

B atc h filtering res ults of s ignal2


7

5
Relative A m plitude

-1
0 10 20 30 40 50 60 70
Tim e /s

Figure 3.41. Unfiltered and Filtered signal2 using a batch filter.

It was confirmed that the filter induces no phase shifting in the filtered signal due to its
purely real nature.

Page 31.
Aleksandar Lazarevic Experiment E713.3

4 Discussion
4.1 Analogue Filter Design

In the course of this experiment, MATLAB software package was used in facilitating the
design of an analogue notch filter. Although a simple LC notch filter could satisfy desired
frequency requirements, its practical construction would be next to impossible and
impractical. Values necessary to obtain satisfactory operation, values for capacitance and
inductance, are several orders of magnitude out of range for real system applications.
Sheer size of these components would render any attempt to construct such system void.
Nevertheless, a theoretical simulation of such analogue filter was performed, and good
attenuation at the notch frequency was obtained. Phase response of the analogue filter
varied severely with frequency, thus limiting the possible uses of this filter to applications
where phase of the output signal is not significant. The comparison of unfiltered versus
filtered signal showed worst performance nearer the beginning of filtering process
(t=1~10s). This is due to the ‘noise’ component overwhelming the desired infra-red
sensor output, which is at that point relatively small. More importantly, the peaks’
amplitude of the filtered signal is not increasing linearly. This could cause unwanted
behaviour from the actuators or jets controlling the satellites position relative to Earth.

4.2 Digital Filter Design

4.2.1 Design by Numerical Integration

An approximation of the analogue differential equation was obtained using a combined


forward and backward difference approximation yielding a central difference
approximation. This numerical approach resulted in two vectors containing the numerator
and denominator values for simulating a digital filter. As shown earlier in spectral
analysis in Figure 3.12. the unwanted 0.1Hz component has been reduced to a negligible
level. Poor performance of this digital filter in first ten seconds of operation is again due
to indistinguishably similar levels of noise and desired signal. Overall, the filter
performed well and provided for very linear increase in peaks’ amplitude over time, thus
enabling possible construction of a ramp function which would control desired satellite
motion. On the plot of filtered and unfiltered signal discrepancy, initial bad filter
performance is clearly reflected in the period t=0~10s. It was also confirmed using a
pole-zero plot that the filter is stable in operation.

4.2.2 Digital Filter Impulse Response

Important characteristic of the digital filter is its impulse response, which was tested by
applying a unit sample sequence as the input signal to the filter. Unit sample sequence
has set the filter ‘ringing’, a state in which the initial applied pulse decays over a period
of time in sinusoidal manner. Since no performance target regarding settling time was set
on the design of this filter, no further modifications were necessary.

Page 32.
Aleksandar Lazarevic Experiment E713.3

4.2.3 FIR and IIR Filters

The basic difference between finite impulse response and infinite impulse response filters
was observed. The significant of the autoregression and moving average term was
explored by altering filter nominator and denominator vectors. FIR filters are extensively
used in digital signal processing, and their design and uses are beyond the scope of this
experiment. Linearity of their phase and/or amplitude response, or constant phase shift of
90o can be very useful in certain applications for which analogue or IIR filters could not
be used. FIR filter transfer functions can contain only zeros and no poles, a task
impossible to accomplish in analogue filter design. Therefore, FIR filters are usually
synthesised directly in z domain, using computer packages like MATLAB.

4.2.4 Digital Filter Frequency Response

Due to the symmetry around the unity circle in z plane, frequency response of the digital
filter is symmetrical around half the sampling frequency. As seen from the Figure 3.27.
almost a perfect match was obtained for the digital filter up to the frequency of 1Hz, after
which the upper half of the frequency spectra is a mirror image of the lower part. This is
true for both frequency and phase response of the digital filter. Digital filter had only
slightly higher gain, which amounted to 0.5%-0.6% @1Hz.

4.2.5 Digital Filter Synthesis Using Yule-Walker Method

Seeking better and more effective filter designs, it is beneficial to relax some
requirements on the new designs. All of the previous digital filters correspond to a
realisable analogue filter. This requirement is quite unnecessary since for a certain
applications no analogue equivalent filter would ever be needed. One of the direct digital
filter design methods is Yule-Walker Method. Direct design is based on fitting the actual
frequency response to a desired frequency response, and can take in consideration phase
response as well, although MATLAB’s yulewalk() function does not map phase response.
The performance of an 8th order Yule-Walker filter was compared to a filter derived by
numerical integration. Although phase shifts were less severe using Yule-Walker filter,
its attenuation at 0.1Hz was much less, therefore its overall performance was inferior to
the numerically derived filter. This was confirmed on both time and frequency domain
plots. The function did however yield a numerically stable filter, since all of its poles and
zeros were contained within the unit circle.

4.2.6 Digital Filter with Clustered Poles and Zeros

In order to improve the filter characteristics it was necessary to use multiple poles and
zeros. By inspection of the pole-zero plots, it was concluded that filters have a zero at the
attenuation frequency, i.e. 0.1Hz. It was decided to use two zeros instead of one,
symmetrically offset by 3o at each side of the original zero. The filter was then

Page 33.
Aleksandar Lazarevic Experiment E713.3

normalized to have gain equal to one, and its frequency response was tested. Figure 3.35
clearly shows a significant improvement in attenuation at 0.1Hz and stop-band narrowing
compared to LC analogue filter. The unwanted effects accompanying this frequency
response improvements come from increasing the filter order. Although not tested, we
can expect ringing, rise, delay and settling time getting worse.

4.3 Cascading Digital Filters

While analogue filter cascading is complex task requiring impedance matching and/or
buffering, digital filter cascading is much simply done. Obviously improving the
attenuation at the notch frequency, modelled two stage cascaded digital filter had greatly
widened stop-band. While this can be tolerated for certain applications, it needs to be
taken into consideration at the design stage, and certain trade-offs regarding stop-band
range can be made, providing the filter stays within required specifications.

4.4 Batch Digital Filtering

Although used only in off-line filtering, batch filter tested performed well in
reconstructing a nearly linear ramp function in the middle of the supplied dataset.
Obviously, more data in the given time interval translates into better filtering. The basis
for this filter was the cascaded digital filter whose response functions had been modified
to have original values at the first six elements of the vector and six elements at mirror
image point around 2Hz. This is due to the ‘wrap-around’ effect so that these points had
to be included. Batch filter tested would not find any use in the satellite control systems,
since actions based on its output would always be out of date. More often batch filtering
is used in tracking slowly varying trends in economy, astronomy etc.

Page 34.
Aleksandar Lazarevic Experiment E713.3

5 Conclusions

• Although giving satisfactory performance, analogue filter implementations are not


always feasible due to component sizes and power consumption problems.
• Analogue to digital conversion using numerical integration resulted in a stable
filter with good frequency response and linearly increasing sequence of peaks was
recovered from the unfiltered signal.
• Digital filters must be constructed conforming to the design requirements,
including the unit sample response.
• Finite Impulse Response filters are extensively used due to their unique
advantages over IIR designs.
• Digital filter synthesised using Yule-Walker numerical method had less
attenuation at the notch frequency resulting in poor overall filter performance.
• The clustering of zeros and poles (two zeros were used) gave excellent results,
with almost total attenuation at the notch frequency.
• Increasing the order of the filter improves frequency response but degrades its
other important characteristics, such as ringing, rise, settle and delay time.
• Filter cascading is easily implemented using digital filters. Side effects of
frequency response improvements were significant stop-band widening.
• Batch filtering can give superior results, since the filter possess the entire data set
to be filtered. Nevertheless, it is significantly limited in use due to its off-line
processing nature.

Page 35.
Aleksandar Lazarevic Experiment E713.3

6 Nomenclature

Symbol Quantity SI Unit(s)


C Capacitance C
L Inductance H
R Resistance Ω
T Sampling time s
fs Sampling frequency s-1
wc Notch frequency rad⋅s-1
Ω0 Signal frequency component rad⋅s-1

Page 36.
Aleksandar Lazarevic Experiment E713.3

7 References

1
Jackson, Leland B., Digital Filters and signal processing: with MATLAB exercises,
Kluwer Academic Publishers, Boston, USA, 1995., page 156.
2
Jackson, Leland B., Digital Filters and signal processing: with MATLAB exercises,
Kluwer Academic Publishers, Boston, USA, 1995., page 33.
3
Popovic, Miodrag V., Digital Signal Processing: numerical exercises and MATLAB
examples, Nauka, Belgrade, Yugoslavia, 1996., page 131.
4
Popovic, Miodrag V., Digital Signal Processing: numerical exercises and MATLAB
examples, Nauka, Belgrade, Yugoslavia, 1996., page 121

Page 37.

You might also like