Sie sind auf Seite 1von 9

# 7

6
MHH606312 Digital Signal Processing

4
5

## The goal of filtering is to perform frequency-dependent alteration of a signal. A simple

design specification for a filter might be to remove noise above a certain cutoff frequency.
Within this laboratory you will explore FIR within Matlab.

7
Digital filters with finite-duration impulse reponse (referred to as FIR filters)
have both
8
response (IIR)
9
filters. (Note: You will need sg01 for some of the functions in this Lab.).
10
11
FIR filters have the following primary advantages:
12
They can have exactly linear phase.
They are always stable, even when quantized.
The design methods are generally linear.
They can be realized effciently in hardware.
The filter startup transients have finite duration.
13
14
The primary disadvantage of FIR filters is that they often require a much
higher filter order
15
than IIR filters to achieve a given level of performance. Correspondingly, the
delay of these
16
filters is often much greater than for an equal performance IIR filter.
17

18
19

FIR Methods

20
The Signal Processing Toolbox supports a variety of methods for the design of
FIR filters.
21
22
Question: Using an appropriate search list the methods available in
Matlab for designing FIR filters.
23

24
25

Impulse Response

26

## FIR filters are described by difference equations of the form

27

y ( n )= x ( m ) h (nm)

28

m=0

(1)
29
8

G Morison
page 1

## MHH606312 Digital Signal Processing

30
where the filtered signal y(n) is just a linear combination of current and
previous values of
31
the input signal x(n). The coeffcients b (b(m)) are the numerator coeffcients
of the transfer
32
function. The denominator of the transfer function will always be a = 1. The
order of the
33
filter is n = length(b) -1.
34
35
Question: Explain how to calculate the impulse response of the
above filter.
36
37

38
(1).
39
40
41
42

Try this in Matlab. Let b represent the coeffcients of the x's in equation

44

## b = [-1 0 2 -3 1]; % no need to specify the a coefficients

stem(b)
figure, impz(b,1)

43

45
46
A filter whose impulse response is symmetric or antisymmetriac about its
midpoint is called
47
a (generalized) linear phase filter. That is,
48
49
h ( n ) H ( e jn )= H ( e jn ) e j()
(2)
50
with
51
( ) =K
(3)
52
The phase shift of the altered signal ( ) will vary linearly with frequency
. (This translates
53
into the fact that the output signal of such a filter has a pure time delay
with respect to the
54
input signal. There is no phase distortion).
The phase delay ( ) / and the group delay d ( ) /d will be equal
and constant
55
56
Except for cfirpm, all the FIR filter design functions in the Signal
Processing Toolbox design linear phase filters only.
57
58
Try this is Matlab
59

60
61
62

a = 1;
b = fir1(5,0.5);
fvtool(b,a)

63
64
This is the classic method of windowed FIR linear-phase filter design. Look at
the phase delay and the group delay in fvtool.
10

G Morison
page 2

65
66
67
68

## Question: Explain the functionality of the fir1 Matlab function.

Question: For this (5th order) 6-point filter, confirm that the phase
( ) 2.4868 as
69
seen in the phase plot of fvtool.
70

71

## FIR Filter Types

72
73
The symmetric impulse response of a linear phase filter can have an odd or
an even number
74
of points,and can have an odd or even symmetry about the midpoint, leading
to four filter
75
types:
76
Type I: Odd length, even symmetry
Type II: Even length, even symmetry
Type III: Odd length, odd symmetry
Type IV: Even length, odd symmetry
77
78
Question: Describe any restrictions that can occur when using each
of the above types of FIR filter.

G Morison
page 3

79

## Window Based Design

80
81
Under FIR Methods above, Windowing is the first filter design method. It is the
common,
82
classic design method for FIR filters.
83
84
Recall that the frequency response H ( e jn ) is periodic. Hence it can be
written as a Fourier series.
85
That is ,
86

H (e jn )=

87

h[n]e jn

n=

