0% found this document useful (0 votes)
4 views26 pages

Lab_6

This document is a laboratory report for a Digital Signal Processing course at the International University, focusing on Fourier Analysis of Discrete-Time Signals. It includes a grading checklist, team contributions, a table of contents, discussions on discrete-time signals, the Discrete-Time Fourier Transform (DTFT), and experimental procedures with results for various problems. The report details the objectives, processes, and outcomes of experiments involving DTFT and DFT calculations using MATLAB.

Uploaded by

ngannguyen999xxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views26 pages

Lab_6

This document is a laboratory report for a Digital Signal Processing course at the International University, focusing on Fourier Analysis of Discrete-Time Signals. It includes a grading checklist, team contributions, a table of contents, discussions on discrete-time signals, the Discrete-Time Fourier Transform (DTFT), and experimental procedures with results for various problems. The report details the objectives, processes, and outcomes of experiments involving DTFT and DFT calculations using MATLAB.

Uploaded by

ngannguyen999xxx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

International University

School of Electrical Engineering

Digital Signal Processing Laboratory

EE093IU

FOURIER ANALYSIS OF DISCRETE- TIME


SIGNALS

Submitted by

Student Name Student ID

Lê Tiến Phát ITITIU21273

Nguyễn Ngọc Ngân SESEIU21025

Date Performed: 16/05/2025


Date Submitted: 06/06/2025
Lab Section: Lab 5
Course Instructor: M. Eng Nguyen Minh Thien
International University 1
EE093IU
School of CSE
GRADING CHECKLIST

Number Content Satisfied? Score Comment


Format (max 9%)
- Font type Yes No
1
- Font size Yes No

- Lab title Yes No

- Page number Yes No

- Table of contents Yes No

- Header/Footer Yes No

- List of figures (if exists) Yes No

- List of tables (if exists) Yes No

- Lab report structure Yes No

2 English Grammar and Spelling (max 6%)


- Grammar Yes No

- Spelling Yes No

3 Data and Result Analysis (max 85%)

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

Discrete-Time Signals and Systems


A discrete-time system is any device or algorithm that takes a discrete-time signal x[n] as
input and produces another discrete-time signal y[n] as output. The signals are sequences defined
only at integer time indices n, representing samples of a continuous-time signal or inherently
discrete data. The discrete-time signals involve recognizing sequences, such as unit impulse
(𝛿[n]) and unit step (u[n]), which are fundamental for defining system inputs, such as computing
transfer functions from impulse responses. Familiarity with the unit step function u[n], which is 1
for n ≥ 0 and 0 otherwise, as used in Example 2 (x[n] = 0. 6𝑛 𝑢[𝑛]).
Recognize the difference between finite-length sequences (e.g.,
x[n] for 0 ≤ n ≤ N−1) and infinite-length sequences, and how they
affect Fourier transform computations.

Discrete-Time Fourier Transform - DTFT

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π.

The inverse transform to recover x[n] from X(ω):

Properties:

● Periodicity: X(ω) is periodic with period 2π.


● Existence: The DTFT exists if the signal x[n] is absolutely summable(∑∞
𝑛=−∞ |𝑥[𝑛]| <
∞).
● Magnitude and Phase: X(ω) is complex-valued, so you need to understand how to
compute and interpret its magnitude ∣X(ω)∣ and phase ∠X(ω).

Discrete-Time Fourier Transform - DTFT


The DFT is a sampled version of the DTFT, computed for a finite-length sequence x[n]
of length N:

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:

● 𝑋𝑘 is a sequence of complex numbers, with magnitude ∣𝑋𝑘 ∣ and


phase ∠𝑋𝑘 .
● Real and imaginary parts: 𝑋𝑘 =Re{𝑋𝑘 } + jIm{𝑋𝑘 }, where:

Fast Fourier Transform - FFT

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.

Continuous-Time Fourier Transform - CTFT

For a continuous-time signal x(t), the CTFT is:

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.

Convolution and Frequency Domain


Understand that the convolution of two sequences 𝑥1 [𝑛](length 𝑁1 ) and 𝑥2 [𝑛] (length 𝑁2 )
results in a sequence of length 𝑁1 + 𝑁2 − 1. Convolution via FFT

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 =

