Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

ETM 4096: Digital Signal Processing Trimester 2 2020/2021

FACULTY OF ENGINEERING & TECHNOLOGY

LAB SHEET

DIGITAL SIGNAL PROCESSING

ETM4096

TRIMESTER 2 (2020/2021)

Experiment 2: DSP2 Design of a Digital Filter

Note: Students are advised to read through this lab sheet before the experiment.

1
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

DSP2: Design of a Digital Filter

1. Objectives
In this experiment, students are required to identify and analyze a digital audio signal with some
added noise. When the audio signal is recorded, it is often corrupted by noise. The objective of this
experiment is to identify these unknown noise signals to obtain the filter specification and to
eliminate them using a suitable digital filter implemented in OCTAVE/SCILAB. This involves
signal spectrum analysis to produce filter performance specification. Subsequently the student is
required to design the filter that meet the specification by determining the filter order and finding the
filter coefficients. At the end of this lab the student should gain the practical knowledge to design a
FIR and IIR digital filter in OCTAVE/SCILAB based on the given filter specification.

Note
Students are required to learn OCTAVE/SCILAB and the basic theory of the FIR and IIR filter
before coming to the lab.

2. Apparatus
● Desktop PC with soundcards
● Original and noise-corrupted audio files (WAV format)*.
● SCILAB Software, OCTAVE Software
* Each student will be assigned a different set of original audio signal and noisy audio signal in
".wav" format. Instructions on getting your files will be informed accordingly.
3. Background Theory
A digital filter implements the difference equation that describes the algorithm to process the
time domain signal in order to achieve filtering objectives. The objective of filtering is to remove
signal in certain frequency range. The difference equation is implemented either in software on DSP
processor or on personal computers. It can also be implemented on hardware, for example in FPGA
or custom integrated circuit. The objective of the filter design is to obtain the filter coefficients so
that the difference equation of the filter can be implemented. Equation (3.1) shows the standard
difference equation for IIR filter (order = max (p,q)) and equation (3.2) shows the standard
difference equation for FIR filter of order q. The filter coefficients are given by bk and ak.

Digital filters can be divided into finite impulse response (FIR) and infinite impulse response (IIR)
filter. IIR filter contains a feedback loop in the block diagram, hence the transfer function of an IIR
filter contains poles, and perhaps zeros as well. FIR filter, on the other hand, does not have the

2
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

feedback loop, thus its transfer function consists of only zeros. Both types of filter have its own
advantages:
Advantages of FIR filter:
● Can have exact linear phase,
● FIR filters are realized non-recursively, thus are always stable,
● Round-off noise and coefficient quantization errors much less severe,
● Arbitrary frequency responses.
Advantages of IIR:
● Analog filters can be readily transformed into equivalent IIR digital filters. This is
impossible with FIR filters as they have no analog counterpart,
● Require less filter coefficients than FIR to achieve similar frequency response,
● In many applications, linearity of phase response is not an issue.
Generally there are 8 stages in the design of a digital filter:
1. Specification of the filter requirements
2. Choice of a type of filter (FIR or IIR).
3. Determination of the filter order.
4. Finding a set of coefficients.
5. Implementation.
6. Quantization.
7. Redesigning if necessary.
8. Choosing the filter structure.
The first step of a digital filter design is the filter specification. The specification is in frequency
domain and based on the magnitude response of the filter. This is due to frequency selective
operation that the filter performs. The important parameters to be included are described in the
following diagram.

Figure 1: Digital Filter Specification

3
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

As shown in Figure 1, the parameters of the filter specification are the passband edge frequency fp,
the stopband edge frequency fs, maximum attenuation in passband (1/Ap), minimum attenuation in
the stopband (1/As) and the transition bandwidth (fs – fp). p defines the magnitude of the ripples
allowed in the passband. The attenuation is usually expressed in the dB unit. The filter to be
designed must meet the criteria in the specification. Normally a low pass filter is designed and the
transfer function is modified in order obtain other types of filter such as the high pass filter and the
bandpass filter. The focus of this experiment is on stages (1) – (4), using both the FIR and IIR filters.

