### FIR filters

```FIR Filters
FIR filters have transfer functions of the following
form:
H ( z)  b0  b1z 1   bm z m.
The impulse response is
h[n]  b0 [n]  b1 [n 1]   bm [n  m].
This impulse response function is finite in duration.
Such filters are referred to as finite impulse
response or FIR filters.
Any filter whose transfer function does not have a
denominator will have an impulse response that is
finite in duration.
There are no (realizable) analog filters with a finite
impulse response, or (stable) analog filters whose
transfer function does not have a denominator.
So why bother with FIR filters?
FIR filters do have one interesting property: unlike
IIR filters, they can have linear phase response.
w
H(ejw)
Example: Find the phase response of
1
H ( z)  (1  z ).
1
2
Solution: We let z=ejw, and find the angle of the
complex value.
jw
H (e )  (1  e
1
2
 jw
).
H(ejw)
w
ejw
0
1
1
2
(1  1)
0°
j
1
2
(1  j )
-45°
-1
1
2
(1 1)
-90°
p/2
p
H(ejw)
*
*The phase must be evaluated as a limit here.
Frequency Response
0.25
jw
 H(e ), x p
0
-0.25
-0.5
-0.75
0
0.25
0.5
w, x p
0.75
1
Frequency Response
0.25
jw
 H(e ), x p
0
-0.25
-0.5
-0.75
0
0.25
0.5
w, x p
0.75
1
FIR filters do not always have linear phase. As an
example,
1
H ( z)   z .
1
2
jw
H (e )   e
1
2
 jw
.
H(ejw)
w
ejw
0
1
1
2
1
0°
j
1
2
j
-63°
-1
1
2
1
-180°
p/2
p
H(ejw)
Frequency Response
0.25
j
 H(e w), x p
0
-0.25
-0.5
-0.75
-1
-1.25
0
0.25
0.5
w, x p
0.75
1
Now, let us find the criteria for an FIR filter to have
linear phase.
Suppose the FIR filter was of the simple form
H ( z)  b0  b1z 1.
H (e jw )  b0  b1e jw .
If b0 = b1 = b, we have
H (e jw )  b  be jw
 b(1  e
 jw
)
 be jw / 2 (e jw / 2  e  jw / 2 )
 jw / 2
 2be
cos w2 .
The phase response of this filter is
jw
H (e )  
which is in fact linear.
w
2
,
If b0 = -b1 = b, we have
H (e jw )  b  be jw
 b(1  e
 jw
)
 be jw / 2 (e jw / 2  e  jw / 2 )
 jw / 2
 2 jbe
sin w2 .
The phase response is
jw
H (e )  
w
2

p
2
As it turns out, as long as the coefficients are
symmetric (even or odd), the phase will be linear.
The following are examples of linear-phase FIR
filters:
1
H ( z)  1  z .
1
H ( z)  1  z .
1
2
3
H ( z)  1  z  z  z .
1
2
3
1
2
3
H ( z)  1  z  z  z .
H ( z)  1  z  z  z .
1
2
2
3
3
H ( z)  1  2z  2z  z .
1
4
5
H ( z)  1  2z  3z  3z  2z  z .
1
2
3
4
1
2
3
4
H ( z)  1  2z  3z  2z  z .
H ( z)  1  2z  3z  2z  z .
Exercise: For each of the previous examples, find
the (linear) relationship of phase to frequency
H(ejw).
Linear Phase and Group
Velocity
What is so special about linear phase?
Let f(w) be the phase response of a filter. Without
loss of generality, let us assume that the filter has
constant magnitude response.
jw
H (e )  e
jf (w )
.
Suppose we pass a sinewave
x1 (t )  cosw1t
through this filter. The corresponding output would
be
y1 (t )  cos(w1t  f (w1 )).
Suppose we pass another sinewave
x2 (t )  cosw2t
through this filter. The corresponding output would
be
y2 (t )  cos(w2t  f (w2 )).
Now suppose we pass the sum of the sinewaves
x(t )  x1 (t )  x2 (t )
through this filter. The corresponding output would
be
y(t )  y1 (t )  y2 (t )
 cos(w1t  f (w1 ))  cos(w2t  f (w2 )).
Now if the phase response is linear, i.e.,
f (w )   w,
then the output would be
y (t )  y1 (t )  y2 (t )
 cos(w1t  w1 )  cos(w 2t  w2 )
 cos(w1[t   ])  cos(w 2 [t   ])
 x1 (t   )  x2 (t   ).
The filter effectively shifts different frequencies by
the same amount in time. If the filter shifted the
frequencies by different amounts in time (as it would
with non-linear phase), then the signals would be
delayed by different amounts and would not be
aligned at the output of the filter. Such a nonaligned result is called dispersion.
The derivative of the phase response is called the
group velocity. For linear phase, the group velocity
is constant (-).
Design of FIR Filters
Since there are no analog filters with a finite-duration
impulse response, FIR filters can not be patterned
after analog filters—new, original design techniques
have to be developed.
The first design technique is the Fourier Series
Method.
The second design technique is the Minimum MeanSquare Error Technique.
The Fourier Series Method
Suppose we wished to design a filter with a desired
frequency response, Hd(ejw). A typical example
would be the following:
Hd(ejw)
wc
wc
w
Let us take a periodic extension (in frequency
domain) of this function:
…
…
2p
2p
We could represent this periodic extension by a
Fourier series (in frequency domain).
w
The “period” would be 2p, and the fundamental
“frequency” would be 2p/2p1.
jw
H d (e ) 

c e
n  
n
jnw
,
where
1
cn 
2p
p
p

H d (w )e  jnw dw .
We can readily construct the z-transform transfer
function of this filter:
H d ( z) 

c z .
n
n  
n
Thus, the coefficients cn turn out to be nearly the FIR
filter coefficients bn.
Example: Suppose the cutoff frequency of our
desired filter is wc=p/2. Find the coefficients of an
FIR filter.
Solution: We calculate the filter coefficients as
follows:
1
cn 
2p
1

2p
p
p H

p /2
p
 /2
d
(w )e
(1)e
 jnw
 jnw
dw
dw
1 1
 jnw p / 2

e
p / 2
2p ( jn)
1 1
 jnp / 2
 jnp / 2

e
e
2p ( jn)
1
np
 sin
.
pn
2


For a practical filter the summation in the Fourier
series cannot be infinite: we must truncate the
Fourier series to n=-r to r (where r is a finite integer):
H ( z) 
r
c
n r
n
n
z .
For r=5, the transfer function for our wc=p/2 filter is
as follows:
H ( z) 
5
n
c
z
 n
n  5
 c5 z 5  c4 z 4  c3 z 3  c2 z 2  c1 z1
 c0 z 0  c1 z 1  c 2 z  2  c3 z 3  c 4 z  4  c5 z 5

1 5 1 3 1 1 1 1 1 1 3 1 5
z 
z  z   z 
z 
z
5p
3p
p
2 p
3p
5p
Plots of the frequency response, for various values
of r, are shown on the following slide.
Frequency Response
2
1.5
1
jw
|H(e )|
r = 20
r = 50
r=5
0.5
0
-0.5
-1
-0.5
0
w, x p
0.5
1
While the frequency response improves for higher
orders, you will notice that there is always “rippling”
at the transition (even for higher orders). This
“rippling” is called Gibbs phenomenon. This
“rippling” can be decreased by the application of
windows.
A window is a filter which decreases the ripples.
The window is applied in time-domain: the filter
coefficients cn are weighted by factors wn which
achieve an extra filtering function.
The resultant windowed filter has transfer function
H ( z) 
r
w c
n r
n n
n
z .
We have several types of windows: Hamming, vonHann, or “Hanning,” Blackman, Kaiser. Such filters
are available through MATLAB via commands like
>> win = hamming(2*r+1);
We can then multiply each of the coefficients by
these Hamming coefficients:
>> c = c.*win’;
The resultant filter coefficients cn will yield a filter
with decreased “rippling” at the transition. The
frequency plots for the previous filter with a
Hamming window applied are shown on the
following slide.
Frequency Response
2
1.5
1
jw
|H(e )|
r = 20
r = 50
r=5
0.5
0
-0.5
-1
-0.5
0
w, x p
0.5
1
The “rippling” is greatly reduced, but the steepness
of the frequency rolloff is decreased.
One last problem,
H ( z) 
r
c
n r
n
z
n
is non-realizable: the impulse response has negative
terms and the system is non-causal. The system
basically responds r samples before the input is
applied. We fix this problem by delaying the
impulse response by r samples.
Our equivalent causal (realizable) filter (with delay)
transfer function is
H ( z)  z
'
r
r
c
n r
2r
n
z
n

r
c
n r
n
z
( n  r )
  cnr z .
n
n 0
Thus, h[n] = c-n-r, and the order of the filter is 2r.
In our previous example for r=5, and wc=p/2 our nonrealizable filter was
H ( z) 
1 5 1 3 1 1 1 1 1 1 3 1 5
z 
z  z   z 
z 
z
5p
3p
p
2 p
3p
5p
The corresponding realizable filter is
H ' ( z) 
1
1  2 1  4 1 5 1 6 1 8 1 10

z  z  z  z 
z 
z
5p 3p
p
2
p
3p
5p
```