(4)
88
h[n] are the Fourier coefficients that are determined using the inverse
89
DTFT. In general, the
90
impulse response cannot be implemented as a digital filter because it is
infinite and non91
causal.
92
93
Question: Show using the Inverse DTFT that the ideal frequency
response of a low pass filter, cannot be implemented, and explain why this
is the case.
94
95
So, h[n] is symmetrically truncated (multiplied by a finite, symmetric
window) and shifted
96
to make it causal, to create an implementation that gives a linear phase finite
impulse response.
97
98
(Recall that from Fourier series properties, if the function is even, the Fourier
coefficients
99
are even and if the function is odd, Fourier coefficients are odd. Hence for
jn
H (e ) even, like
100 for a low pass filter, h[n] will be even, i.e. symmetric.)
101
102 The truncated Fourier series can be shown to be an approximation to the ideal
filter, which
103 is best" in a mean square sense, compared to other approximations of the
same length.
104 However, the abrupt truncation leads to overshoot (Gibb's phenomenon) and
ripples in the
105 spectrum. The undesirable effects of truncation can be reduced or eliminated
by the use of
106 tapered windows.
107
108 Question: Describe what is meant by the Gibbs phenomenon.
109
110 The Windowing method does not allow you to design a filter, with explicit
amplitude response

G Morison
page 4

111
used
112
113
114
115
116

117
118
119
120

121
122

## constraints, such as passband ripple or stopband attenuation. It needs to be

iteratively and we stop when design specifications are met.
Using the file windemo.m from GCU Learn
Try this is Matlab
edit windemo
windemo(20)
windemo(50)
windemo(100)

## Question: What do the arguments (20, 50, 100) specify?

123
124 Question: How does the filter frequency response change with
increasing the size of
125 the filter?
126
127 Question: Even as you increase the number of filter
coefficients that you retain, does
128 the largest overshoot in the magnitude frequency response
decrease in size?
129
130 Question: Explain what is happening in the 4 figures that you
see in windemo.
131

## 132 Windowing Functions

133

134 In windemo you saw the effects (Gibbs phenomena) on the frequency
response of the finite
135 length filter when a (default) rectangular window was imposed. Now we see
methods of
136 ridding ourselves of Gibbs phenomena - at a price.
137
138 The Signal Processing Toolbox supports a variety of windows commonly used
in FIR filter
139 design. (We will see this in class.) Typing
140
141
142

help window

## 143 provides a list of the available windows:

144
145 Individual window functions take inputs for a window length n and window
parameters and
146 return the window w in a column vector of length n. (Note: Use w' for array
products with
147 row vector impulse responses.) The window function serves as a gateway to
the individual
148 functions.
149
2

G Morison
page 5

150
151

## MHH606312 Digital Signal Processing

alpha=0.25
w = gausswin(64,alpha)

152
153
154

and

155

w = window(@gausswin,64,alpha)

156
157 both return a Gaussian window of length 64 with standard deviation equal to
1/alpha.
158
159 Question: Pick two of the available windows and discuss and
demonstrate their properties.
160

## 161 Windowing and Spectra

162
163 As we saw above, when a signal is truncated in time, high-frequency
components are in164 troduced in frequency that are visible in the DFT spectrum. By
windowing the truncated
165 signal in the time domain, endpoints are assigned a reduced weight.
The effect of this on
166 the DFT is to reduce the height of the side lobes in the spectrum, but
increase the width of
167 the main lobe. (That is the penalty we pay). Here is a simple
demonstration:
168
169

170
171

## Using the file windft.m from GCU Learn

Try this is Matlab

172
173 edit windft
174 windft
175
176 You see a truncated signal (5 hz sine wave) and its DFT (Recall the
Fourier transform of a sine wave? Do you see how the DFT is different?) Then,
the truncated sine wave is multiplied by a Gaussian window and the DFT is
taken of the truncated windowed signal.

177
178 Question: Detail and explain the output of the above function.
179
180 Question: For a continuous-time sine wave, its Fourier transform are
a couple of delta functions. For a discrete-time truncated sine wave, how
is its spectrum (DFT) different to the idealized delta function spectrum of a
(continuous-time) sine wave?
181
182 Question: How does windowing the truncated sine wave "improve"
the DFT spectrum.
183
184 Note: You have a 5 hertz sine wave.
185
2

G Morison
page 6

## MHH606312 Digital Signal Processing

186
If you edit windft you see that you are just looking at it for 1 second. So you
see 5 cycles of it in 1 second. Hence you are taking a sine wave, infinitely long, and
putting a 1 second rectangular window on it. In the analog domain you have,
187
x w ( t )=sin ( 2 5 t ) . w R (t)
188
(5)
189
190 where w R (t ) is a 1 second rectangular window.
191
192 Question: Calculate the Fourier transform of the signal x w ( t ) .
193
194 Question: Compare the results of the Fourier transform with the
Matlab output from the DFT of the signal.
195

## 196 Window Visualisation Tool

197
198 To window" a filter, the filter impulse response h(n) of size N is multiplied by
a window
199 of size N. The transition bandwidth of a window-based FIR filter is determined,
by the width of the main lobe of the DFT of the window function. The main lobe
width, as you can observe, can be adjusted by changing size of N. Passband and
stopband ripples are determined by the magnitude of the side lobe of the DFT of the
window function, and are usually not adjustable by changing the _lter order.
200
201 Ideally, the spectrum of a window should approximate an impulse. The main
lobe should be
202 as narrow as possible and the side lobes should contain as little energy as
possible.
203 The Window Visualization Tool (WVTool) allows you to investigate the tradeoffs
among
204 different windows and filter orders.
205

206

wvtool(windowname(n))

214
215
216

wvtool(hamming(64),hann(64),gausswin(64),rectwin(64))
wvtool(hamming(32),kaiser(32,2.5),flattopwin(32))
wvtool(kaiser(32,1),kaiser(32,5),kaiser(32,10))

207
208 opens WVTool with time and frequency domain plots of the n-length window
specified in
209 windowname, which can be any window in the Signal Processing Toolbox.
Several windows
210 can be given as input arguments for comparative display.
211
212 Try the following in Matlab
213

217
218 Question: Comment on the differences - main lobe width and ripples
- between the
219 same size rectangular window and the Hamming window.
220
2

G Morison
page 7

## 221 Window Design and Analysis Tool

222
223 The Window Design and Analysis Tool (WinTool) is used in conjunction with the
Window
224 Visualization Tool.
225
Use WVTool for displaying and comparing existing windows created in the
Matlab workspace.
Use WinTool to interactively design windows with certain speci_cations and
export them
226 to the Matlab workspace.
227
228 Most window types satisfy some optimality criterion. Some windows are
combinations of simpler windows. For example, the Hann window is the sum of a
rectangular and a cosine window, and the Bartlett window is the convolution of two
rectangular windows. Other windows emphasize certain desirable features. The
Hann window improves high-frequency decay (at the expense of larger peaks in the
side lobes). The Hamming window minimizes side lobe peaks (at the expense of
slower high-frequency decay). The Kaiser window has a parameter that can be
tuned to control side lobe levels. Other windows are based on simple mathematical
formulas for easy application. The Hann window is easy to use as a convolution in
the frequency domain.
229
230 An optimal time-limited window maximizes energy in its spectrum over a
given frequency band. In the discrete domain, the Kaiser window gives the best
approximation to such an optimal window.
231
232 Try
233

234

wintool

235 Question:
Experiment with different windows (minimum 3) and
detail what you find.
236
237
238

## 239 The above should be written as a formal laboratory

report, detailing the experimental process undertaken in
Matlab, any required mathematics, and explanations on
what you observe. All questions within the text should be
attemped. Marks are given for presentation.
240
241
242
243 The material in this lab derives somewhat from the MathWorks training
document MATLAB for Signal Processing",
244
245
2

G Morison
page 8

246

G Morison
page 9