For IIR filter, the design approach commonly used is to design a prototype analog filter and
transform it to an equivalent digital filter using method such as the bilinear transform. This approach
makes use of the many establish methods of analog filter design available such as the Butterworth
and Chebyshev filter. Figure 2 shows the design flow for an IIR filter using bilinear transform. Take

note that the cut-off frequency obtained from the filter specification is a digital frequency where

= 2 f/fsampling (f is frequency in Hz) and is the prewarped analog frequency =2/Ts tan( /2),
Ts= 1/ fsampling . The analog filter uses as the cut-off frequency.

Filter 2: IIR filter design using bilinear transform


One common method used for designing the FIR filter is the windowing approach. The idea is to
truncate the infinite impulse response h(n) of an ideal low pass filter using a window function such
as a rectangle function. This is to produce a linear phase and causal FIR filter. This process however
distorts the magnitude response of the ideal filter by introducing ripples in the passband and
stopband. In addition, the transition band is created as well. Different types of window such as the
Hanning, Blackman and Hamming window can be used to mitigate this unwanted effect. Figure 2
below shows the effect of windowing on the ideal frequency response.

4
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

cut-off

Figure 3: The ideal desired frequency response and the practical response
For FIR filter, we need to first determine the window type and the filter order. The window type is
determined based on the stopband attenuation, while the filter order is identified based on the
transition width:
- Rectangular window: αs= -21dB, N = 0.9 / Δf;
- Hanning window: αs= -44dB, N = 3.1 / Δf;
- Hamming window: αs= -53dB, N = 3.3 / Δf;
- Blackman window: αs= -74dB, N = 5.5 / Δf;
- Kaiser window: αs= -20log(δs), N = (αs - 7.95) / (14.36 Δf);
Δf =( fstop - fpass)/ fsampling
The filter coefficients of FIR filter can then be found using OCTAVE/SCILAB function.
4. Experimental Procedure

The audio signals need to be compared both in time and in frequency domain. To read the signal, use
the function wavread for SCILAB and audioread for OCTAVE. You can also use the function
wavread to identify the sampling frequency of audio files (type ‘help wavread or help
audioread’). The length of the signal can be obtained using the command length. The sound
wave can be played using the command wavplay for SCILAB and sound for OCTAVE.
Before the filter specification can be obtained, the frequency spectrum of the clean and noisy signal
will need to be obtained. This enables you to locate the noise frequency range by comparing the
spectrum plot for both the clean and noisy signal. The frequency spectrum of Fourier transform can
be obtained using the command fft. Note that the fft is a complex function, hence it can be split up
in its real and imaginary parts (functions imag and real) or in its amplitude and phase (abs and
angle). Usually, we are more interested in the amplitude than in the phase - can you see why from
the plot of both phase and amplitude? You are only required to plot the spectrum magnitude till the
Nyquist frequency.

5
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

Plot the amplitude of the frequency spectrum for both the original clean signal and noisy signal.
From the comparison between both, specify the requirements for a filter that would eliminate the
noise as much as possible and alter the signal as little as possible. From passband edge frequency fp
and stopband edge frequency fs, the cutoff frequency fc is calculated as the average of both. The
student will have to implement both an FIR and an IIR filter.

For the FIR filter, the command fir1 will be used. For this experiment, you should achieve a peak
passband ripple of 3 dB and minimum stopband attenuation of X dB (The value for X will be given
during the lab session). Which window will you choose? Why? Determine the filter order N for the
chosen window. Design the FIR filter using the function fir1. The frequency response of the filter
can be obtained using the function freqz for OCTAVE and frmag for SCILAB. Plot the
designed filter frequency response and see whether the specifications are met. Check especially the
passband and stopband edge frequencies. If necessary, redesign the filter.

Apply the filter to the noisy signal using the function filter for OCTAVE and flts for
SCILAB. For example, if the noisy signal is stored in vector x and the designed FIR filter
coefficients are stored in vector h, we can obtain the filtered signal by using y = filter (h,
1, x) for OCTAVE and y = flts(x,h). Plot the frequency spectrum or Fourier
transform of the filtered signal, and compare it with the Fourier transform of the original and of the
noisy signal. Discuss your findings.

