You are on page 1of 31

Filtering Problem

Goal: design a filter to attenuate the disturbances

SIGNAL

s[n]

x[n] Filter

v[n]
NOISE

y[n] s[n]

Define Signal and Noise in the Frequency Domain

n
SIGNAL

v[n] NOISE
s[n]

Filter

n
y[n] s[n]

x[n]

SIGNAL
NOISE

| S ( ) |

| V ( ) |
P

Mostly NOISE

Mostly
SIGNAL

(rad )
Mostly NOISE

IDEAL Filter
Since the filter has real coefficients, we need only the
positive frequencies

H ( )

PASS
Band

p STOP
Band

Non-IDEAL Filter
Since the filter has real coefficients, we need only the
positive frequencies
| H ( ) |

PASS
Band

Trans.
Band

STOP
Band

Design a Low Pass Filter: IDEAL


Hd ( )
1

P P

First we can determine an infinite length expansion using


the DTFT:
H d () DTFT hd [n]

j n
h
[
n
]
e
d

1
hd [n] IDTFT H d ()
2
1
hd [ n]
2

j n

j n
H
(

)
e
d
d

sin P n P
P
d

sinc
n
n

Design a Low Pass Filter: IDEAL (continued)


hd [n]

This means the following. If


then

H d ()

j n
h
[
n
]
e
d

hd [n]

Hd ( )

P

sinc P n

P P

0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05
-0.1
-60

-40

-20

20

40

60

From IDEAL to FIR


Notice that

lim hd [n] 0

Then we can approximate with a finite sum

H d ()

j n
h
[
n
]
e
d

n L

and choose the filter as h[n] hd [n L]


2L

H () h[n]e

j n

n 0

actual

2L

hd [n L]e
n 0

j n

hd [n]e

n L

j n

e jL H d ( )e jL

desired

Summary of design of Low Pass FIR


Given the Pass Band Frequency 0 P
The impulse response of the filter: let N 2 L

P
P

h[n]
sinc
(n L) , n 0,..., N

2L

H () h[n]e jn H d ( )e jL
n 0

Magnitude and Phase:


Magnitude:
Phase:

H ( ) H d ( )
H ( ) H d ( ) L
L in the passband

Example of Freq. Response


P / 4

h=(wp/pi)*sinc((wp/pi)*(n-L));

freqz(h)

Magnitude (dB)

50
0

20dB

-50
-100

0.1

0
Phase (degrees)

n=0:N;

L 20, N 40

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

0.9

20

-500
-1000
-1500

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

Impulse Response
n=0:N;
stem(n,h)
h[n]

0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05
-0.1

10

15

20

25

30

35

40

Example with Hamming window


1
1

h[n] sinc ( n 20)


4
4

2n
0.54 0.46 cos
, n 0,...,40
40

hamming window
n=0:N;
h0=(wp/pi)*sinc((wp/pi)*(n-L));
h=h0.*hamming(N);
stem(n,h)

h[n]
0.3
0.25
0.2
0.15
0.1
0.05
0
-0.05

10

15

20

25

30

35

40

Example with Hamming window


1
1

h[n] sinc ( n 20)


4
4

2n
0.54 0.46 cos
, n 0,...,40
40

hamming window

Magnitude (dB)

50
0

~ 50dB

-50
-100
-150

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

0
Phase (degrees)

freqz(h)

H ( )

-500
-1000
-1500

Low Pass Filter Design: Analytical


Transition Region: depends on the window and the filter length N
Attenuation: depends on window only
20

window

Rectangular

4 / N

Hamming

8-43dB
/N

Blackman

12 / N

attenuation
-13dB

0
-20

attenuation

-40
-60

-58dB

-80
-100
-120

0.5

P S

1.5

2.5

transition region

Example of Low Pass Filter Design


Specs: Pass Band 0 - 4 kHz
Stop Band

> 5kHz with attenuation of at least 40dB

Sampling Frequency 20kHz

40dB

Step 1: translate specifications into digital frequency


Pass Band

02 4 / 20 2 / 5rad

Stop Band

2 5 / 20 / 2 rad

Step 2: from pass band, determine ideal filter impulse


response

hd (n)

P
2
2n
sinc P n sinc

5
5

4 5
2
5 2


10

F kHz

10

Example of Low Pass Filter Design (continued)

Step 3: from desired attenuation choose the window. In this case we can choose the
hamming window;
Step 4: from the transition region choose the length N of the impulse response.
Choose an even number N such that:

N 10