44 (due to spectral symmetry).


1. Declare signal x[n] and calculate DFT by fft(), it returns the DFT of x[n], that mean
𝑋𝑘 , the complex number with amplitude and phase information.
2. Draw a 4-part graph
- Magnitude: abs(Xk)
- Angle: angle(Xk)
- Real part: real(Xk)
- Imaginary part: imag(Xk)
Problem 3:

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:

a. Plot the frequency response of the given circuit


b. Interchange R and C, plot the frequency response, and explain what happens
c. Generate a 7 Hz square signal, apply it to the low-pass RC circuit, and plot the
response Vo
d. Apply the same square signal to the high-pass RC circuit and compare with part
(c)

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+𝑗𝜔𝑅𝐶.

c. Use square(2 * pi * f_signal * t) to generate a square wave with frequency 7 Hz,


sampled at 2000 Hz over 1 second. This produces a signal alternating between +1
2𝜋𝑘𝑓𝑠
and -1. Compute H(ω) at the DFT frequencies 𝜔𝑘 = . Compute the DFT of
𝑁
the input using fft, multiply by H(ω), and compute the IDFT using ifft to get the
time-domain output.
d. The high-pass filter emphasizes high-frequency components, so the output retains
the sharp transitions of the square wave (high-frequency content) but attenuates the
DC and low-frequency components. The output may appear as a series of spikes at
the transitions of the square wave, with a reduced DC offset. (The low-pass filter
produces a smoother output, while the high-pass filter highlights the edges of the
square wave, resulting in a waveform with pronounced transients.)

International University 8
EE093IU
School of CSE
Experimental Results

Problem 1:

clear all; close all;

% Define signal
n = 0:10;
x = cos(pi * n / 3);

% Symbolic DTFT
syms w
X = sum(x .* exp(-j * w * n));

% Plot magnitude over [-3pi, 3pi]


figure;
ezplot(abs(X), [-3*pi 3*pi]);
title('Magnitude of DTFT over [-3\pi, 3\pi]');
ylim([0 5.4]);

% Plot phase over [-3pi, 3pi]


figure;
w1 = -3*pi:0.01:3*pi;
XX = subs(X, w, w1);
plot(w1, angle(XX));
title('Phase of DTFT over [-3\pi, 3\pi]');
xlim([-3*pi 3*pi]);

% Plot magnitude over [-7pi, 7pi]


figure;
ezplot(abs(X), [-7*pi 7*pi]);
title('Magnitude of DTFT over [-7\pi, 7\pi]');
ylim([0 5.4]);

% Plot phase over [-7pi, 7pi]


figure;
w1 = -7*pi:0.01:7*pi;
XX = subs(X, w, w1);
plot(w1, angle(XX));
title('Phase of DTFT over [-7\pi, 7\pi]');
xlim([-7*pi 7*pi]);

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:

clear all; close all;

% 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]);

% Plot real part


figure;
stem(0:N-1, real(Xk));
title('Real Part of DFT');
xlabel('k'); ylabel('Re\{X_k\}');
xlim([-0.5 64.5]);

% Plot imaginary part


figure;
stem(0:N-1, imag(Xk));
title('Imaginary Part of DFT');
xlabel('k'); ylabel('Im\{X_k\}');
xlim([-0.5 64.5]);

Result

Figure 5. Result of the program in Problem 2 – Magnitude of DFT.

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:

clear all; close all;

% 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

Figure 9. Result of the program in Problem 3 – Magnitude of DTFT and DFT.

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

%% Part a: Frequency response of RC circuit (Low-pass filter)


% Create frequency vector (in Hz)
f = linspace(0, fs/2, N);
omega = 2*pi*f; % Angular frequency

% Calculate transfer function H(j?) for RC circuit (low-pass filter)


H_RC = 1./(1 + 1j*omega*R*C);

% Calculate magnitude and phase


mag_RC = abs(H_RC);
phase_RC = angle(H_RC)*180/pi; % Convert to degrees

% Plot frequency response (magnitude)


figure(1);

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;

% Plot frequency response (phase)


subplot(2,1,2);
semilogx(f, phase_RC, 'LineWidth', 1.5);
title('RC Circuit (Low-Pass Filter): Phase Response');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;

