LAB Objectives:
To perform Discrete Fourier Transform on different signals and analyze the
signals in the frequency domain.
Discrete Fourier Transform is given as:
“Discrete Fourier Transform is a powerful computation tool
which allows us to evaluate the Fourier Transform X(ej) on a
digital computer or specially designed digital hardware.”
Question 1:
Use a random discrete signal with N = 15. Compute Discrete Fourier Transform and plot
the magnitude of DFT signal.
MATLAB Code:
clc; close all;
% Ques No 1
Ni = 15; % Length of input sequence
rng(9) % Setting seed for random generation
x = randi([-20 20],1,Ni) % Generate randomly
subplot(2,2,1); % Using subplot to plot together
stem(x);
grid minor
xlabel('Time');
ylabel('Magnitude');
title('Time Spectrum');
% Compute DFT
N = length(x); % Length of signal
X = zeros(1,N); % Initialize DFT coefficients
for k = 1:N % Loops for DFT calculations manually
for n = 1:N
X(k) = X(k) + x(n)*exp(-1i*2*pi*(k-1)*(n-1)/N);
end
end
% Compute magnitude and phase
mag_X = zeros(1,N); % Initialize magnitude
phi_X = zeros(1,N); % Initialize phase
for k = 1:N
mag_X(k) = sqrt(real(X(k))^2 + imag(X(k))^2); % Compute magnitude
phi_X(k) = atan2(imag(X(k)), real(X(k))); % Compute phase
end
% Plot results
f = (0:N-1)/N; % Frequency vector
subplot(2,2,3);
plot(f, mag_X); % Plot the magnitude
grid minor
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum');
subplot(2,2,4);
plot(f, phi_X); % Plot the phase
grid minor
xlabel('Frequency (Hz)');
ylabel('Phase (rad)');
title('Phase Spectrum');
Code Output:
Question 2:
Define signal x as sum of two sinusoidal components with frequency 60 Hz (for sine wave)
and 90 Hz (for cosine wave). Compute discrete Fourier transform X using two nested for
loops and implement formula for DFT. Calculate and display the magnitude and phase of
the resulting DFT signal?
Take length N of the input signal x as 100.
Question 3:
Define a signal x as sum of two sinusoidal component and two cosine components with
frequencies 60 & 20 Hz (for sine wave) and 5 & 90 Hz (for cosine wave). Compute Discrete
Fourier Transform X (manual calculation). Calculate and display the magnitude and phase
of the resulting DFT signal?
Take length N of the input signal x as 80.
Question 4:
Consider the following signal ( ). Compute Discrete Fourier Transform. Plot the
magnitude and phase of the resulting DFT signal?
( )= ( / ) ( / )
+ for − ≤ ≤