So choose N=80 which yields the shift L=40.

Example of Low Pass Filter Design (continued)


Finally the impulse response of the filter

2
2(n - 40)
2 n
0.54 0.46 cos

sinc

80
5
h ( n) 5

, if 0 n 80,

otherwise

Example of Low Pass Filter Design (continued)


The Frequency Response of the Filter:

H( )
dB

H( )
rad

Design Parameters
Pass Band Frequency
Stop Band Frequency
Pass Band Ripple
Stop Band Attenuation

p rad.
S rad.
20 log10 A / B dB
20 log10 A / C dB

H ( )
A
B

Computer Aided Design of FIR Filters


Best Design tool for FIR Filters: the Equiripple algorithm. It
minimizes the maximum error between the frequency
responses of the ideal and actual filter.
Step 1: define the desired filter with pairs of frequencies and
values. For a Low Pass Filter:
PASS

f 2 STOP

f 1

f=[0,f1,f2,1];

where

A=[1,1,0,0];
Linear Interpolation

1
0

PASS

STOP

(rad )

Computer Aided Design of FIR Filters


Step 2: Choose filter length N from desired attenuation as

Attenuation (dB)
N~
11 STOP PASS /
Step 3: call firpm (pm = Parks, McClellan)
h=firpm(N,f,A);
which yields the desired impulse response

h h[0], h[1] h[ N ]

Example: Low Pass Filter


Passband: 3kHz
Stopband: 3.5kHz
Attenuation: 60dB
Sampling Freq: 15 kHz
Then compute:

3,000 2

15,000 5
3,500 7
STOP 2

15,000 15
60
N
82
7
2
11 15 5

PASS 2

h=firpm(82,[0,2/5,7/15,1],[1,1,0,0]);

Frequency Response
freqz(h)

Magnitude (dB)

50
0

50dB, not quite


yet!

-50
-100

Increase N.
0

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

Phase (degrees)

0
-1000
-2000
-3000
-4000

Increase Filter Length N


h=firpm(95,[0,2/5,7/15,1],[1,1,0,0]);
freqz(h)
Magnitude (dB)

50
0
-50
-100

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

Phase (degrees)

0
-1000
-2000
-3000
-4000

Impulse Response of Example


stem(h)
0.6
0.5
0.4
0.3
0.2
0.1
0
-0.1

10

20

30

40

50

60

70

80

90

100

Typical Applications
In applications such as Radar, Sonar or Digital Communications we transmit a
Pulse or a sequence of pulses.
For example, we transmit a short sinusoidal burst:

x(t ) A sin( 2F0t ), 0 t T1


2

F0 500 Hz

1.5
1

T1 8 m sec

0.5
0
-0.5
-1
-1.5
-2

4
sec

8
-3

x 10

Typical Applications
For example in a communications signal we send 0 and 1.
For example let:

1 x(t )
0 x(t )
4

Transmitted:

3
2
1
0
-1
-2
-3
-4

1
0

0.005

0.01

1
0.015
millisec

0.02

0
0.025

0.03

Received Signal with Noise


Suppose you receive the signal with 0dB SNR:

8
6
4
2
0
-2
-4
-6
-8

0.005

0.01

0.015
millisec

0.02

0.025

0.03

DTFT of Signal
Magnitude of the DFT of the Pulse (in dB):

dB

50
40
30
20
10
0
-10
-20
-30
-40
-50

1000

2000

3000

4000

5000

6000

7000

8000

9000

Hz

DTFT of Signal
Bandwidth of the Signal (take about -20dB from max) is about 1.0kHz

50
40

~ 20dB

30
20
10
0
-10
-20
-30
-40
-50

1000

2000

3000

4000

5000

6000

7000

8000

9000

Design the Low Pass Filter


Pass 0 to 1kHz;
Stop 1.5kHz to 10.0kHz

N=81

Magnitude (dB)

Attenuation 40dB

0
-50
-100

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

0.1

0.2

0.3
0.4
0.5
0.6
0.7
0.8
Normalized Frequency ( rad/sample)

0.9

0
Phase (degrees)

Sampling Freq 20.0kHz

50

-500
-1000
-1500

Filtered Data

10
5

Received signal:

0
-5
-10

10

15

millisec

20

25

30

35

4
2

and Filtered:

0
-2
-4

10

15

20
millisec

25

30

35

4
3

Compare to
the original:

2
1
0
-1
-2
-3
-4

0.005

0.01

0.015
millisec

0.02

0.025

0.03

40

You might also like