Sunteți pe pagina 1din 26

Ideal Filters

One of the reasons why we design a filter is to remove disturbances

SIGNAL s (n) x(n) y ( n)  s ( n)


 Filter

v (n)
NOISE
We discriminate between signal and noise in terms of the frequency spectrum

S (F ) Y (F )

V (F )

 F0 F0 F
F0  F0 F0 F
Conditions for Non-Distortion
Problem: ideally we do not want the filter to distort the signal we want to recover.

x(t )  s (t ) y (t )  As(t  T )
Same shape as s(t),
IDEAL just scaled and
2 FILTER 2
delayed.
1.5
1.5

1 1

0.5 0.5

0 0

-0.5 -0.5

-1 -1

-1.5 -1.5

-2 -2
0 200 400 600 800 1000 0 200 400 600 800 1000

Consequence on the Frequency Response:

constant | H (F ) |
 Ae j 2FT if F is in the passband
H (F )  
F 0 otherwise
linear
 H (F )

F
For real time implementation we also want the filter to be causal, ie.

h( n)

 h(n)  0 for n  0
  
  since
  
  n 
y (n)   h(k )
x 
(nk)
k 0
past values only

FACT (Bad News!): by the Paley-Wiener Theorem, if h(n) is causal and with finite energy,



 ln H ( ) d   

ie H ( ) cannot be zero on an interval, therefore it cannot be ideal.

2

1  2
log H ( )  log( 0)     log H ( ) d  
1
Characteristics of Non Ideal Digital Filters

| H ( ) | IDEAL

p  Positive freq. only

NON IDEAL
Two Classes of Digital Filters:
a) Finite Impulse Response (FIR), non recursive, of the form

y (n)  h(0) x(n)  h(1) x(n  1)  ...  h( N ) x(n  N )


With N being the order of the filter.
Advantages: always stable, the phase can be made exactly linear, we can approximate any
filter we want;
Disadvantages: we need a lot of coefficients (N large) for good performance;

b) Infinite Impulse Response (IIR), recursive, of the form

y(n)  a1 y(n  1)  ...  aN y(n  N )  b0 x(n)  b1 x(n  1)  ...  bN x(n  N )

Advantages: very selective with a few coefficients;


Disadvantages: non necessarily stable, non linear phase.
Finite Impulse Response (FIR) Filters

Definition: a filter whose impulse response has finite duration.

x(n) y(n)
h( n)

h( n)

 
 
               
  n

h( n)  0 h( n)  0
Problem: Given a desired Frequency Response Hd ( ) of the filter, determine the impulse
response h(n) .

Recall: we relate the Frequency Response and the Impulse Response by the DTFT:


H d ( )  DTFT hd (n)   h ( n)ed
 j n

n  


hd (n)  IDTFT H d () 
1
 d
j n
H ( )e d
2 

Example: Ideal Low Pass Filter

sin c n 
c
1   
hd (n) 
2 
 Ae j n d  A
n
 A c sinc  c
  
n

c

hd (n)
Hd ( )
DTFT
A

 c
 4
   c  c 
n
Notice two facts:
• the filter is not causal, i.e. the impulse response h(n) is non zero for n<0;

• the impulse response has infinite duration.

This is not just a coincidence. In general the following can be shown:

If a filter is causal then

• the frequency response cannot be zero on an interval;


H( )
H( )  0
h( n)
h( n)  0




 

• magnitude and phase are not independent, i.e. they cannot be specified arbitrarily

As a consequence: an ideal filter cannot be causal.


Problem: we want to determine a causal Finite Impulse Response (FIR) approximation of the
ideal filter.
rectangular window hw (n)
We do this by 2 0.25

1.8
0.2
a) Windowing 1.6

1.4 0.15


1.2
0.1
1
hd (n) 0.8 0.05

0.25 0.6
0
0.4
0.2
0.2 -0.05

0.15 0


-100 -50 0 50 100 -0.1

L
-100 -50 0 50 100
L L
0.1

0.05
L
0
hamming window hw (n)
-0.05
2
0.25
-0.1
-100 -50 0 50 100 1.8
0.2
1.6


1.4 0.15
infinite impulse response 1.2
0.1
(ideal) 1

0.8 0.05

0.6
0
0.4

0.2 -0.05
0
-100 -50 0 50 100 -0.1

L
-100 -50 0 50 100

L L L

finite impulse response


b) Shifting in time, to make it causal:

hw (n) h(n)  hw (n  L)
0.25
0.25

0.2
0.2

0.15 0.15

0.1 0.1

0.05 0.05

0 0

-0.05 -0.05

-0.1 -0.1
-100 -50 0 50 100 -100 -50 0 50 100
Effects of windowing and shifting on the frequency response of the filter:
1
a) Windowing: since hw (n)  hd (n)w(n) then H w ( )  H d ( ) *W ( )
2
| W ( ) | rectangular window | H w ( ) |
40 20

20 0

0
-20


-20
-40
-40

H d ( )
* -60

-80
-60

-80

-100
-100

-120
-120 0 0.5 1 1.5 2 2.5 3
0 0.5 1 1.5 2 2.5 3

 c c  40
hamming window
20

20
0


0
-20
-20

* -40

-60
-40

-60

-80
-80

