Transcript 7-FIR
Ideal Filters
One of the reasons why we design a filter is to remove disturbances
SIGNAL
s(n)
x(n)
Filter
y(n) s(n)
v(n)
NOISE
We discriminate between signal and noise in terms of the frequency spectrum
Y (F )
S (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 )
IDEAL
FILTER
2
2
1.5
1.5
1
1
0.5
0.5
0
0
-0.5
-0.5
-1
-1
-1.5
-1.5
-2
Same shape as s(t),
just scaled and
delayed.
0
200
400
600
800
-2
1000
0
200
400
600
800
1000
Consequence on the Frequency Response:
constant
| H (F ) |
F
linear
H (F )
F
Ae j 2FT
H (F )
0
if F is in the passband
otherwise
For real time implementation we also want the filter to be causal, ie.
h( n)
n
h(n) 0 for n 0
since
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
1 2
log H ( ) log( 0)
cannot be ideal.
2
log H ( ) d
1
Characteristics of Non Ideal Digital Filters
| H ( ) |
p
IDEAL
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) b1x(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)
h(n) 0
n
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 () DTFThd (n)
h (n)e
n
1
hd (n) IDTFTH d ( )
2
j n
d
j n
H
(
)
e
d
d
Example: Ideal Low Pass Filter
1
hd (n)
2
c
Ae j n d A
c
sin c n
A c sinc c
n
hd (n)
Hd ( )
DTFT
A
c
c
n
c
n
4
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(n) 0
h( n)
H( )
H( ) 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.
hw (n)
rectangular window
We do this by
2
0.25
1.8
0.2
a) Windowing
1.6
0.15
1.4
1.2
1
hd (n)
0.8
0.25
0.6
0.1
0.05
0
0.4
0.2
-0.05
0.2
0.15
0.1
0.05
0
-100
-50
L
0
50
-0.1
-100
100
L
-0.05
-50
0
50
100
1.8
100
50
100
L
0.2
1.6
infinite impulse response
(ideal)
50
0.25
2
-0.1
-100
L
0
hw (n)
hamming window
0
-50
1.4
1.2
1
0.8
0.15
0.1
0.05
0.6
0
0.4
-0.05
0.2
0
-100
-50
L
0
50
L
100
-0.1
-100
-50
L
0
L
finite impulse response
b) Shifting in time, to make it causal:
h(n) hw (n L)
hw (n)
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
-100
-50
0
50
100
-0.1
-100
-50
0
50
100
Effects of windowing and shifting on the frequency response of the filter:
a) Windowing: since
hw (n) hd (n)w(n)
| W ( ) |
then H w ( )
1
H d ( ) *W ( )
2
| H w ( ) |
rectangular window
40
20
20
0
0
-20
H d ( )
*
-40
-60
-100
-120
0
0.5
1
1.5
2
2.5
3
0
0.5
1
1.5
2
2.5
3
0
0.5
1
1.5
2
2.5
3
hamming window
40
20
20
0
0
*
-60
-80
-120
c
-40
-80
-100
c
-20
-20
-40
-60
-40
-60
-80
-80
-100
-100
-120
-20
0
0.5
1
1.5
2
2.5
3
-120
For different windows we have different values of the transition region and the attenuation in the
stopband:
attenuatio n
20
Rectangular
4 / N
-13dB
Bartlett
8 / N
0
-27dB
-20
Hanning
8 / N
-32dB
-40
Hamming
8 / N
-43dB
-60
Blackman
16 / N
-58dB
-80
attenuation
-100
hw (n)
-120
N 2L 1
with
0
0.5
1
0.25
transition
region
0.2
0.15
0.1
0.05
0
-0.05
-0.1
-100
-50
L
0
50
L
100
n
1.5
2
2.5
3
Effect of windowing and shifting on the frequency response:
b) shifting: since
Therefore
h(n) hw (n L)
then
H ( ) H w ( )e jL
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
H w ( )
real for all
.
h
n
hw (n) hw (n).
Then
j n
(
n
)
e
hw (0) 2 hw (n) cos( n)
w
n 1
Then
in thepassband;
0
H w ( )
don' t care, otherwise
The phase of FIR low pass filter:
H ( ) L in thepassband;
Which shows that it is a Linear Phase Filter.
20
0
-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
40dB
Step 1: translate specifications into digital frequency
Pass Band
Stop Band
0 2 4 / 20 2 / 5 rad
2 5 / 20 / 2 rad
Step 2: from pass band, determine ideal filter impulse
response
c
c 2
2n
hd (n)
sinc
n sinc
5
5
4 5
2
5 2
10
10
F kHz
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
0.54 0.46 cos
, if 0 n 80,
sinc
80
5
h( n) 5
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
5
0.5
10
0
0
20
40
60
80
100
120
n
There are some empirical formulas:
A
Attenuation in dB
Transition Region in rad
N
Example:
Sampling Freq. 20 kHz
Pass Band 4 kHz
2
P
,
5
S
Stop Band 5kHz, with 40dB Attenuation
S P
A 40dB
10
rad
N 45
3.3953
2
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
with
9
c P S
20
1
2
N 45 2 L 1 L 22
h[n]
Impulse Response
n
| 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 )
if
F 5kHz
0
• Sampling Frequency Fs 20kHz
• Attenuation in the stopband at least 50dB.
Solution.
Step 1. Convert to digital frequency
H d ( ) H d ( F ) F F / 2
s
2
2
jFs j 20,000 if - 5 5
0
if
| |
2
Step 2: determine ideal impulse response
hd (n) IDTFTH d ( )
1
2
From integration tables or integrating by parts we obtain
2
5
2
5
j 20,000 e j n d
ax
e
1
ax
xe
dx
x
a
a
Therefore
2n
2n
cos
sin
4
5
5
2
if n 0
20,000
hd (n)
5
n
n2
if n 0
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
which yields
2
2
12
0.1
5
N
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
4
5
5
2
0.42 0.5 cos 2n 0.08cos 4n
h(n) 20,000
5
n 60
(n 60) 2
120
120
for 0 n 120
Frequency Response
H ( )
2
x 10
5
1.8
1.6
Impulse response h(n)
3
x 10
1.4
1.2
4
1
0.8
2
0.6
0.4
1
0.2
0
0
0
0.5
1
1.5
2
2.5
3
3
3.5
-1
-2
-3
0
20
40
60
80
100
120
140
H ( ) dB
150
100
50
0
-50
-100
-150
-200
-250
0
0.5
1
1.5
2
2.5