You are on page 1of 39

EEE6209

Advanced Signal Processing (ASP)


Dr Charith Abhayaratne
Topic 01 - Digital Filters :
Part I
Analogue vs. Digital
Filter basics
Time/Frequency domain parameters
A framework for filter design
Part II
Time/Frequency domain parameters
What makes a good filter?
Realising other filters from a LPF
Moving average filter
Reference
Proakis: Ch8.1

Tel: 25893
Email: c.abhayaratne@sheffield.ac.uk
Office: P/C11

MATLAB
Commands: filter, freqz, pz2tf, tf2pz, fft, plot, help, fir1, fir2, remez, firls
EEE6209

Digital filters are used for two general purposes:


(1) separation of signals that have been combined,
E.g., foetus heartbeat monitoring

(2) restoration of signals that have been distorted in


some way.
E.g., Denoising an image

Analogue vs. Digital filters


Advantages of Digital filters?
Disadvantages of digital filters?

EEE6209

x(n)

y(n)
Digital filter

y(n) T[ x(n)]

Both x(n) and y(n) are digital signals.


Usually a filter's input and output signals are in the time
domain. (Due to A to D conversion process sampling at
equal intervals of time)
The second most common way of sampling is at equal
intervals in space. E.g., imaging

EEE6209

Difference Equation
N

y(n) = ak y(n k ) + bk x(n k )


k =1

(1.1)

k =0

Convolution

y ( n) =

h( k ) x ( n k )

(1.2)

k =

Y ( z) = H ( z) X ( z)
b0 + b1 z 1 + ... + bM z M
H ( z) =
1 + a1 z 1 + ... + a N z N
EEE6209

(1.3)
(1.4)

The impulse response


The step response
The frequency response.
Each of these responses contains complete
information about the filter, but in a different
form.
If one of the three is specified, the other two
are fixed and can be directly calculated.
All three of these representations are
important, because they describe how the
filter will react under different circumstances.

EEE6209

The impulse response

y ( n) = h( k ) x ( n k )
k =

y (n) = h(n) when x(n) = (0)

The output when the input is an impulse

The step response


The output when the input is a step (also called an
edge, and an edge response)
It is the integral of the impulse response
Two ways to compute.
EEE6209

Frequency response
Denoted by H(j)
H ( j ) = H ( z ) z = e j

b0 + b1e j + ... + bM e jM
=
1 + a1e j + ... + a N e jN

Magnitude and Phase responses


H ( j ) = H ( j ) e j ( ) = H ( j ) H ( j )
H ( j ) = H ( j )
( ) = ( )

EEE6209

EEE6440

Exercise: 2.1
Consider the difference equation
y(n) = 0.5y(n-1) + x(n) x(n-2)

Find out
Impulse response
Step response
Frequency response

EEE6209

Filter Implementation
The most straightforward way to implement a
digital filter is by convolving the input signal with
the digital filter's impulse response.
All possible linear filters can be made in this
manner.
When the impulse response is used in this way,
filter designers give it a special name: the filter
kernel.
There is also another way to make digital filters,
called recursion.
EEE6209

10

When a filter is implemented by convolution, each


sample in the output is calculated by weighting the
samples in the input, and adding them together.
Recursive filters are an extension of this, using
previously calculated values from the output,
besides points from the input.
Instead of using a filter kernel, recursive filters are
defined by a set of recursion coefficients.
Remember, all linear filters have an impulse
response, even if you don't use it to implement the
filter.
EEE6209

11

To find the impulse response of a recursive filter,


simply feed in an impulse, and see what comes out.
The impulse responses of recursive filters are
composed of sinusoids that exponentially decay in
amplitude.
In principle, this makes their impulse responses
infinitely long. However, the amplitude eventually
drops below the round-off noise of the system, and
the remaining samples can be ignored.
Because of this characteristic, recursive filters are
also called Infinite Impulse Response or IIR filters.
In comparison, filters carried out by convolution are
called Finite Impulse Response or FIR filters.
EEE6209

12

IIR Filters
Duration length of h(n) is infinite. That means
h(n)0 when n.
IIR filters are recursive. That means at least one
coefficient ak0.
Causal IIR filters can be represented as

