Mathlab Ok
Mathlab Ok
Mathlab Ok
Introduction
Your solutions to the following two questions must be typewritten and should be submitted online
via Blackboard by the deadline of 10th January 2022.
Question 1: 50 marks
The MATLAB data file Q1data.mat contains a data sequence recorded at a sampling rate Fs = 256
Hz. This means that the first 128 elements of the data sequence represent an observation interval
T = 0.5 s of the discrete time signal; the first 256 elements represent T = 1s; the first 512 elements
represent T = 2s; and so on.
Download Q1data.mat into a directory on your MATLAB path and load it into the MATLAB
workspace, e.g., by using the load command.
Use the inbuilt MATLAB function fft.m to carry out a spectral analysis of the discrete-time signal
represented by the MATLAB vector variable Q1data in the loaded mat-file. Repeat the analysis
using each of the five sets of parameters listed in Table 1 to obtain the DFT sequence G[k] of the
discrete-time signal, and hence plot (in Figures 1 to 5) the magnitude of G[k] (in dB relative to
peak) over the frequency range from 0 to 24 Hz.
1 Hamming 8 0.0625
2 Hamming 2 0.0625
3 Rectangular 8 0.0625
4 Rectangular 2 0.0625
5 Rectangular 1 1
Page 4 of 7
Present a report of your work, which should include:
(i) A clear and concise description of the computations involved in obtaining each Figure,
including how the specified values of the parameters (window, T, and F) were
achieved and used. 10 marks
(ii) For each analysis, a fully labelled plot (numbered from Figure 1 to 5) of the magnitude
of G[k] (in dB relative to peak) over the frequency range from 0 to 24 Hz. Your x axis
should cover the range 0 to 24 Hz with tick marks or grid lines in steps of 0.5 Hz, and
your y axis should cover the range from −40 to 0 dB with grid lines in steps of 1 dB.
15 marks
(iii) From each graph, read the values of the frequency and relative amplitude of each
sinusoidal component in the discrete-time signal. 5 marks
(iv) Ensuring that you provide multiple examples from your results to support your
statements and conclusions, discuss the practical issues posed by frequency
resolution, spectral leakage, and spectral smearing, and explain how these issues can
be managed and any problems mitigated through choice of observation interval T,
window function, and/or zero padding of the data sequence. 20 marks
Page 5 of 7
Question 2: 50 marks
The DFT G(k) of a data sequence g[n], and the inverse DFT (IDFT) g(n) of a DFT sequence G[k]
are given, respectively, by the following equations:
2
N −1 −j kn
G(k) = g(n)e N , k = 0,1, 2, , N −1 (1)
n=0
2
1 N −1 j kn
g(n) =
N G (k)e
k=0
N
, n = 0,1, 2, , N −1 (2)
The following MATLAB function myDFT.m implements Equation (1) to calculate the DFT of a data
sequence.
function Gk = myDFT(gn)
%MYDFT: Direct computation of discrete Fourier Transform
% Gk = myDFT(gn) returns the transform sequence Gk corresponding to the
% data sequence gn.
%
%AUTHOR: Prof Ifiok Otung
%DATE: 16 November 2018
%
scalefactor =
1; WN = -
1j*2*pi/N;
for k = 0:N-1
Gk(k+1) =
sum(gn.*exp(WN*k.*n)); end
Gk = Gk*scalefactor;
(a) Modify this code so that it computes DFT by default and inverse DFT by a choice made
using a second input argument. Submit your modified code along with a discussion of how
you tested the code to ensure it works correctly as required. 16 marks
Page 6 of 7
(b) The input discrete-time signal x[n] given by Equation (3) is transmitted through a finite
impulse response (FIR) filter with impulse response h[n] given by Equation (4) as follows:
10, 0 n 5
x(n) = (3)
0, Elsewhere
5 exp ( − n 2 ) , 0 n 6
h(n) = (4)
0, Elsewhere
(i). Use a frequency domain approach and your code in (a) to compute the output
sequence y[n] of this filter. Describe every step of your computation.
14 marks
(ii). Using the inbuilt MATLAB function conv.m, compute the output sequence y[n] of
the filter through a time domain approach. How does your result here compare with the
result obtained in (i)?
8 marks
(iii). Sketch the input and output sequences x[n] and y[n] and, by comparing both,
quantify the effects of the filter on its input signal in terms of gain, delay, dispersion
(i.e., pulse broadening), and pulse shaping (i.e., relative attenuation of low or high
frequency components).
12 marks
Page 7 of 7