-100 -100

-120 -120
0 0.5 1 1.5 2 2.5 3 0 0.5 1 1.5 2 2.5 3
For different windows we have different values of the transition region and the attenuation in the
stopband:
 attenuatio n
20

Rectangular 4 / N -13dB 0

Bartlett 8 / N -27dB -20

8 / N attenuation
Hanning -32dB -40

Hamming 8 / N -43dB -60

16 / N
-80
Blackman -58dB
-100

-120
with N  2L  1 0 0.5 1 1.5 2 2.5 3

hw (n) 0.25

0.2

0.15
transition
0.1 region
0.05

-0.05

-0.1
-100 -50 0 50 100

n
L L
Effect of windowing and shifting on the frequency response:
b) shifting: since h(n)  hw (n  L) then H ( )  H w ( )e  jL
Therefore
H ( )  H w ( ) no effect on the magnitude,
 H( )   H w ( )  L shift in phase.

See what is  H w ( ).

For a Low Pass Filter we can verify the symmetry hw (n)  hw (n). Then
 
H w ( )  h
n  
w ( n )e  j n
 hw (0)  2 hw (n) cos( n)
n 1

real for all . Then


0 in the passband;
 H w ( )  
don' t care, otherwise
The phase of FIR low pass filter:

 H ( )  L in the passband;


Which shows that it is a Linear Phase Filter. 20

-20

H ( ) -40

-60
dB
-80

-100

-120
0 0.5 1 1.5 2 2.5 3


 H ( )
degrees

don’t care
Example of Design of an FIR filter using Windows:
Specs: Pass Band 0 - 4 kHz
Stop Band > 5kHz with attenuation of at least 40dB
Sampling Frequency 20kHz

Step 1: translate specifications into digital frequency  40dB


Pass Band 0  2 4 / 20  2 / 5 rad
4 5 10 F kHz
2 
Stop Band 2 5 / 20   / 2   rad  
5 2


Step 2: from pass band, determine ideal filter impulse  
10
response

c  c  2  2n 
hd (n)  sinc n  sinc 
    5  5
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 odd
number N such that:
8 

N 10

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

Finally the impulse response of the filter

2  2(n - 40)    2 n  
 sinc   0.54  0.46 cos   , if 0  n  80,
h( n)   5  5   80  

 0 otherwise
The Frequency Response of the Filter:

H( )

dB


 H( )

rad


A Parametrized Window: the Kaiser Window

The Kaiser window has two parameters:

N Window Length

 To control attenuation in the Stop Band

1.5

w[n]  0
1

 1

0.5
 5
  10
0
0 20 40 60 80 100 120
n
There are some empirical formulas:

Attenuation in dB A  N
  
Transition Region in rad    

Example:

2 

Sampling Freq. 20 kHz
P  , S 
Pass Band 4 kHz 5 2
Stop Band 5kHz, with 40dB Attenuation

 N  45
   S   P 

rad
10
A  40dB   3.3953
Then we determine the Kaiser window

w  kaiser ( N ,  )

w[n]

n
Then the impulse response of the FIR filter becomes

sin  c (n  L) 
h[n]  w[n]
 ( n  L)
 
ideal impulse
response

9
with  c   P   S  
1
2
20

N  45  2L 1  L  22
h[n ]

Impulse Response

| H ( ) |dB

Frequency Response

 (rad)
Example: design a digital filter which approximates a differentiator.
Specifications:
• Desired Frequency Response:
 j 2 F if  4kHz  F  4kHz
H d (F )  
0 if F  5kHz

• Sampling Frequency Fs  20kHz


• Attenuation in the stopband at least 50dB.
Solution.
Step 1. Convert to digital frequency

 2 2
 jFs  j 20,000 if - 5    5
H d ( )  H d ( F ) F F / 2 
s
0 
 if |  | 
2
Step 2: determine ideal impulse response
2
5
hd (n)  IDTFT H d ( ) 
1
2 
2
j 20,000  e j n d

5
 1
ax
e
    
ax
From integration tables or integrating by parts we obtain xe dx x
a a
Therefore
   2n   2n  
  cos   sin  
20,000 4  5  2  5   if n  0
hd (n)    5 n n 2 
  
 

0 if n  0
Step 3. From the given attenuation we use the Blackman window. This window has a transition
region region of 12 / N . From the given transition region we solve for the complexity N as
follows
 2 12
    0.1 
2 5 N

which yields N  120. Choose it odd as, for example, N=121, ie. L=60.

Step 4. Finally the result

  2 (n  60)   2 (n  60)  
 cos  sin  
   2     0.42  0.5 cos 2n   0.08 cos 4n  
h(n)  20,000
4 5 5
   
 5 n  60 (n  60) 2    120   120 
 
 

for 0  n  120
Frequency Response
5
x 10

H ( )
2

1.8

1.6

Impulse response h(n) 1.4

4
1.2
x 10
3 1

0.8
2
0.6

1 0.4

0.2
0 0


0 0.5 1 1.5 2 2.5 3

-1

-2

-3
0 20 40 60 80 100 120 140 150

H ( ) dB 100

50

-50

-100

-150

-200


-250
0 0.5 1 1.5 2 2.5 3 3.5

S-ar putea să vă placă și