0% found this document useful (0 votes)
158 views3 pages

Lab 5

This document describes a laboratory exercise on digital filters for an undergraduate course. The exercise involves: (1) generating a test signal with three sine waves of different frequencies and amplitudes, (2) examining the signal's spectrum, (3) designing low-pass, high-pass, band-pass and band-stop filters to isolate components of the test signal, and (4) investigating how filter length affects performance. Students are asked to write MATLAB code to complete the tasks, show their results, and comment on their observations.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views3 pages

Lab 5

This document describes a laboratory exercise on digital filters for an undergraduate course. The exercise involves: (1) generating a test signal with three sine waves of different frequencies and amplitudes, (2) examining the signal's spectrum, (3) designing low-pass, high-pass, band-pass and band-stop filters to isolate components of the test signal, and (4) investigating how filter length affects performance. Students are asked to write MATLAB code to complete the tasks, show their results, and comment on their observations.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

SRI LANKA INSTITUTE OF INFORMATION TECHNOLOGY

B.ENG (HONS) IN ELECTRONIC ENGINEERING


DIGITAL SIGNAL PROCESSING

Laboratory Exercises 5

Filters
Filters appear as basic building blocks in a signal processing environment and there is a wealth
of knowledge that deals with the design and implementation of digital filters. This exercise will
make use of the MATLAB built-in function fir1, to realize a low-pass, a high-pass, a band-pass,
and a band-stop filter. (MATLAB description of fir1 is appended here for your reference.)

The exercise involves the following tasks:


(a) The generation of a signal which contains 3 different frequency (and three different
amplitude) values.
(b) Examining the spectrum of this signal.
(c) Designing of filters to low-pass, high-pass, band-pass, and band-stop the signal generated in
(a) above.
(d) Examining the filter outputs (in the frequency domain) in all four filter types above when the
signal in (a) above is input to those.
(e) Investigation of the influence of the filter length on the filter performance.

You may proceed as follows:


1. Generate three sine waves (s1, s2, s3) with amplitudes 5V, 3V, 1V, and frequencies 1.0 kHz,
1.5 kHz, 2.0 kHz, respectively.
2. Obtain the composite signal s = s1 + s2 + s3 and display it (in time domain).
3. Use Fast Fourier Transform (FFT) in MATLAB to obtain the spectrum of s and display it (in
the frequency domain). Comment on the accuracy of the spectrum. Do they appear at the
correct frequency? Do they have the correct amplitudes?
4. Design a low-pass FIR filter to isolate s1.
5. Use spectrum analysis to determine the effectiveness of the filter in isolating s1 from s.
6. Investigate how the filter length effects its performance.
7. Design a high-pass FIR filter to isolate s3 from s, and repeat steps 6 and 7 above for s3.
8. Design a band-pass FIR filter to isolate s2 from s, and repeat steps 6 and 7 above for s2.
9. Design a band-stop FIR filter to remove s2 from s, and repeat steps 6 and 7 above for s2.

Note:
The MATLAB built in function conv could be used to obtain the output of the filter in the time
domain. Alternatively, MATLAB filter function can be used for same (but with caution).

Submission
Your report should include the following:
(a) Your MATLAB code with appropriate comments that describe your approach and steps.
(b) The graphs and other results you have obtained.
(c) Your observations and comments with regard to the investigation you have completed.
PD/10
fir1 - Window-based finite impulse response filter design
Syntax
b = fir1(n,Wn)
b = fir1(n,Wn,'ftype')
b = fir1(n,Wn,window)
b = fir1(n,Wn,'ftype',window)
b = fir1(...,'normalization')

Description
fir1 implements the classical method of windowed linear-phase FIR digital filter design [1]. It designs filters
in standard lowpass, highpass, bandpass, and bandstop configurations. By default the filter is normalized so
that the magnitude response of the filter at the center frequency of the passband is 0 dB.

Note Use fir2 for windowed filters with arbitrary frequency response.

b = fir1(n,Wn) returns row vector b containing the n+1 coefficients of an order n lowpass FIR filter. This
is a Hamming-window based, linear-phase filter with normalized cutoff frequency Wn. The output filter
coefficients, b, are ordered in descending powers of z.

Wn is a number between 0 and 1, where 1 corresponds to the Nyquist frequency.


If Wn is a two-element vector, Wn = [w1 w2], fir1 returns a bandpass filter with passband w1 < ω< w2.

If Wn is a multi-element vector, Wn = [w1 w2 w3 w4 w5 ... wn], fir1 returns an order n multiband filter
with bands 0 < ω< w1, w1 < ω< w2, ..., wn < ω< 1.

By default, the filter is scaled so that the center of the first passband has a magnitude of exactly 1 after
windowing.
b = fir1(n,Wn,'ftype') specifies a filter type, where 'ftype' is:

 'high' for a highpass filter with cutoff frequency Wn.

 'stop' for a bandstop filter, if Wn = [w1 w2]. The stopband frequency range is specified by this
interval.

 'DC-1' to make the first band of a multiband filter a passband.

 'DC-0' to make the first band of a multiband filter a stopband.


fir1 always uses an even filter order for the highpass and bandstop configurations. This is because for odd
orders, the frequency response at the Nyquist frequency is 0, which is inappropriate for highpass and
bandstop filters. If you specify an odd-valued n, fir1 increments it by 1.

b = fir1(n,Wn,window) uses the window specified in column vector window for the design. The vector
window must be n+1 elements long. If no window is specified, fir1 uses a Hamming window (see hamming)
of length n+1.

b = fir1(n,Wn,'ftype',window) accepts both 'ftype' and window parameters.


b = fir1(...,'normalization') specifies whether or not the filter magnitude is normalized. The string
'normalization' can be the following:

 'scale' (default): Normalize the filter so that the magnitude response of the filter at the center
frequency of the passband is 0 dB.

 'noscale': Do not normalize the filter.


The group delay of the FIR filter designed by fir1 is n/2.
Algorithm
fir1 uses the window method of FIR filter design [1]. If w(n) denotes a window, where 1 ≤ n ≤ N, and the
impulse response of the ideal filter is h(n), where h(n) is the inverse Fourier transform of the ideal frequency
response, then the windowed digital filter coefficients are given by

Examples

Example 1

Design a 48th-order FIR bandpass filter with passband 0.35 ≤ ω ≤ 0.65:


b = fir1(48,[0.35 0.65]);
freqz(b,1,512)

Example 2

The chirp.mat file contains a signal, y, that has most of its power above fs/4, or half the Nyquist
frequency. Design a 34th-order FIR highpass filter to attenuate the components of the signal below fs/4.
Use a cutoff frequency of 0.48 and a Chebyshev window with 30 dB of ripple:
load chirp % Load y and fs.
b = fir1(34,0.48,'high',chebwin(35,30));
freqz(b,1,512)

References
[1] Programs for Digital Signal Processing, IEEE Press, New York, 1979. Algorithm 5.2.

You might also like