%% Part b: Frequency response of CR circuit (High-pass filter)


% Calculate transfer function H(j?) for CR circuit (high-pass filter)
H_CR = 1j*omega*R*C./(1 + 1j*omega*R*C);

% Calculate magnitude and phase


mag_CR = abs(H_CR);
phase_CR = angle(H_CR)*180/pi; % Convert to degrees

% Plot frequency response (magnitude)


figure(2);
subplot(2,1,1);
semilogx(f, 20*log10(mag_CR), 'LineWidth', 1.5);
title('CR Circuit (High-Pass Filter): Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
grid on;

% Plot frequency response (phase)


subplot(2,1,2);
semilogx(f, phase_CR, 'LineWidth', 1.5);
title('CR Circuit (High-Pass Filter): Phase Response');
xlabel('Frequency (Hz)');
ylabel('Phase (degrees)');
grid on;

%% Part c: Square wave response of RC circuit


% Generate time vector
duration = 1; % 1 second duration
t = 0:1/fs:duration-1/fs;
N_time = length(t);

% Generate square wave input


input_signal = square(2*pi*f_square*t);

% Calculate impulse response of RC circuit (low-pass filter)


tau_RC = R*C; % Time constant
h_RC = (1/tau_RC)*exp(-t/tau_RC);

% Calculate output using convolution (time-domain)


% We could use frequency domain multiplication but this is more direct
International University 20
EE093IU
School of CSE
output_RC = conv(input_signal, h_RC);
output_RC = output_RC(1:N_time); % Truncate to same length as input

% Plot Input and Output for RC circuit


figure(3);
subplot(2,1,1);
plot(t, input_signal, 'b', 'LineWidth', 1);
hold on;
plot(t, output_RC, 'r', 'LineWidth', 1.5);
title('RC Circuit (Low-Pass): Square Wave Response');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Input (Square Wave)', 'Output Response');
grid on;

%% Part d: Square wave response of CR circuit


% Calculate impulse response of CR circuit (high-pass filter)
h_CR = [1, -exp(-t(2:end)/tau_RC)]; % Impulse response of CR circuit

% Calculate output using convolution (time-domain)


output_CR = conv(input_signal, h_CR);
output_CR = output_CR(1:N_time); % Truncate to same length as input

% Plot Input and Output for CR circuit


subplot(2,1,2);
plot(t, input_signal, 'b', 'LineWidth', 1);
hold on;
plot(t, output_CR, 'r', 'LineWidth', 1.5);
title('CR Circuit (High-Pass): Square Wave Response');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Input (Square Wave)', 'Output Response');
grid on;

%% Alternative implementation using frequency domain multiplication


% This provides a more accurate calculation of the circuit response
% especially for the CR (high-pass) filter

% Compute DFT of input signal


X = fft(input_signal);

% Compute transfer function for RC filter at the DFT frequencies


omega_dft = 2*pi*(0:N_time-1)*fs/N_time;
H_RC_dft = 1./(1 + 1j*omega_dft*R*C);

% Compute output for RC filter


Y_RC = X .* H_RC_dft;
y_RC = real(ifft(Y_RC));

% Compute transfer function for CR filter at the DFT frequencies


H_CR_dft = 1j*omega_dft*R*C./(1 + 1j*omega_dft*R*C);

% Compute output for CR filter


Y_CR = X .* H_CR_dft;
y_CR = real(ifft(Y_CR));
International University 21
EE093IU
School of CSE
% Plot the results
figure(4);
subplot(2,1,1);
plot(t, input_signal, 'b', 'LineWidth', 1);
hold on;
plot(t, y_RC, 'r', 'LineWidth', 1.5);
title('RC Circuit (Low-Pass): Square Wave Response (Frequency Domain Method)');
xlabel('Time (s)');
ylabel('Amplitude');
legend('Input (Square Wave)', 'Output Response');
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.

Difficulties and Solutions

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.

Direct DFT/IDFT implementations using loops produce small numerical errors in


imaginary parts due to floating-point arithmetic. Use MATLAB’s fft and ifft for higher precision
and efficiency. Apply real() to eliminate negligible imaginary components.

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

You might also like