y(n) = h(k ) x(n k ) = ak y(n k ) + bk x(n k )


k =0

k =1

k =0

IIR filters have at least one nonzero finite pole


b0 + b1 z 1 + ... + bM z M b0 + b1 z 1 + ... + bM z M
H ( z) =
=
1
N
1 + a1 z + ... + a N z
1 p1 z 1 ... 1 + p N z N

EEE6209

)(

)
13

FIR Filters
Duration length of h(n) is finite. Length is M+1 <
. That means h(n)=0 when n.
FIR filters are non-recursive. That means all
coefficients ak=0 when k>0 and a0=1.
Causal FIR filters can be represented as
M

y(n) = h(k ) x(n k ) = bk x(n k )


k =0

k =0

FIR filters are all zero filters. That means all poles
are either 0 finite pole
H ( z ) = b0 + b1 z 1 + ... + bM z M
EEE6209

14

Information in signals
There are many ways that information can be contained
in a signal.
information represented in the time domain,
information represented in the frequency domain

Information represented in the time domain describes


when something occurs and what the amplitude of the
occurrence is.
Each sample contains information that is interpretable
without reference to any other sample. Even if you have
only one sample from this signal, you still know
something about what you are measuring.
This is the simplest way for information to be contained
in a signal.
The step response describes how information
represented in the time domain is being modified by the
system
EEE6209

15

Information in signals
In contrast, information represented in the frequency
domain is more indirect.
Many things in our universe show periodic motion.
By measuring the frequency, phase, and amplitude of
this periodic motion, information can often be
obtained about the system producing the motion.
A single sample, in itself, contains no information
about the periodic motion. The information is
contained in the relationship between many points in
the signal.
The frequency response shows how information
represented in the frequency domain is being
changed.
EEE6209

16

Filter parameters
Step response
Fast step response
No overshoot
Linear phase

Frequency response
Fast roll-off
Flat passband
Good stopband attenuation

Why step response and not the impulse response is


considered?
What about phase related parameters of the frequency
response?
EEE6209

17

EEE6209

18

Filter Classification
Four main types

Low pass
High pass
Band pass
Band reject

How to design a high pass filter if we know the impulse


response of the low pass FIR filter h(n)?

EEE6209

19

H(z)
1

There are two methods


Spectral inversion
Spectral reversal

fc

0.5

fc

0.5

G(z)
1

Spectral Inversion
If low pass filter is H(z)
0
0
The high pass filter G(z) = 1 H(z)
in time domain g(n) = (n) h(n)
Parallel filters
h(n)
+
x(n)

y(n)

(n)
EEE6209

20

Spectral reversal
If low pass filter is H(z)
The high pass filter G(z) = H(z+0.5)
in time domain g(n) = (1)n h(n)
H(z)
1

fc

0.5

0.5-fc 0.5

G(z)
1

EEE6209

21

Show how to use cascade and/or parallel LPF and/or HPF to


realise band-pass and band-reject filters.
LPF H(Z) with cut-off frequency f1
HPF G(z) with cut-off frequency f2
If f1 > f2
Band-pass filter is given by H(z) G(z) or h(n) * g(n) (cascaded filters)
Band reject by 1 H(z)G(z) (spectral inversion of band pass)

If f1 < f2
Band reject is give by parallel h(n) + g(n)

EEE6209

22

Draw the cascaded/parallel filtering system for Band pass and band reject filtering

EEE6209

23

The Moving average filter (MAF)


The moving average filter operates by averaging a number of
points from the input signal to produce each point in the
output signal.
1 M 1
y(i) = x(i + k )
M k =0

Example: Consider a 5-point MAF, i.e., M=5

What is the impulse response?


What is the step response?
Write a pseudo-code to implement it
What is the frequency response?

The main aim of the MAF is to remove the noise while


keeping sharp transitions intact
EEE6209

24

EEE6209

25

Noise reduction performance


Consider the signal below
MATLAB commands:
X=[zeros(1,200) ones(1,100) zeros(1,200)];
Y= X+ 0.2*randn(1,500); % original signal

What is the output (recovered X) when the following three


MAFs are used on Y.
M=5
M=11
M=25

Explain your observations using the step and frequency


responses of the above filters.
EEE6209

26

EEE6209

