Lab_6
Lab_6
EE093IU
Submitted by
- Header/Footer Yes No
- Spelling Yes No
Total Score
Date:
Signature
International University 2
EE093IU
School of CSE
TEAM CONTRIBUTION
Task Lê Tiến Phát Nguyễn Ngọc Ngân
Collaborated on all coding tasks, participated in problem-solving
Collaboration
discussions, and jointly tested MATLAB implementations
Lab preparation Answer in-class questions
and experiment
Data analysis Jointly analyzed & verified the results for all problems
Write fundamental background & Write experiment procedure &
Report writing
Conclusion Results
International University 3
EE093IU
School of CSE
Table of Contents
List of Figures ........................................................................................….….............................. 4
Discussion of Fundamentals.............................................................................................…….... 5
Experimental Procedure.............................................................................................……........... 7
Results ........................................................................................................……... 9
Conclusions………...................................................................................................................... 25
List of Figures
Figure 1 – Magnitude of DFT over [-3pi,3pi] 10
Figure 2 – Phase of DFT over [-3pi,3pi] 11
Figure 3 – Magnitude of DFT over [-7pi,7pi] 12
Figure 4 – Phase of DFT over [-7pi,7pi] 13
Figure 5 – Magnitude of DFT 14
Figure 6 – Phase of DFT 15
Figure 7 – Real Part of DFT 16
Figure 8 – Imaginary Part of DFT 17
Figure 9 – Magnitude of DTFT and DFT 18
Figure 10 – Phase of DTFT and DFT 19
Figure 11 – Magnitude and Phase Response of Low-Pass Filter 22
Figure 12 – Magnitude and Phase Response of High-Pass Filter 23
Figure 13 – Square Wave Response of Low-Pass and High-Pass 24
Figure 14 – Square Wave Response (Frequency Domain Method) of Low-Pass and High-Pass 25
International University 4
EE093IU
School of CSE
Discussion of Fundamentals
The DTFT is used to analyze the frequency content of discrete-time signals, DTFT transforms a
discrete-time signal x[n] into a continuous frequency-domain function X(ω), defined as:
Understand that ω is a continuous frequency variable, and X(ω) is periodic with period 2π.
Properties:
International University 5
EE093IU
School of CSE
2𝜋𝑘
Understand that X represents the frequency components at discrete frequencies 𝜔𝑘 = 𝑁 (the
DFT samples the DTFT)
The IDFT (Inverse DFT) recovers the original signal:
Properties:
The FFT is an efficient algorithm to compute the DFT, reducing the computational
complexity from O(𝑁 2 ) to O (𝑁 𝑙𝑜𝑔 𝑁) when N is a power of 2. Uses a "divide and conquer"
approach, splitting the DFT into smaller subproblems.
Understand how the CTFT relates to the DFT when approximating the frequency response of a
continuous-time signal via sampling. The DFT of a sampled signal x[nT] approximates the
2𝜋𝑘
CTFT X(Ω) at frequencies 𝛺𝑘 = , with the relationship:
𝑁𝑇
This requires understanding sampling theory and the effects of sampling time T and
sequence length N.
International University 6
EE093IU
School of CSE
Experimental Procedure
Problem 1:
Objective: Plot the magnitude and the phase of the DTFT X(ω) of the signal
𝜋𝑛
𝑥[𝑛] = 𝑐𝑜𝑠( ), 0 ≤ 𝑛 ≤ 10
3
over two frequency intervals:
● −3π ≤ ω ≤ 3π
● −7π ≤ ω ≤ 7π
Process:
1. Declare signal x[n] and Create continuous frequency vector 𝜔
2. Calculate DTFT X(ω) using the formula:
3. Draw graph with abs() function to get magnitude, angle() to get phase
Problem 2:
Objective: Plot the magnitude, the angle, the real part, and the imaginary part of the DFT
𝑋𝑘
Process: The DFT of an ideal cosine signal will have two sharp peaks at the 𝜔𝑘 =
2𝜋𝑘 2𝜋𝑛
frequencies corresponding to the original frequency. For the cos ( ) signal, since the DFT
𝑁 3
2𝜋𝑘
samples the spectrum at points 𝜔𝑘 = 𝑁 will have a large amplitude at k = 21 and k = N - 21 =
International University 7
EE093IU
School of CSE
Objective:
- DTFT graph X(ω) of x[n] on the interval 0 ≤ ω ≤ 2π
2𝜋𝑘
- DFT graph of x[n] at points 𝜔𝑘 = 𝑁 , 𝑘 = 0,1, . . . , 𝑁 − 1
Process:
1. Declare signal x[n] and find DTFT continuous
2. Calculate DFT by fft()
Problem 4:
Objective:
Principle:
1
a. For a low-pass RC circuit, apply the transfer function: 𝐻(𝜔) = 1+𝑗𝜔𝑅𝐶. Use 0 to
100 Hz to capture the behavior around 7 Hz. Convert to angular frequency using ω
= 2πf.
𝑗𝜔𝑅𝐶
b. For a high-pass RC circuit, apply the transfer function: 𝐻(𝜔) = 1+𝑗𝜔𝑅𝐶.
International University 8
EE093IU
School of CSE
Experimental Results
Problem 1:
% Define signal
n = 0:10;
x = cos(pi * n / 3);
% Symbolic DTFT
syms w
X = sum(x .* exp(-j * w * n));
Result
International University 9
EE093IU
School of CSE
Figure 1. Result of the program in Problem 1 – Magnitude of DFT over [-3pi,3pi]
International University 10
EE093IU
School of CSE
Figure 2. Result of the program in Problem 1 – Phase of DFT over [-3pi,3pi].
International University 11
EE093IU
School of CSE
Figure 3. Result of the program in Problem 1 – Magnitude of DFT over [-7pi,7pi].
International University 12
EE093IU
School of CSE
Figure 4. Result of the program in Problem 1 – Phase of DFT over [-7pi,7pi].
Problem 2:
% Define signal
n = 0:64;
x = 3 * cos(2 * pi * n / 3);
% Compute DFT
N = length(x);
Xk = fft(x);
% Plot magnitude
figure;
stem(0:N-1, abs(Xk));
title('Magnitude of DFT');
xlabel('k'); ylabel('|X_k|');
xlim([-0.5 64.5]);
% Plot phase
figure;
stem(0:N-1, angle(Xk));
title('Phase of DFT');
xlabel('k'); ylabel('\angle X_k');
International University 13
EE093IU
School of CSE
xlim([-0.5 64.5]);
Result
International University 14
EE093IU
School of CSE
Figure 6. Result of the program in Problem 2 – Phase of DFT.
International University 15
EE093IU
School of CSE
Figure 7. Result of the program in Problem 2 – Real Part of DFT
International University 16
EE093IU
School of CSE
Figure 8. Result of the program in Problem 2 – Imaginary Part of DFT.
Problem 3:
% Define signal
n = 0:19;
x = 5 * cos(2 * pi * n / 3);
% Compute DTFT
syms w
Xdtft = sum(x .* exp(-j * w * n));
% Compute DFT
Xdft = fft(x);
N = length(Xdft);
k = 0:N-1;
wk = 2 * pi * k / N;
% Plot magnitude
figure;
w1 = 0:0.01:2*pi;
XX = subs(Xdtft, w, w1);
plot(w1, abs(XX), 'b', 'DisplayName', '|X(\omega)| (DTFT)');
International University 17
EE093IU
School of CSE
hold on;
stem(wk, abs(Xdft), 'r', 'DisplayName', '|X_k| (DFT)');
title('Magnitude of DTFT and DFT');
xlabel('\omega'); ylabel('Magnitude');
xlim([0 2*pi]);
legend;
% Plot phase
figure;
plot(w1, angle(XX), 'b', 'DisplayName', '\angle X(\omega) (DTFT)');
hold on;
stem(wk, angle(Xdft), 'r', 'DisplayName', '\angle X_k (DFT)');
title('Phase of DTFT and DFT');
xlabel('\omega'); ylabel('Phase');
xlim([0 2*pi]);
legend;
Result
International University 18
EE093IU
School of CSE
Figure 10. Result of the program in Problem 3 – Phase of DTFT and DFT.
Problem 4:
R = 1; % Resistance in Ohms
C = 0.1; % Capacitance in Farads
fs = 2000; % Sampling frequency (Hz)
f_square = 7; % Frequency of square wave (Hz)
N = 8192; % Number of points for frequency response
International University 19
EE093IU
School of CSE
subplot(2,1,1);
semilogx(f, 20*log10(mag_RC), 'LineWidth', 1.5);
title('RC Circuit (Low-Pass Filter): Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;
subplot(2,1,2);
plot(t, input_signal, 'b', 'LineWidth', 1);
hold on;
plot(t, y_CR, 'r', 'LineWidth', 1.5);
title('CR Circuit (High-Pass): Square Wave Response (Frequency Domain Method)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Input (Square Wave)', 'Output Response');
grid on;
Result
Figure 11. Result of the program in Problem 4 – Magnitude and Phase Response of Low-Pass Filter
International University 22
EE093IU
School of CSE
Figure 12. Result of the program in Problem 4 – Magnitude and Phase Response of High-Pass Filter
International University 23
EE093IU
School of CSE
Figure 13. Result of the program in Problem 4 – Square Wave Response of Low-Pass and High-Pass
International University 24
EE093IU
School of CSE
Figure 14. Result of the program in Problem 4 – Square Wave Response (Frequency Domain Method) of Low-Pass and High-Pass
Conclusion
Summary of Work
This lab focuses on the Fourier analysis of discrete-time signals using MATLAB to
illustrate the properties of the Discrete-Time Fourier Transform (DTFT), Discrete Fourier
Transform (DFT), and related concepts. The lab includes theoretical explanations, MATLAB code
examples, and practical problems to compute and visualize the DTFT and DFT of various signals,
their inverse transforms, and their applications in circuit analysis.
Key Findings
Theoretical Validation: Understand and compute the DTFT and DFT of discrete-time signals.
Implement MATLAB code to plot magnitude and phase responses. Explore the relationship
between DTFT and DFT. Apply Fourier analysis to practical scenarios, such as analyzing the
frequency response of an RC circuit and its response to a square wave input.
International University 25
EE093IU
School of CSE
Algorithm Performance: Using subs to evaluate the DTFT at discrete frequencies reduces
computation time for plotting, as seen in Examples 1 and 2. The fft and ifft commands (Example
8) leverage the FFT algorithm, reducing complexity to O (N log N) . This is critical for real-
time applications or large datasets. Using fft and ifft for frequency-domain processing is efficient,
especially for the large number of samples (N=2000) due to the 2000 Hz sampling rate.
Practical Applications: DTFT and DFT are used to identify frequency components in signals, such
as in speech recognition or vibration analysis. The FFT algorithm is critical for efficient
modulation/demodulation in digital communications (e.g., OFDM in 4G/5G networks).
Approximating CTFT with DFT is used in physics and engineering to analyze continuous signals
from sampled data, such as in radar or seismic analysis.
Computing the DTFT for infinite sequences or complex signals requires symbolic math,
which is slow and memory-intensive. Use symsum for infinite sequences (Example 2) and
numerical summation for finite sequences (Example 1). Limit the frequency range for plotting to
reduce computation time.
A 2000 Hz sampling rate generates large datasets, increasing computational load. Use
FFT/IFFT for efficient processing. Ensure sufficient time duration (e.g., 1 second) to capture
multiple periods of the 7 Hz square wave.
Understanding the difference between low-pass and high-pass filter outputs for a square
wave. Plot both magnitude and phase responses to visualize filtering effects. Compare time-
domain outputs to highlight smoothing (low-pass) vs. edge enhancement (high-pass).
THE END
International University 26
EE093IU
School of CSE