Lecture 05: Design of Non-Recursive Digital Filters: John Chiverton

You might also like

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

Lecture 05: Design of Non-recursive Digital

Filters

John Chiverton

School of Information Technology


Mae Fah Luang University

1st Semester 2009/ 2552


Lecture Contents

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
What is a Digital Filter?

Any digital system can be described as a digital filter. The word


“filter” means to remove a part of a signal and allow another part
to pass through.
The verb “to filter” is used in many areas of English language.
Examples
I The water filter cleans the water for drinking.
I The cook filtered the bad fruit from the good for cooking
later.
I The air conditioning filters dust from the air.
What is a Digital Filter?
Often used to remove some frequencies from a signal X(Ω) and to
allow other frequencies to pass through to the output Y (Ω).
|H ( Ω) |

( Ω)
Low Pass

t, Y
tpu
Ou
Low Frequencies π Ω
|H ( Ω) |

e
nt S r Tim
em
yst
a
Band Pass

Inv ), Line
aria
H(Ω
Middle Frequencies π Ω
|H ( Ω) |

)
X(Ω
High Pass

ut,
Inp
π Ω
High Frequencies
Non-recursive digital filters

Linear Time
Input, x[n] Output, y[n]
Invariant System

What is a non-recursive digital filter?


I “Recursive” comes from the word “to recur”
Meaning: to repeat
A recursive filter uses past output values (y[n − i]) for the current
output y[n]:
I Recursive Filter Example

y[n] = 0.5y[n − 1] + 0.5x[n].

A non-recursive filter only uses input values x[n − i]:


I Non-recursive Filter Example

y[n] = 0.5x[n − 1] + 0.5x[n].


Generalised Non-Recursive Difference Equation

Recall the generalised difference equation for causal LTI systems


(see Lecture 02):
N
X N
X
ak y[n − k] = bk x[n − k]
k=0 k=0

So a non-recursive digital filter in a causal LTI system is given by:


N
X
y[n] = bk x[n − k]
k=0
Non-Recursive Digital Filters

Non-recursive digital filters are often known as


I Finite Impulse Response (FIR) Filters
as a non-recursive digital filter has a finite number of coefficients
in the impulse response h[n].
Recursive digital filters are often known as
I Infinite Impulse Response (IIR) Filters
as the impulse response of an IIR filter has an infinite number of
coefficients.
FIR Filters
I Have linear phase characteristics (i.e. no phase distortion);
I But they typically require a higher number of computations.
Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Moving Average Filters
I Moving average filters are usually implemented non-recursively.
I Moving average filters are interesting as they
I Are useful for some applications
I But the frequency response is not ideal
 1
k
if −k/2 ≤ n ≤ k/2
h[n] = ; where k is odd.
0 otherwise
Example 
0.2 if −2 ≤ n ≤ 2
h[n] = .
0 otherwise
Moving Average Frequency Responses
k=3 k=5

k=7 k=9
Moving Average Frequency Responses
k=11 k=13

k=15 k=17
Moving Average Frequency Responses and the Sinc
Function

k=19 sinc function

The frequency response tends to a Sinc function defined as:


1
h[n] = sinc(n) = sin(n).
n
Moving Average and Ideal Frequency Responses (Low
Pass)
Moving average (k = 7) frequency response (blue) and ideal low
psas frequency response (magenta).

The moving average frequency response is not ideal. The ripples


allow many other frequencies to pass through the filter.
Moving Average and Ideal Frequency Responses (Low
Pass)
Ideal low pass frequency response only.

The ideal low pass frequency response is perfect, stopping all


unwanted frequencies. But it is rarely achievable.
Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Ideal Frequency Response Time Domain Representation
What is the time domain representation for the ideal low pass
frequency response?
Recall the inverse Fourier Transform is given by:
Z
1
x[n] = X(Ω) exp(jΩπ)dΩ. (1)
2π 2π

So for an impulse response h[n]:


Z
1
h[n] = H(Ω) exp(jΩπ)dΩ; (2)
2π 2π

or sometimes simpler to use



1
h[n] = H(Ω) exp(jΩπ)dΩ; (3)

−π

which is possible due to periodicity.


Ideal Frequency Response Time Domain Representation
The ideal low pass frequency response is given by:

1 for −Ω1 ≤ Ω ≤ Ω1 ,
H(Ω) = (4)
0 otherwise.

This equation states that any frequency Ω between −Ω1 and +Ω1 can pass
without attenuation (H(Ω) = 1). All other frequencies are stopped altogether.
The time domain representation of (4) is given by
0 −Ω
ZΩ1
1
Zπ Z 1 Zπ
1 1 @
h[n] = H(Ω) exp(jΩπ)dΩ = 0dΩ + 1 × exp(jΩπ)dΩ + 0dΩA
2π 2π
−π −π −Ω1 Ω1
» –Ω1 ! » –Ω1
1 exp(jΩn) 1 exp(jΩn)
= [0]−Ω 1
−π + + [0]πΩ1 =
2π jn −Ω1 2π jn −Ω1
1 1 1
= (exp(jΩ1 n) − exp(−jΩ1 n)) = 2j sin(Ω1 n) = sin(Ω1 n)
2πjn 2πjn πn
Ω1
= sinc(nΩ1 )
π
sin(nΩ1 )
where sinc(nΩ1 ) = nΩ1
is known as the sinc function.
Ideal Low Pass Frequency Response Time Domain
Representation

Example
Q. What is the time domain
impulse response for an ideal
low pass frequency response
filter with Ω1 = π/2?
A.
π  π 1  nπ 
h[n] = sinc n = sinc
2π 2 2 2
2 1  nπ 
= sin
nπ 2 2
1  nπ 
= sin .
nπ 2
Ideal Low Pass Frequency Response Time Domain
Representation

Example
Q. What is the time domain
impulse response for an ideal
low pass frequency response
filter with Ω1 = π/2?
A.
π  π 1  nπ 
h[n] = sinc n = sinc
2π 2 2 2
2 1  nπ 
= sin
nπ 2 2
1  nπ 
= sin .
nπ 2
h[n] is sampled at discrete
values of n.
Sinc Function
I The Sinc function is the Fourier transform of a square wave or impulse response.

Time Domain Frequency Domain

F

Fourier

F −1

Inverse
Fourier

I The Sinc function is also the inverse Fourier transform of a square wave.
Ideal Frequency Response Time Domain Representation
A Problem!
The Sinc function continues forever.

Therefore the time domain representation has to be stopped early.


Ideal Frequency Response Time Domain Representation

A Problem!
The Sinc function continues forever.

Therefore the time domain representation has to be stopped early.


Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
How to Stop the Sinc function early?

A window can be used...

... to limit the impulse response.


How to Stop the Sinc function early?

We can use a relatively big


window...
How to Stop the Sinc function early?

We can use a medium sized


window...
How to Stop the Sinc function early?

Or we can use a relatively


small window...
How to Stop the Sinc function early?

The window here w[n] is rectangular and constant, i.e.

(
1 for − window2 width ≤ n ≤ window2 width
w[n] =
0 every where else

usually known as a rectangular window.


The sinc function filter coefficients are multiplied by this window
(in the time domain):

h2 [n] = h[n] × w[n].

So that
(
h[n] for − window2 width ≤ n ≤ window2 width ,
h2 [n] =
0 every where else.
How to Stop the Sinc function early?

(
h[n] for − window2 width ≤ n ≤ window2 width ,
h2 [n] =
0 every where else.
Problem with A Rectangular Window!

HOWEVER! The frequency response of this window is not ideal.

Rectangular pulse in time domain = sinc function in frequency


domain:
Time Domain Frequency Domain

F

Fourier

I The original ideal low pass filter in the frequency domain is


corrupted by the windowing1 .
1
Windowing describes multiplication by the window function.
Problem with A Rectangular Window!

Time Domain Frequency Domain


Convolution ⇐⇒ Multiplication
x[n] ∗ y[n] X(Ω) × Y (Ω)
Multiplication ⇐⇒ Convolution
x[n] × y[n] X(Ω) ∗ Y (Ω)

Time domain multiplication of w[n] with h[n] is the same as


convolution in the frequency domain, i.e.

F(w[n] × h[n]) = W (Ω) ∗ H(Ω).


Time domain Frequency Domain
w[n] ⇐⇒ W (Ω)
h[n] ⇐⇒ H(Ω)
h2 [n] ⇐⇒ H2 (Ω)

H2 (Ω) = F(h2 (n)) = W (Ω) ∗ H(Ω).


Frequency Domain Effect of (Rectangular) Windowing
Ideal Low Pass Filter
Ideal Time Domain Filter Rectangular Window (Time)

=
Time Domain Frequency Response (Mag)

F

Frequency Domain Effect of (Rectangular) Windowing
Ideal Low Pass Filter
Big Window Smaller Window

Even Smaller Window Very Small Window


Frequency Domain Effect of (Rectangular) Windowing
Ideal Low Pass Filter Log - to emphasise the side lobes
Big Window Smaller Window

Even Smaller Window Very Small Window


Gibbs Ringing or Truncation Artifact

Gibbs artifact = truncation artifact.

Bumps around sudden changes in signal.


Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Filter Parameters

A filter can be described by a number of parameters.

1.2

1+ δ p
1.0
δp
1−δ p I δp : pass band ripple
0.8

I δs : stop band ripple


0.6

I Pass Band (little


0.4
attenuation)
0.2 I Transition width
δs
δs I Stop Band (highest
0.0
0 0.2 0.4 0.6 0.8 1 1.2 1.4
Ω p Ωs frequency attenuation)
Pass Band Stop Band
Widtion
th
i
ns
Tra
Filter Parameters

A filter can be described by a number of parameters.

1.2
I δp = 0.12
1+ δ p
1.0
δp I δs = 0.08
1−δ p ∴ Gain at end of pass band
0.8

is 1 − δp = 0.88.
0.6 Gain and attenuation in
decibels (dB):
0.4

gaindB = 20 log( gain ).


0.2

δs So Gain at end of pass band


δs
0.0
0 0.2 0.4 0.6 0.8 1 1.2 1.4
Ω p Ωs frequency 20 log(1 − δp ) = −1.11dB.
Pass Band Stop Band
Widtion

Gain at end of stop band is


th
i
ns

1 − δs = 0.08 or -21.94dB.
Tra
Filter Parameters

A filter can be described by a number of parameters.


I δp = 0.12
1.2

1+ δ p I δs = 0.08
1.0
δp
Pass band frequencies:
1−δ p
0.8
Ω = 0 to Ωp
0.6
where Ωp = 0.43 radians.
0.4
Transition width:

0.2
Ω = Ωp to Ωs =
δs
δs 0.43 to 0.56 radians.
0.0
0 0.2 0.4 0.6 0.8 1 1.2 1.4
Ω p Ωs frequency Stop band starts at:
Pass Band Stop Band
Widtion
th

Ω = Ωs = 0.56 radians.
i
ns
Tra
Filter Bandwidth
Filter bandwidth defined by:
“Range of frequencies the filter gain is greater than -3dB”.

1.2

As
1.0

gaindB = 20 log( gain ).


0.8

Then 0.708
0.6
„ «
gaindB
20
gain = 10 . 0.4

So for 0.2

gaindB = −3dB then


gain = 0.708. 0.0
0 0.2 0.4 0.6 0.8 1 1.2 1.4
frequency
Filter Ω cf
Bandwidth
I The cut-off frequency Ωcf corresponds to when the gain falls
below -3dB.
Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Other Window Types for Truncation (Other than
Rectangle)

Other types of window functions can be used to truncate the ideal


time domain response:

Window Name Equation


(N +1)−|n|
Bartlett/ triangular w[n] = (N +1)2 “
for |n| ≤ (N − 1)/2

Hamming w[n] = 0.54 + 0.46 cos N2πn−1
for |n| ≤ (N − 1)/2
“ ”
2πn
Hanning w[n] = 0.5 + 0.5 cos N −1 for |n| ≤ (N − 1)/2
r !
“ ”2
1 2n
Kaiser w[n] = I0 (α) I0 α 1 − N −1 − 1 for |n| ≤ (N − 1)/2.

Others include Blackman, Lanczos and Tukey windows.


Example Frequency Responses with Different Windows

Each window is slightly different in the time domain.


Example Frequency Responses with Different Windows
Windowed truncation of a filter ideal frequency response.

I Each window type has different properties.


I e.g. Stop band attenuation for Blackman is highest but Blackman has
long transition width.
Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Steps for FIR Low Pass Filter Design

1. Find the cut-off digital frequency, Ωcf


1.1 It may be given directly,
I e.g. Ωcf = π/4 radians
1.2 Or the sampling frequency and cut off frequencies may be given instead,
calculated from Ω = 2πf /fs ,
I e.g. fs = 100kHz and fcf = 12.5kHz, so that
Ωcf = 2π12500/100000 = π/4 radians.
2. Calculate the appropriate sinc function for ideal low pass filter:

Ω1
h[n] = sinc(nΩ1 )
π

where Ω1 = Ωcf is the cut-off frequency.


3. Select a window with appropriate parameters. e.g. short transition width or high
stop band attenuation.
4. Calculate non-causal time domain impulse response from h2 [n] = w[n] × h[n].
5. Shift the impulse response to make a causal version h3 [n] = h2 [n − (N − 1)/2].
Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Band Pass FIR Filter Design
Low pass filter H(Ω) can be converted to a bandpass filter by:
I Convolution in frequency domain with delta function δΩ ;
0
I At centre frequency Ω0 .

Frequency Domain Time Domain


(Convolution ) (Multiplication)
H(Ω) ∗ δΩ0 ⇐⇒ h[n] × cos(nΩ0 )
|H ( Ω) |

Band Pass


−Ωcf Ωcf π
Ω0
Band Pass FIR Filter Design

Low pass filter H(Ω) can be converted to a bandpass filter by:


I Convolution in frequency domain with delta function δΩ0 ;
I At centre frequency Ω0 .
The resulting band pass impulse response h0 [n]
I with bandwidth 2 × Ωcf ,
I using window function w[n],
I and centre frequency Ω0
is given by

h0 [n] = h[n] × w[n] × cos(nΩ0 )


Ωcf
= sinc(nΩcf ) × w[n] × cos(nΩ0 ).
π
High Pass FIR Filter
High pass filter can be achieved by
I Shifting the impulse response to Ω0 = π,
I Via multiplication by cos(nΩ0 ) = cos(nπ).
I This is the limit of the unique part of the digital spectrum.
|H ( Ω) |

Low Pass

Low Frequencies π Ω
|H ( Ω) |

High Pass

Ωcf Ωcf π− Ωcf Ω0=π π+ Ωcf Ω


Ω=0

High Frequencies
High Pass FIR Filter

High pass filter can be achieved by


I Shifting the impulse response to Ω0 = π,
I Via multiplication by cos(nΩ0 ) = cos(nπ).
I This is the limit of the unique part of the digital spectrum.
|H ( Ω) |

High Frequencies

High Pass


π− Ωcf Ω0=π π+ Ωcf
High Pass FIR Filter

High pass filter can be achieved by


I Shifting the impulse response to Ω0 = π,
I Via multiplication by cos(nΩ0 ) = cos(nπ).
I This is the limit of the unique part of the digital spectrum.
The resulting high pass impulse response h0 [n]
I with bandwidth Ωcf ,
I using window function w[n],
is given by

h0 [n] = h[n] × w[n] × cos(nπ)


Ωcf
= sinc(nΩcf ) × w[n] × cos(nπ).
π
Other Topics in Filter Design

Band stop is another type of filter,


I Created from a combination of high and low pass filters.
Digital differentiators are common in DSP applications,
I To differentiate a signal, to calculate e.g. speed.
Other techniques for FIR filter design include:
I Equiripple filters
I Optimization of passband and stopband ripples.
I Frequency sampling method
I Optimization from specified (sampled) frequency response.
Other factors to consider
I Phase response of the filter, not just the magnitude.
I e.g. Hilbert transformer places a 90o phase shift on a signal.
Outline

Introduction

Moving Average Filters

Ideal Frequency Response

Windowing

Filter Parameters

Alternative Windows for Truncation

Filter Design

High Pass and Band Pass FIR Filters

Summary
Summary

Today’s lecture has covered:


I Moving average filters (and their frequency response)
I Ideal frequency response of FIR filters
I Windowing techniques
I Filter parameters
I Filter design techniques for
I low pass,
I band pass
I and high pass FIR filters

You might also like