For the IIR filter, the student has the choice between 4 types of filter: Butterworth, Chebyshev type I,
Chebyshev type II, and elliptic. The filter order can be determined using the functions buttord,
cheb1ord, cheb2ord and ellipord, respectively. As in the case of the FIR filter, you should
achieve a peak passband ripple of 3 dB and minimum stopband attenuation of 30dB. Which filter
type will you choose? Why? Determine the filter order N for the chosen filter type. Design the IIR
filter using the function butter, cheby1, cheby2 or ellip, respectively. The frequency
response of the filter can be obtained using the function freqz for OCTAVE and frmag for
SCILAB. Plot the designed filter frequency response and see whether the specifications are met.
Check especially the passband and stopband edge frequencies. If necessary, redesign the filter.

Apply the filter to the noisy signal using the function filter for OCTAVE and flts for
SCILAB. For example, if the noisy signal is stored in vector x and the designed FIR or IIR filter
coefficients are stored in vectors a and b, we can obtain the filtered signal by using y =
filter(b, a, x) for OCTAVE and y = flts(x,h)where h is the transfer
functions values. Plot the Fourier transform of the filtered signal, and compare it with the
Fourier transform of the original and of the noisy signal. Discuss your findings.

6
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

Summary of basic procedure and useful functions:


1. To read the wav file into a vector, use the wavread function. To play the sound stored
in the vector, use the wavplay function. For OCTAVE use audioread and sound.
2. Plot the spectrum using the fft function. Wherever possible, use the subplot
function to combine the spectra of the noisy and clean signal into a signal plot for easy
comparison.
3. Determine the cut-off frequency, transition width, and filter order required. For FIR
filters, the filter order needs to be computed manually except for Kaiser it can be
computed using kaiserord. For IIR, it can be computed using either the buttord,
cheb1ord, cheb2ord and ellipord functions.
4. Design a low-pass filter using. For FIR, use the fir1 function. For IIR, use either the
butter, cheby1, cheby2 or ellip functions.
5. Filter the noisy signal using the filter (OCTAVE) or flts (SCILAB) function.
6. Compare the frequency spectrum again to check if the noise has been removed. You can
play back the sound too to check if the quality has been improved. Use Signal-to-noise
ratio (SNR) for performance evaluation of the designed filter.

7
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

5. Exercise Questions

a) Describe the filter specification used and the results obtained using FIR and IIR filter. Use
data tables to tabulate your result.

Write a OCTAVE/SCILAB code to compute the difference between the frequency samples
of the clean signal and the noisy signal. The frequency samples of the signal can be obtained
using the OCTAVE/SCILAB fft function. Use the code to estimate the noise frequency
range. Your filter design specifications depend on this estimation.

Noise frequency range (Hz): _____

Filter Specification
Sampling frequency (Hz): ______ Nyquist Frequency (Hz) ____
Passband edge frequency (Hz): ____ Passband frequency range: ______
Stopband edge frequency (Hz): ______ Stopband frequency range: ______
Maximum passband attenuation (dB): _____ Minimum stopband attenuation (dB): ____

i) Tabulate the performance of the FIR filter obtained. Plot the magnitude and frequency
response graph.

FIR Filter Design with Window Method


Implemented filter
Design method used. Mention the window Kaiser Optimal Method
function used.
Minimum order attained, N
Attenuation at passband edge frequency.
(dB)
(Obtained from frequency response graph)
Attenuation at stopband edge frequency.
(dB)
(Obtained from frequency response graph)

Which window function provides the best performance? Justify your answer.
How many filter coefficients are used to implement the FIR filter?

8
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

ii) Use OCTAVE function to estimate the order of the various IIR filter. Write the answer in the
table below. Which IIR filter gives the best performance? Explain your answer from the
aspect of computational complexity and memory requirement of the filter implementation.

IIR Filter Types Butterworth Type 1 Type 2 Elliptic


Chebyshev Chebyshev filter
Minimum order attained, N
Comment on ripples in the
passband

iii) Fill up the table below with the result obtained from the chosen IIR filter. Plot the magnitude
and frequency response graph.

