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

The University of Hong Kong

Department of Electrical and Electronic Engineering

ELEC2845 Applied optimization and applications

Assignment: Filter Design


(8 marks)

1. Objectives:

The purpose of this assignment is to study the properties of Short Time Fourier Transform
(STFT) based spectral analysis and the design of one dimensional finite-duration impulse
response (FIR) linear phase filters using MATLAB. The convex programming method will
be studied.

2. Equipment Required

MATLAB: MATLAB is an interactive environment for high level simulation of general


numerical applications such as numerical linear algebra, signal processing, etc. Refer to
http://www.mathworks.com/help/matlab/ for more details.

If you do not have the MATLAB software, you may use the PC workstations located at the
CYC103 Laboratory.

Reference: A.V. Oppenheim, Discrete-time Signal Processing, Prentice-Hall, 1991.

3. Submission Format and Deadline

A brief written report addressing the problems listed in section 5 should be submitted either in
Microsoft Word or PDF format together with the appended MATLAB codes and uploaded to
the Moodle System by March 15, 2024 23:59 (GMT +8:00).

4. Theory
4.1 Frequency Response & Spectrogram

Figure (1) Frequency response of a practical lowpass filter.


3DVVEDQG5LSSOH įၶ 7KLVLVWKHYDULDWLRQLQWKHILOWHU VJDLQDOORZHGLQWKHSDVVEDQG,WLVWKH
PD[LPXPGHYLDWLRQIURPWKHLGHDOUHVSRQVH ZKLFKLVW\SLFDOO\RUG%IRUQRUPDOL]HGJDLQ LQ
WKHSDVVEDQG7KHSDVVEDQGULSSOHLVPHDVXUHGIURP RUG% DQGH[WHQGVWRδ₁DQGíδ₁LQ
WKHPDJQLWXGHUHVSRQVH

6WRSEDQG5LSSOH įၷ 6LPLODUWRWKHSDVVEDQGULSSOHWKLVLVWKHPD[LPXPDOORZHGYDULDWLRQLQ
WKHVWRSEDQG,WVSHFLILHVWKHPD[LPXPDPRXQWE\ZKLFKWKHILOWHU VJDLQFDQGHYLDWHIURP]HURLQ
WKHVWRSEDQG

3DVVEDQG(GJH)UHTXHQF\ Ȧႉ 7KLVLVWKHIUHTXHQF\DWWKHHGJHRIWKHSDVVEDQGEH\RQG
ZKLFKWKHWUDQVLWLRQEDQGEHJLQV,WW\SLFDOO\GHILQHVWKHFXWRIISRLQWZKHUHWKHILOWHU VPDJQLWXGH
UHVSRQVHEHJLQVWRIDOOEHORZWKHįၶOHYHO

6WRSEDQG(GJH)UHTXHQF\ Ȧႊ 7KLVLVWKHIUHTXHQF\DWWKHHGJHRIWKHVWRSEDQGZKLFK
GHILQHVWKHVWDUWRIWKHVWRSEDQGIRUWKHILOWHU,WLVWKHSRLQWZKHUHWKHPDJQLWXGHUHVSRQVHLV
H[SHFWHGWREHEHORZWKHPD[LPXPDOORZHGVWRSEDQGULSSOHįၷ

7UDQVLWLRQ%DQG7KHIUHTXHQF\UDQJHEHWZHHQȦႉDQGȦႊLVWKHWUDQVLWLRQEDQG7KLVLVZKHUH
WKHILOWHU VUHVSRQVHWUDQVLWLRQVIURPWKHSDVVEDQGWRWKHVWRSEDQG

Figure (2) Spectrogram of a short-time Fourier transform.

Spectrogram divides the time signal into short segments and computes the frequency spectrum
for each segment. This provides a two-dimensional representation of the signal where one axis
represents time, the second axis represents frequency, and the intensity or color at each point
represents the amplitude (or power) of a particular frequency at a particular time.

4.2 Convex programming method

Optimization toolbox: The problem mentioned above can be solved using a free Matlab toolbox
“CVX”, which is available at http://cvxr.com/cvx/download

Install the CVX toolbox according to the descriptions therein.

Background:
In FIR filter design, the following minimax problem is commonly encountered:
min max | H (e jZ )  H d (Z ) | , (1)
h (n) Z:

where h(n) is the filter coefficients to be determined, : is the frequency interval of interest,
H (e jZ ) is the frequency response of the FIR filter given by
N 1
H (e jZ ) ¦ h(n)e jZn , (2)
n 0

N is the filter length and H d (Z ) is the ideal frequency response. Typical ideal frequency
responses of lowpass and highpass FIR filters are respectively given by
­e  jZW , 0  Z  Z p ,
H dLPF (e jZ ) ® , (3)
¯0, Z s  Z  S ,
­0, 0  Z  Zp,
H dHPF (e jZ ) ®  jZW , (4)
¯e , Zs  Z  S ,
where W is the group delay of the FIR filter, and Z p and Zs are the passband and stopband
edges, respectively.

4.3 PC-MATLAB

PC-MATLAB is an interactive environment for high level simulation of general numerical applications
such as numerical linear algebra, signal processing, etc.

MATLAB works with essentially only one kind of object, a rectangular numerical matrix with
possibly complex elements. Refer to PC-MATLAB Reference and Tutorial for more details of
matrix declaration and manipulation.

User defined function or command files can be added to MATLAB’s vocabulary if they are
expressed in terms of other existing functions. The commands and functions that comprise the new
function are put in a file whose name defines the name of the new function, with a file type of .m
appended. See the PC-MATLAB reference pp.3-84-3.85 for details. M-files can be created using
ordinary text-editor and placed in the same directory of MATLAB or other defined search path in
MATLAB. Type the name of the M-file in MATLAB environment will invoke the commands or
functions defined in the corresponding M-file.

In this experiment, we shall make use of functions in the Signal Processing Toolbox in the PC-
MATLAB for designing linear phase FIR filters.

fvtool is a powerful graphical user interface in MATLAB for analyzing digital filters. It provides
various ways to visualize a filter's characteristics, including its magnitude response, phase response,
group delay, impulse response, step response, and pole-zero plot, among others. For example

fvtool(h, 1)

Vector h containing the filter coefficients. Refer to MATLAB Signal Processing Toolbox Tutorial pp.
5-13 - 5-14 for more details.

conv function in MATLAB is used for performing convolution between two vectors or arrays.
Convolution is a mathematical operation that combines two sets of information.

c = conv(x,h,'same')

x represents an input signal and h represents the filter coefficients, the output c will represent the
filtered signal from that system. 'same': Returns the central part of the convolution that is the same size
as x.
5. Procedure

The assignment package ‘lab1.zip’ contains the following files:

x lab1_main.m: This script is used to calculate and display the spectrogram of the synthetic
signal which is stored in Signal.mat. The script will load a variable named ‘x’, which is
a signal. The total duration of the signal is 2 seconds and the sampling rate is 200 Hz.

x stft.m: In-house MATLAB scripts to perform STFT.

x fir_type2_hp_cvx.m: This script is to design a type-II FIR linear-phase highpass filter


with the ideal frequency response in (4) and the following specifications:

(a) N 31 .
(b) Zs 0.6S and Z p 0.8S .
(c) W ( N  1) / 2 15 .
(d) Coefficient symmetry: h(n) h( N  1  n) , n 0,1,..., N .

(i) Run lab1_main.m to display the synthetic signal and the STFT-based spectrogram
using the default setting (window length = 0.3s). From the signal and its spectrogram,
comment on the properties of the signal and identify the frequency of the signal at
t 0, 1 and 2 s.

(2 marks)

(ii) Use the convex programming method (refer to fir_type2_hp_cvx.m) to design a


lowpass filter with the passband, stopband and filter length as in (5). Plot its impulse,
group delay and frequency responses.

Zp 0.6S , Z s 0.7S , N = 52, (5)


(2 marks)
(*)
(iii) Use the filter designed in (ii) to filter signal ‘x’ by linear convolution.

(1 marks)

Remarks (*)
You can use the function conv in MATLAB for your implementation.

(iv) Calculate the spectrogram of filtered signal with default window size. Plot the filtered
signal and its spectrogram.

(1 marks)
(v) Comment and explain the difference between the spectrogram of signal ‘x’ and the
filtered signal.

(2 marks)

***END***

You might also like