Coursework 2023
Coursework 2023
Plagiarism
Please note the following School statement on Plagiarism: “The deliberate
and substantial unacknowledged incorporation in your submission of
material derived from work (published or unpublished) of another is
prohibited. In such cases the work submitted is classified as illegal and
will result in further action being taken by the University, which may include
recording a failure.”
Marking Criteria
All assessed work shall be marked according to the following performance criteria.
Description % Mark
Excellent 70+
Above Average 60-69
Average 50-59
Satisfactory 40-49
Unsatisfactory 0-39
The definition of the criteria named are:
Digital filters with finite-duration impulse response (referred to as FIR filters) have both
advantages and disadvantages when compared to infinite-duration impulse response (IIR)
filters.
The primary disadvantage of FIR filters is that they often require a much higher filter order
than IIR filters to achieve a given level of performance. Correspondingly, the delay of these
filters is often much greater than for an equal performance IIR filter.
FIR Methods
The Signal Processing Toolbox supports a variety of methods for the design of FIR filters.
Question 1: Using an appropriate search, list the methods available in Matlab for designing FIR
filters.
Impulse Response
𝑦𝑦(𝑛𝑛) = ∑𝑀𝑀
𝑚𝑚=0 𝑥𝑥(𝑚𝑚)ℎ(𝑛𝑛 − 𝑚𝑚) (1)
where the filtered signal y(n) is just a linear combination of current and previous values of
the input signal x(n). The coefficients b (b(m)) are the numerator coefficients of the transfer
function. The denominator of the transfer function will always be a = 1. The order of the
filter is n = length(b) -1.
Question 2: Explain how to calculate the impulse response of the above filter.
Try this in Matlab. Let b represent the coefficients of the x's in equation (1).
• The phase shift of the altered signal 𝜃𝜃(𝜔𝜔) will vary linearly with frequency 𝜔𝜔. (This translates
into the fact that the output signal of such a filter has a pure time delay with respect to the
input signal. There is no phase distortion).
• The phase delay −𝜃𝜃(𝜔𝜔)/𝜔𝜔 and the group delay −𝑑𝑑𝑑𝑑(𝜔𝜔)/𝑑𝑑𝑑𝑑 will be equal and constant
Except for cfirpm, all the FIR filter design functions in the Signal Processing Toolbox design linear
phase filters only.
a = 1;
b = fir1(5,0.5);
fvtool(b,a)
This is the classic method of windowed FIR linear-phase filter design. Look at the phase delay and the
group delay in fvtool.
Question 4: For this (5th order) 6-point filter, confirm that the phase 𝜃𝜃(𝜔𝜔) ≈ −2.5𝜔𝜔 as
seen in the phase plot of fvtool. Provide theoretical explanation for this finding.
Question 5: Describe any restrictions that can occur when using each of the above types of FIR
filter. Hint: use Matlab help.
Recall that the frequency response 𝐻𝐻�𝑒𝑒 𝑗𝑗𝑗𝑗𝑗𝑗 � is periodic. Hence it can be written as a Fourier series.
That is
𝐻𝐻(𝑒𝑒 𝑗𝑗𝑗𝑗𝑗𝑗 ) = ∑∞
𝑛𝑛=−∞ ℎ[𝑛𝑛]𝑒𝑒
−𝑗𝑗𝑗𝑗𝑗𝑗
(4)
ℎ[𝑛𝑛] are the Fourier coefficients that are determined using the inverse DTFT. In general, the
impulse response cannot be implemented as a digital filter because it is infinite and non-
causal.
Question 6: 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.
So, ℎ[𝑛𝑛] is symmetrically truncated (multiplied by a finite, symmetric window) and shifted
to make it causal, to create an implementation that gives a linear phase finite impulse response.
(Recall that from Fourier series properties, if the function is even, the Fourier coefficients
are even and if the function is odd, Fourier coefficients are odd. Hence for 𝐻𝐻(𝑒𝑒 𝑗𝑗𝑗𝑗𝑗𝑗 ) even, like
for a low pass filter, ℎ[𝑛𝑛] will be even, i.e. symmetric.)
The truncated Fourier series can be shown to be an approximation to the ideal filter, which
is “best" in a mean square sense, compared to other approximations of the same length.
However, the abrupt truncation leads to overshoot (Gibb's phenomenon) and ripples in the
spectrum. The undesirable effects of truncation can be reduced or eliminated by the use of
tapered windows.
The Windowing method does not allow you to design a filter, with explicit amplitude response
constraints, such as passband ripple or stopband attenuation. It needs to be used iteratively and we
stop when design specifications are met.
Using the file windemo.m from GCU Learn, try the following in Matlab
edit windemo
windemo(20)
windemo(50)
windemo(100)
Question 9: How does the filter frequency response change with increasing the size of
the filter?
Question 10: Even as you increase the number of filter coefficients that you retain, does
the largest overshoot in the magnitude frequency response decrease in size?
Question 11: Explain what is happening in the 4 figures that you see in windemo.
Windowing Functions
In windemo you saw the effects (Gibbs phenomena) on the frequency response of the finite
length filter when a (default) rectangular window was imposed. Now we see methods of
ridding ourselves of Gibbs phenomena - at a price.
The Signal Processing Toolbox supports a variety of windows commonly used in FIR filter
design. (We will see this in class.) Typing
help window
Individual window functions take inputs for a window length n and window parameters and
return the window w in a column vector of length n. (Note: Use w' for array products with
row vector impulse responses.) The window function serves as a gateway to the individual
functions.
alpha=0.25
w = gausswin(64,alpha)
and
w = window(@gausswin,64,alpha)
both return a Gaussian window of length 64 with standard deviation equal to 1/alpha.
Question 12: Pick two of the available windows and discuss and demonstrate their properties.
edit windft
windft
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.
Question 13: Detail and explain the output of the above function.
Question 14: 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?
Question 15: How does windowing the truncated sine wave "improve" the DFT spectrum?
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 (Why?). Hence you are taking a sine wave, infinitely long, and putting a 1 second rectangular
window on it. In the analogue domain you have,
Question 16: Calculate the Fourier transform of the signal 𝑥𝑥𝑤𝑤 (𝑡𝑡).
Question 17: Compare the results of the Fourier transform with the Matlab output from the DFT of
the signal.
To “window" a filter, the filter impulse response h(n) of size N is multiplied by a window
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 filter
order.
Ideally, the spectrum of a window should approximate an impulse. The main lobe should be
as narrow as possible and the side lobes should contain as little energy as possible.
The Window Visualization Tool (WVTool) allows you to investigate the tradeoffs among
different windows and filter orders.
wvtool(windowname(n))
opens WVTool with time and frequency domain plots of the n-length window specified in
windowname, which can be any window in the Signal Processing Toolbox. Several windows
can be given as input arguments for comparative display.
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))
Question 18: Comment on the differences - main lobe width and ripples - between the
same size rectangular window and the Hamming window.
The Window Design and Analysis Tool (WinTool) is used in conjunction with the Window
Visualization Tool.
• Use WVTool for displaying and comparing existing windows created in the Matlab
workspace.
• Use WinTool to interactively design windows with certain specifications and export them
to the Matlab workspace.
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.
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.
Try
windowDesigner
Question 19: Experiment with different windows (minimum 3) and detail what you find.
The material in this lab derives somewhat from the MathWorks training document “MATLAB for
Signal Processing" by G. Morison and S. Sinanovic.
The purpose of this part of the coursework is to investigate and document the development of the
FFT algorithm, from the development of the Fourier series through to the FFT. Ensure that the report
also covers the following areas:
1. The derivation of the radix-2 decimation in time FFT algorithm, giving the signal flow graph
for an 8 point FFT. (Describe explicitly the butterflies required in the FFT)
2. Discuss spectral leakage and how window functions can be utilized to reduce the effect of
this.
3. Discuss the computational advantage gained by using the FFT algorithms in terms of
multiplications and additions, and discuss what has to be done to the data before the
computations are performed (what is the algorithm for this?).
The above should be written as a report on the FFT, with the following question answered at the end:
4. Take the fft in Matlab of the sound file from laboratory 3 (swfaith.wav), plot the magnitude
and phase spectrums of the fft of this signal, labelling all axis. Repeat this in the range –f/2:f/2.
(Hint: Investigate plotting phase in Matlab).
Performing the above will provide information about the frequency spectrum calculated over the
duration of the entire signal, which removes all temporal information. Investigate and describe how
to obtain information in both the time and frequency domain for the above signal. Use Matlab to aid
you with your description, giving appropriate plots and explanation of the time-frequency
algorithm(s). Use the above signal and any other as required.
In this instance it is acceptable and advised to use existing software, online or existing within Matlab
to perform the above, providing appropriate referencing is utilized. (Hint: Search for Time Frequency
Matlab).