IIR Filter Design with Bilinear Transform

Implemented filter
Design method. Mention the analog prototype
filter used.
Minimum order attained, N
Attenuation at passband edge frequency. (dB)
(Obtained from frequency response graph)
Attenuation at stopband edge frequency. (dB)
(Obtained from frequency response graph)

b) Based on the filter that you have designed, compare and comment on the performance of the
FIR and IIR filters. Explain if the filters designed successfully remove the noise. Explain
your answer by referring to the frequency spectrum of the clean, noisy and filtered signal.
Explain why the filtered signal is not perceptually similar to the clean signal.

9
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

6. Lab 2 Report Writing Guidelines


NOTE: Submit lab report within two weeks from the date of experiment. The submission via
Google Classroom.
The lab report must be typewritten and shall consist of the following headings. Write clearly and
concisely to describe the important elements of your experiment. All graphs and tables need to be
labeled properly. The answer from the questions in Section 5 can be incorporated into the result and
discussion section. If there is any numerical calculation, it needs to be shown in the procedure section.
Don’t forget to mention the filter specification and design parameters used.

i) Lab Report Submission Cover Page


● which mentions student name and ID number, subject, lab number, date of
experiment and date of report

ii) Introduction
● This section introduces the basic theory underlying the experiment.

iii) Objectives
● State the specific investigation that you would like to conduct in this
experiment.

iv) Procedures
● Explain the procedure and the methodology used

v) Results and Discussion


● Describe the results obtained in a suitable form such as table and graph.
● Discuss the finding of the experiment from the result obtained.

vi) Conclusion
● Derive conclusion based on your findings and results

vii) References

10
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

7. Lab 2 Report Submission Guidelines


You are warned that any act of experiment data fabrication, copying of other people work and failure
to acknowledge the source of your information in the report (plagiarism) are serious offences and if
found, the student will be penalized.

WARNING: Students who are found to have copied someone else's report and the ones who
let somebody else copy their reports will all get their marks averaged. For example, two students
with similar reports originally deserving 20 marks each will each get 10 marks; and three students
with similar reports originally deserving 18 marks each will each get 6 marks instead. A complete
database of your seniors’ reports will also be used in the copy detection process. Plagiarizing
reports of previous years will result in getting zero marks.

Please read the following carefully, failing to comply with any item will result in 20% reduction
for each mistake committed:
● Please save your report in Google Document as provided.
● The filename of the report/zipped report should be your student ID number (e.g. the lab
report of student with ID number 1151104866 should be " 1151104866.doc").
● Students also need to submit three .wav files: one for the noisy signal before filtered, one
for the noisy signal filtered using the designed FIR filter, and the other for the noisy signal
filtered using the designed IIR filter. The filename of the .wav files should be the student
ID number followed by the letter b, i or f, corresponding to the before filtered, IIR filter or
the FIR filter (e.g. the sound file of the signal filtered with the IIR filter of student with ID
number 1151104866 should have the name "1151104866i.wav").
● Submit the FOUR FILES mentioned above.

11
ETM 4096: Digital Signal Processing Trimester 2 2020/2021

8. Further Readings
[1] J. H. McClellan, R. W. Schafer, and M. A. Yoder, Signal Processing First. Upper Saddle
River, NJ: Prentice Hall, 2003.
[2] V. K. Ingle and J. G. Proakis, Digital Signal Processing Using MATLAB V.4. Boston:
PWS Publishing Company, 1997.
[3] E. C. Ifeachor and B. W. Jervis, Digital Signal Processing: A Practical Approach, 2nd ed.
Upper Saddle River, NJ: Prentice Hall, 2001.
[4] M. H. Hayes, Schaum's Outline of Theory and Problems of Digital Signal Processing, New
York: McGraw-Hill, 1999.
[5] J. G. Proakis and D. G. Manolakis, Digital Signal Processing: Principles, Algorithms, and
Applications, 3rd ed. Englewood Cliffs, NJ: Prentice Hall, 1996.
[6] A. V. Oppenheim and R. W. Schafer, Discrete-Time Signal Processing. Englewood Cliffs,
NJ: Prentice-Hall, 1989.

12

You might also like