MAKERERE UNIVERSITY
COLLEGE OF ENGINEERING DESIGN ART AND TECHNOLOGY
DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING
ASSIGNMENT 2: FREQUENCY DOMAIN ANALYSIS, FILTERS
NAME REGISTRATION NO. PROGRAM
Alvin Bagetuuma Kimbowa 18/U/125 ELE
Paul Okwija Mugume 18/U/22521/PS ELE
Kevin Ssonko 18/U/488 ELE
Instructor: Dr. Cosmas Mwikirize
Question 1
1 a)
A Fourier series is used to analyze the spectral characteristics of a periodic signal. On the other
hand, Fourier transform is considered when analyzing the spectral characteristics of an aperiodic
signal. The Fourier transform is basically an extension of the Fourier Series to aperiodic signals
whose period is assumed to tend to infinity. Fig. 1 shows an aperiodic signal which can be redrawn
as a periodic signal as shown in Fig. 2, but with its period tending to infinity.
Figure 1. Aperiodic Signal
Figure 2: Periodic Signal
1 b)
𝑁−1
2𝜋𝑘
𝑋[𝑘] = ∑ 𝑥[𝑛] 𝑒 −𝑗 𝑁
𝑛
𝑛=0
For 𝑥[𝑛] = 5𝛿[𝑛]
2
𝑁−1
2𝜋𝑘
𝑋[𝑘] = ∑ 5𝛿[𝑛] 𝑒 −𝑗 𝑁
𝑛
𝑛=0
2𝜋𝑘
(0)
𝑋[𝑘] = 5𝛿[0]𝑒 −𝑗 𝑁 +0+0+⋯
For a unit impulse function, 𝛿[0] = 1
∴ 𝑋[𝑘] = 5 𝑓𝑜𝑟 0 ≤ 𝑘 ≤ 𝑁 − 1
c)
𝑓𝑠 500
𝐹𝑟𝑒𝑞𝑢𝑒𝑛𝑐𝑦 𝑟𝑒𝑠𝑜𝑙𝑢𝑡𝑖𝑜𝑛 = = = 0.9767
𝑁 512
d) (i) Minimum sampling rate
, 𝑓𝑠𝑚𝑖𝑛 = 2𝑓𝑖 = 2 × 100 = 200𝐻𝑧
(ii) With a sampling frequency of 200 Hz, the digital signal obtained is:
𝑥[𝑛] = 𝑥(𝑛𝑇𝑠 ) = 4 cos(200𝜋 𝑛𝑇𝑠 )
Where 𝑇𝑠 = 1⁄𝑓 = 1⁄200
𝑠
∴ 𝒙[𝒏] = 𝟒 𝐜𝐨𝐬(𝝅 𝒏)
3
e)
We used the following MATLAB code to generate, visualize and obtain the Fourier Transform of
the required signal.
fs = 8e3;
Ts = 1/fs;
t = 0:Ts:(1/8 - 1/8000);
x = cos(2*pi*4000*t);
figure(1); plot(t,x);
xlim([0 0.001])
title("x(t) = cos(2*pi*4000*t)")
N = length(x);
Xf = abs(fft(x));
f = (1:N)*fs/N;
figure(2), plot(f,Xf);
title("X(f)")
Fig. 3 shows a plot of the original signal limited between 0 and 1 along the time axis. Fig. 4 shows
a plot of the DFT spectrum.
Figure 3: Plot of x(t)
4
Figure 4: A plot of the magnitude spectrum X(f).
From the magnitude spectrum, we obtained a peak at only one frequency i.e. 4000. Therefore,
𝑓 4000
𝑘1 = 𝑘2 = 𝑁 𝑓0 = 1000 × 8000 = 500
𝑠
5
Question 2
2 a)
We used the code below to visualize the corrupted image shown in Fig. 5.
clear
clc
close all
addpath(genpath(pwd));
load('mri_per_noise.mat');
img = mri_per_noise;
[M,N] = size(img);
figure(1), imshow(img,[])
title("Original Image")
Figure 5: Noisy MRI image of the knee
Using the code below, we obtained the Fourier Transform of the image and shifted the zero-
frequency component to the center. Fig. 6 shows the obtained magnitude spectrum.
mri_fft = fft2(img);
mri_fft_shifted = fftshift(mri_fft);
figure(2), imshow(log(abs(mri_fft_shifted)),[]);
title("Shifted Image fft")
impixelinfo
6
Figure 6: Magnitude Spectrum
b)
From the magnitude spectrum in Fig. 6, we obtained the coordinates of the centers, k1 and k2, of
the two left-most high intensity pixels as shown in the code below. We then use these
coordinates to create an ideal reject notch filter with a radius of cut-off frequency of 15. To
achieve this, we utilized the cnotch function provided in the homework resources. Fig. 7 shows
the notch filter design that we obtained.
k1 = [129 1];
k2 = [129 65];
C = [k1;k2];
n_filter = cnotch('ideal','reject',M,N,C,15);
% figure(3), subplot(1,2,1), imshow(n_filter,[]);
% title("Notch Filter")
% Shifting the notch (flipping it horizontally)
n_filter_shifted = fftshift(n_filter);
imshow(n_filter_shifted,[]);
title("Shifted Notch Filter")
7
Figure 7: Visualization of the notch filter with the zero-frequency component centered.
c)
We utilized the dftfilt function provided in the homework resources to perform frequency domain
filtering as shown in the code below. Fig. 8 shows the reconstructed MRI Image. It can be seen
that the noise that was present in the original image has been removed.
final_img = dftfilt(img,n_filter);
figure(4); imshow(final_img,[]);
title("Filtered Image")
Figure 8: Filtered MRI Image
Published with MATLAB® R2022a