27

Frequency response of MAF


Mathematically described by the Fourier transform of the
rectangular pulse.
How to write the rectangular pulse ?
Frequency response?
H[ f ] =

sin(fM )
M sin(f )

An alternative way
zero pad the impulse response to make it a length N filter, where
N is a power of 2
Take the FFT
0 to N/2 points represent the Frequency response from 0 to 0.5 of
the normalised frequency.

EEE6209

28

The roll-off is very slow and the stopband attenuation is


ghastly. Clearly, the moving average filter cannot separate one
band of frequencies from another. (Good performance in the
time domain results in poor performance in the frequency
domain, and vice versa)
the moving average is an exceptionally good smoothing filter
(the action in the time domain), but an exceptionally bad lowpass filter (the action in the frequency domain).
EEE6209

29

Multiple pass MAF


Consider M=5 MAF and involve passing the input signal
through a moving average filter two or more times.
Find out the
Filter kernal (the impulse response)
Step response
Frequency response
For 1 pass, 2-pass and 3-pass MAF.

How is the noise removal performance for the (example in


slide 12)
For 2-pass MAF
For 3-pass MAF

EEE6209

30

Multiple pass MAF


Consider the output after the first stage
y1 = h*x
Second stage
y2 = h*y1
y2 = h*h*x
h2 = h*h
Third stage
y3 = h*y2
y3 = h*h2*x
h3 = h*h2

EEE6209

31

EEE6209

32

Multiple pass MAF

EEE6440

33

Multiple pass MAF


Two passes are equivalent to using a triangular filter
kernel (a rectangular filter kernel convolved with itself).
After four or more passes, the equivalent filter kernel looks
like a Gaussian.
As shown in (b), multiple passes produce an "s" shaped
step response, as compared to the straight line of the
single pass.
The frequency responses in (c) and (d) are given by the
equation in slide 14 multiplied by itself for each pass. That
is, each time domain convolution results in a multiplication
of the frequency spectra.
Why are the resulting filters from multiple passes better
than the MAF itself?
EEE6209

34

Recursive implementation of MAF


Consider a MAF with M=5
y[n] is computed as
y[n] = (x[n-2]+x[n-1]+x[n]+x[n+1]+x[n+2])/5

y[n+1] is computed as
y[n+1] = (x[n-1]+x[n]+x[n+1]+x[n+2]+x[n+3])/5
In other words,
y[n+1] = y[n]+(x[n+3]-x[n-2])/5

For any M, y[i] is computed as


y[i] = y[i-1]+(x[i+p]-x[i-q])/M
where p=(M-1)/2
q=p+1
EEE6209

35

Filters can be summarized by


Their use
1) In time domain
E.g. ?

2) In frequency domain
E.g. ?

3) Custom
E.g. ?

Their implementation
A) Convolution
B) Recursion

Examples for 1A, 1B, 2A, 2B, 3A, 3B ?

EEE6209

36

Recursive implementation of MAF


The equation in the previous slide uses two sources of

data to calculate each point in the output:


points from the input and
previously calculated points from the output.

This is called a recursive equation, meaning that the


result of one calculation is used in future calculations.
Be aware that the moving average recursive filter is
very different from typical recursive filters.
Is this an IIR or a FIR?
This algorithm is faster than other digital filters for
several reasons.
there are only two computations per point, regardless of the
length of the filter kernel.
addition and subtraction are the only math operations
needed (if division by M is omitted at the individual step and
performed at the end) --- Integer representation.
EEE6209

37

Custom filters
Most filters have one of the four standard frequency
responses: low-pass, high-pass, band-pass or band-reject.
But most of the time, we have to design digital filters with
an arbitrary frequency response, tailored to the needs of
our particular application.
Two important uses of custom filters:
Deconvolution - a way of restoring signals that have undergone an
unwanted convolution, and
Optimal filtering - the problem of separating signals with
overlapping frequency spectra. (lectures by WL)
EEE6209

38

Deconvolution
The detected signal is the
desired signal convolved with an
unwanted kernel.
How do we recover the desired
signal back?

If the exact frequency response


of the desired signal not known
how can we get the desired signal
back? (blind deconvolution from WL lectures)
EEE6209

39

You might also like