EBEE 4092 Digital Signal Processing
Final Awarded Marks
Lab :1
Title : Discrete time signals and systems
Total Marks : 10%
Class : September 2024
Due Date : 24 October 2024
Date submitted : 25 october 2024
NAME : Ahmed kamal Moahmed Ibrahim Elnaggar Student ID:0127378
Submission Checklist (To be filled-up by marker)
Report
MATLAB Program
Turn-It-In Report
Extension Granted (YES/NO)
Overall Comments:
Signature : ____________________
Marker : Tan Sin Jin
Date :
Lab Exercise Assessments (Section Allocated Marks: 5)
Allocated Awarded
No Assessment Criteria
Marks Marks
Lab Exercise (LO2, PO5):
1. 10
a) Discrete time signal plotting
Report (Section Allocated Marks: 50)
Allocated Awarded
No Assessment Criteria
Marks Marks
Matlab codes (LO2, PO5)
1. 15
2. Theoretical calculation (LO1, PO2) 10
Output graphs (LO2, PO5)
3. 15
Discussion (LO1, PO2)
4. 30
5. Conclusion (LO1, PO2) 10
Language, writing styles, chapters arrangement and
6. 10
formatting (LO1, PO2)
Section Awarded Marks
Assessment and Learning Outcome Mapping
Learning Outcome Assignment 1
LO1 Analyse discrete time signals and systems using 60%
appropriate signals transformation and spectral analysis
techniques.
LO2 Use modern computation software to implement digital 40%
signal processing operations on one dimensional signal.
LO3 Design different frequency selective digital filters to meet -
a set of frequency domain specification.
Assessment and Programme Outcome Mapping
Programme Outcome
Assessment
1 2 3 4 5 6 7 8 9 10 11 12
Lab 1 √ √
Assessment and Knowledge Profile Mapping
Assessment WK 1 WK 2 WK 3 WK 4 WK 5 WK 6 WK 7 WK 8
Lab 1
Assessment and Complex Problem Solving Attribute Mapping
Assessment WP 1 WP 2 WP 3 WP 4 WP 5 WP 6 WP 7 WP 8
Lab 1
Assessment and Complex Engineering Activities Attribute Mapping
Assessment EA1 EA2 EA3 EA4 EA5
Lab 1
Student Statement:
I/we have read and understood the rules on academic dishonest and
plagiarism in the Programme Handbook.
I/we understand that plagiarism is the presentation of the work, idea or
creation of another person as though it is your own. It is a form of cheating and is a
very serious academic offence that may lead to expulsion from the University.
Plagiarised material can be drawn from, and presented in, written, graphic and
visual form, including electronic data, and oral presentations. Plagiarism occurs
when the origin of the material used is not appropriately cited.
I/we understand the rules and am aware of the consequences which may
follow if I breach those rules.
I/we have taken proper care of safeguarding this work and make all
reasonable effort to ensure it could not be copied.
I/we certify that I have not plagiarised the work of others or participated in
unauthorised collaboration when preparing this assignment.
I/we declare that the attached assignment my/our original work and no part
of it has been copied from any other student’s work or from any other source except
where due acknowledgment is made.
Signature : _______________________
Date : _25 october 2024
Lab Exercise
b
Lab Assignment
1 A) Code and graph are shown below
B) Code and graphs are shown below
C) Code and graph are shown below
Theoretical Analysis
Frequency Components:
o The cosine term Xcos(2π×50n/fs)X \cos(2 \pi \times 50 n /
fs)Xcos(2π×50n/fs) has peaks at 50 Hz and 950 Hz.
o The sine term 2sin(2π×150n/fs)2 \sin(2 \pi \times 150 n /
fs)2sin(2π×150n/fs) has peaks at 150 Hz and 850 Hz.
• Expected Magnitudes:
o At 50 Hz and 950 Hz, the magnitude is X/2X/2X/2.
o At 150 Hz and 850 Hz, the magnitude is 2/2=12/2 = 12/2=1.
Given X=8X = 8X=8:
• 4 at 50 Hz and 950 Hz
• 1 at 150 Hz and 850 Hz
• Comparison with FFT Results: The FFT results were plotted with theoretical
peaks marked in red. The match between theoretical and FFT values validates
the frequency and magnitude calculations.
Frequency (Hz) Theoretical Magnitude
50 4
150 1
850 1
950 4
D) Code and graphs are shown below
E) Code and graph are shown below
F) Code and graphs are shown below
g)
The additional noise in x3[n]x_3[n]x3[n] is Gaussian white noise with:
Variance: 0.5, indicating the spread of the noise levels. The standard deviation, derived as the
square root of the variance, is around 0.707. This indicates that the majority of noise values
fall within ±0.707 of the mean.
Mean: Approximately 0, signifying that the noise fluctuates evenly around zero without a
persistent bias in direction.
This noise emulates random disturbances that may arise in actual digital signal applications,
making it appropriate for assessing signal-processing techniques, particularly in evaluating
filter efficacy for noise reduction.
Within the framework of this experiment, the noise introduced to x2[n] results in x3[n], a
distorted iteration of the original signal. This version simulates the appearance of genuine
signals influenced by random external influences, such sensor mistakes or environmental
interference. The DTFT analysis conducted on x3[n] demonstrates the influence of noise on
the signal's frequency characteristics, as seen by the fluctuations in amplitude and phase
across frequencies.
H) Code and graphs are shown below
I) Code and graphs are shown below
J) Code and graphs are shown below
Discussion and Conclusion
In this laboratory assignment, the discrete-time signal x2[n] = Xcos(2π ×
50n/fs).+2sin(2π × 150n/fs)x2[n] = Xcos(2π×50n/fs) + 2sin(2π×150n/fs) was examined
through many stages, that involve theoretical analysis, FFT implementation, noise
incorporation, and filtering, enabling an extensive exploration of digital signal
processing concepts and methodologies.
Analysis of Frequency: The FFT was crucial in determining the frequency components of
the data, with peaks at 50 Hz, 150 Hz, 850 Hz, and 950 Hz. The results closely matched
theoretical expectations, demonstrating the FFT's capability to correctly divide signals
into their frequency components. This is crucial in DSP applications, where the
identification and analysis of specific frequency content are vital, especially in
communications and audio processing.
The impact of Noise: The introduction of Gaussian noise with a variance of 0.5 resulted
in substantial oscillations in both the temporal and frequency domains. This noise
demonstrated genuine interference, which digital signals frequently experience owing
to ambient variables or system constraints. Analyzing the noisy signal in the frequency
domain revealed the dispersion of noise across frequencies, which might hide or
diminish the quality of the original signal. This step highlighted the significance of noise-
reduction strategies in maintaining signal integrity, particularly in sensitive applications
such as medical imaging or wireless transmission.
Effectiveness of Filtering and Signal Smoothing
The implementation of 3-point and 6-point moving average filters yielded a comparative
analysis of their effectiveness in noise reduction. The 3-point filter provided
fundamental smoothing, diminishing small variations while maintaining the essential
signal structure. Conversely, the 6-point filter generated a more refined signal by further
diminishing high-frequency noise, but at the expense of significantly diminishing the
signal's detail clarity. The trade-off between noise reduction and signal fidelity is a
crucial factor in filter design, particularly in domains necessitating both high signal
clarity and noise resilience, such as radar and voice processing.
Conclusion
This laboratory experiment effectively illustrated fundamental principles in discrete-
time signal processing. The congruence of theoretical and FFT findings confirmed the
precision of our methodology, while the juxtaposition of noisy and filtered signals
highlighted the difficulties presented by noise and the significance of filtering
approaches. Grasping the right balance between noise attenuation and signal retention
is essential in digital signal processing and emphasizes the necessity of choosing
suitable filters according to the signal characteristics and application requirements.
Therefore, this exercise yielded practical insights into signal decomposition, noise
influence, and filtering, therefore providing a core comprehension of the tools and
techniques of digital signal processing.
Lab Exercise coding
%1A
n = [0:1:10]; %assigning the range
f=0.8.^n; %assigning signal using student number 0129498
figure(1); %graph plotting
stem(n,f,'filled'); grid;
title('discrete time signal 1A'); %titling the graph
ylabel('amplitude') %labelling the y axis
xlabel('n') %labelling the x axis
Lab exercise (b) MATLAB code.
%1B
n = [0:1:15]; %assigning the range
f = 8*cos((0.4*pi*n)+(pi/4)) %assigning the signal
figure(1); %plotting the signal
stem(n,f,'filled'); grid;
title('discrete time signal 1B');%labelling the graph
ylabel('amplitude'); %labelling the y axis
xlabel('n'); %labelling the x axis
Lab assignment
Coding
1a
%1a Generate discrete time signal x1[n] = delta[n] + delta[n-2]
n = -5:10; % Define the range of n
x1 = (n == 0) + (n == 2); % Generate delta functions
% Plot the signal
figure;
stem(n, x1, 'filled');
title('Discrete Time Signal x1[n] = \delta[n] + \delta[n-2]');
xlabel('n');
ylabel('x1[n]');
grid on;
1b
% 1b Assuming X is the last digit of your student number
X = 8; % Replace with your actual value
% Generate the signal
n = 0:1023; % Define n from 0 to 1023 for 1024 points
fs = 1000; % Sampling frequency (1000 Hz)
x2 = X * cos(2 * pi * 50 * n / fs) + 2 * sin(2 * pi * 150 * n / fs);
% Compute the DFT using FFT
NFFT = 1024; % Number of FFT points
X2_fft = fft(x2, NFFT);
% Calculate magnitude and phase
magnitude = abs(X2_fft);
phase = angle(X2_fft);
% Frequency axis (normalized to [0, 1] or [0, fs/2] in Hz)
f = (0:NFFT-1) * (fs / NFFT);
% Figure 1: Plot the magnitude only
figure(1);
plot(f, magnitude, 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT');
grid on;
% Figure 2: Plot the phase only
figure(2);
plot(f, phase, 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT');
grid on;
% Figure 3: Combined Magnitude and Phase Plot
figure(3);
yyaxis left;
plot(f, magnitude, 'b'); % Plot magnitude with blue color
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude and Phase of DTFT');
grid on;
yyaxis right;
plot(f, phase, 'r'); % Plot phase with red color
ylabel('Phase (radians)');
legend('Magnitude', 'Phase');
1c
% 1C Assuming X is the last digit of your student number
X = 8; % Replace with your actual value
% Generate the signal
n = 0:1023; % Define n from 0 to 1023 for 1024 points
fs = 1000; % Sampling frequency (1000 Hz)
x2 = X * cos(2 * pi * 50 * n / fs) + 2 * sin(2 * pi * 150 * n / fs);
% Compute the DFT using FFT
NFFT = 1024; % Number of FFT points
X2_fft = fft(x2, NFFT);
% Calculate magnitude and phase
magnitude = abs(X2_fft);
phase = angle(X2_fft);
% Frequency axis (normalized to [0, 1] or [0, fs/2] in Hz)
f = (0:NFFT-1) * (fs / NFFT);
% Plot the magnitude for comparison
figure;
plot(f, magnitude, 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT and Theoretical Peaks');
grid on;
% Hold the plot to add theoretical values
hold on;
% Theoretical Peaks
theoretical_frequencies = [50, 150, fs - 50, fs - 150];
theoretical_magnitudes = [X/2, 2/2, X/2, 2/2]; % Magnitude of cosine and sine
components
% Plot the theoretical peaks
stem(theoretical_frequencies, theoretical_magnitudes, 'r', 'LineWidth', 2);
legend('FFT Magnitude', 'Theoretical Peaks');
1D
% Task D: Generate and Analyze the Signal x2[n]
% Assuming X is the last digit of your student number
X = 8; % Replace with your actual value
% Define the parameters for x2[n]
n = 0:100; % Define n from 0 to 100 for 101 points
fs = 1000; % Sampling frequency (1000 Hz)
% Generate the signal x2[n]
x2 = X * cos(2 * pi * 50 * n / fs) + 2 * sin(2 * pi * 150 * n / fs);
% Plot x2[n]
figure(1); % Create a new figure with handle 1
stem(n, x2, 'filled');
xlabel('n');
ylabel('x2[n]');
title('Discrete-Time Signal x2[n]');
grid on;
% Compute the DFT using FFT for x2[n]
NFFT = 1024; % Number of FFT points
X2_fft = fft(x2, NFFT);
% Frequency axis (normalized to [0, 1] or [0, fs/2] in Hz)
f = (0:NFFT-1) * (fs / NFFT);
% Calculate magnitude and phase of X2[n]
magnitude = abs(X2_fft);
phase = angle(X2_fft);
% Figure 2: Plot the magnitude only
figure(2);
plot(f, magnitude, 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT for x2[n]');
grid on;
% Figure 3: Plot the phase only
figure(3);
plot(f, phase, 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT for x2[n]');
grid on;
1E
% Task E: Plotting Signal and DTFT with Sampling Frequency
% Re-generate the signal x2[n] for n = 0 to 100
n = 0:100; % Define n from 0 to 100
fs = 1000; % Sampling frequency (1000 Hz)
% Generate the signal x2[n]
x2 = X * cos(2 * pi * 50 * n / fs) + 2 * sin(2 * pi * 150 * n / fs);
% Plot x2[n]
figure(4);
stem(n, x2, 'filled');
xlabel('n');
ylabel('x2[n]');
title('Discrete-Time Signal x2[n] for n = 0 to 100');
grid on;
% Compute the DTFT using FFT for x2[n]
NFFT = 1024; % Number of FFT points
X2_fft = fft(x2, NFFT);
% Frequency axis in Hz
f = (0:NFFT-1) * (fs / NFFT);
% Calculate magnitude and phase of X2_fft
magnitude = abs(X2_fft);
phase = angle(X2_fft);
% Figure 5: Plot the magnitude spectrum of DTFT for x2[n]
figure(5);
plot(f, magnitude, 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT for x2[n]');
grid on;
% Figure 6: Plot the phase spectrum of DTFT for x2[n]
figure(6);
plot(f, phase, 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT for x2[n]');
grid on;
% Figure 7: Combined Magnitude and Phase Plot for x2[n]
figure(7);
yyaxis left;
plot(f, magnitude, 'b'); % Plot magnitude with blue color
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude and Phase of DTFT for x2[n]');
grid on;
yyaxis right;
plot(f, phase, 'r'); % Plot phase with red color
ylabel('Phase (radians)');
legend('Magnitude', 'Phase');
1F
% Task F: Add Random Noise to the Signal and Analyze
% Assuming X is the last digit of your student number
X = 8; % Replace with your actual value
% Define the parameters for x2[n]
n = 0:100; % Define n from 0 to 100 for 101 points
fs = 1000; % Sampling frequency (1000 Hz)
% Generate the signal x2[n]
x2 = X * cos(2 * pi * 50 * n / fs) + 2 * sin(2 * pi * 150 * n / fs);
% Add random noise with variance 0.5 to x2[n] to create x3[n]
noise = sqrt(0.5) * randn(size(n));
x3 = x2 + noise; % Noisy signal
% Plot x3[n]
figure(1);
stem(n, x3, 'filled');
xlabel('n');
ylabel('x3[n]');
title('Discrete-Time Signal x3[n] (Noisy Signal)');
grid on;
% Compute the DFT using FFT for x3[n]
NFFT = 1024; % Number of FFT points
X3_fft = fft(x3, NFFT);
% Frequency axis (normalized to [0, 1] or [0, fs/2] in Hz)
f = (0:NFFT-1) * (fs / NFFT);
% Calculate magnitude and phase of X3[n]
magnitude = abs(X3_fft);
phase = angle(X3_fft);
% Figure 2: Plot the magnitude spectrum of DTFT for x3[n]
figure(2);
plot(f, magnitude, 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT for x3[n]');
grid on;
% Figure 3: Plot the phase spectrum of DTFT for x3[n]
figure(3);
plot(f, phase, 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT for x3[n]');
grid on;
% Figure 4: Combined Magnitude and Phase Plot for x3[n]
figure(4);
yyaxis left;
plot(f, magnitude, 'b'); % Plot magnitude with blue color
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude and Phase of DTFT for x3[n] (Noisy Signal)');
grid on;
yyaxis right;
plot(f, phase, 'r'); % Plot phase with red color
ylabel('Phase (radians)');
legend('Magnitude', 'Phase');
1i
% Task I: Create 3-Point and 6-Point Moving Average Filters and Plot Their DTFT
% Assuming X is the last digit of your student number
X = 8; % Replace with your actual value
% Define the parameters for x2[n]
n = 0:100; % Define n from 0 to 100 for 101 points
fs = 1000; % Sampling frequency (1000 Hz)
% Generate the signal x2[n]
x2 = X * cos(2 * pi * 50 * n / fs) + 2 * sin(2 * pi * 150 * n / fs);
% Add random noise with variance 0.5 to x2[n] to create x3[n]
noise = sqrt(0.5) * randn(size(n));
x3 = x2 + noise; % Noisy signal
% Create 3-point and 6-point moving average filters
h3 = (1/3) * ones(1, 3); % 3-point moving average filter
h6 = (1/6) * ones(1, 6); % 6-point moving average filter
% Plot the impulse response of 3-point filter
figure(1);
stem(0:2, h3, 'filled');
xlabel('n');
ylabel('h3[n]');
title('Impulse Response of 3-Point Moving Average Filter');
grid on;
% Plot the impulse response of 6-point filter
figure(2);
stem(0:5, h6, 'filled');
xlabel('n');
ylabel('h6[n]');
title('Impulse Response of 6-Point Moving Average Filter');
grid on;
% Compute the DTFT of the 3-point filter using FFT
NFFT = 1024; % Number of FFT points
H3_fft = fft(h3, NFFT);
% Frequency axis (normalized to [0, 1] or [0, fs/2] in Hz)
f = (0:NFFT-1) * (fs / NFFT);
% Plot the magnitude spectrum of DTFT for 3-point filter
figure(3);
plot(f, abs(H3_fft), 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT for 3-Point Moving Average Filter');
grid on;
% Compute the DTFT of the 6-point filter using FFT
H6_fft = fft(h6, NFFT);
% Plot the magnitude spectrum of DTFT for 6-point filter
figure(4);
plot(f, abs(H6_fft), 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT for 6-Point Moving Average Filter');
grid on;
% Plot the phase spectrum of DTFT for 3-point filter
figure(5);
plot(f, angle(H3_fft), 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT for 3-Point Moving Average Filter');
grid on;
% Plot the phase spectrum of DTFT for 6-point filter
figure(6);
plot(f, angle(H6_fft), 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT for 6-Point Moving Average Filter');
grid on;
1J
% Task J: Apply Moving Average Filters to Signal x3[n] and Plot the Output
% Assuming X is the last digit of your student number
X = 8; % Replace with your actual value
% Define the parameters for x2[n]
n = 0:100; % Define n from 0 to 100 for 101 points
fs = 1000; % Sampling frequency (1000 Hz)
% Generate the signal x2[n]
x2 = X * cos(2 * pi * 50 * n / fs) + 2 * sin(2 * pi * 150 * n / fs);
% Add random noise with variance 0.5 to x2[n] to create x3[n]
noise = sqrt(0.5) * randn(size(n));
x3 = x2 + noise; % Noisy signal
% Create 3-point and 6-point moving average filters
h3 = (1/3) * ones(1, 3); % 3-point moving average filter
h6 = (1/6) * ones(1, 6); % 6-point moving average filter
% Apply 3-point moving average filter to x3[n]
y3 = filter(h3, 1, x3);
% Apply 6-point moving average filter to x3[n]
y6 = filter(h6, 1, x3);
% Plot the output signal y3[n] after 3-point filter in time domain
figure(1);
stem(n, y3(1:length(n)), 'filled');
xlabel('n');
ylabel('y3[n]');
title('Output Signal y3[n] after 3-Point Moving Average Filter');
grid on;
% Plot the output signal y6[n] after 6-point filter in time domain
figure(2);
stem(n, y6(1:length(n)), 'filled');
xlabel('n');
ylabel('y6[n]');
title('Output Signal y6[n] after 6-Point Moving Average Filter');
grid on;
% Compute the DTFT using FFT for y3[n]
NFFT = 1024; % Number of FFT points
Y3_fft = fft(y3, NFFT);
% Frequency axis (normalized to [0, 1] or [0, fs/2] in Hz)
f = (0:NFFT-1) * (fs / NFFT);
% Plot the magnitude spectrum of DTFT for y3[n]
figure(3);
plot(f, abs(Y3_fft), 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT for y3[n] after 3-Point Filter');
grid on;
% Compute the DTFT using FFT for y6[n]
Y6_fft = fft(y6, NFFT);
% Plot the magnitude spectrum of DTFT for y6[n]
figure(4);
plot(f, abs(Y6_fft), 'b');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude of DTFT for y6[n] after 6-Point Filter');
grid on;
% Plot the phase spectrum of DTFT for y3[n]
figure(5);
plot(f, angle(Y3_fft), 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT for y3[n] after 3-Point Filter');
grid on;
% Plot the phase spectrum of DTFT for y6[n]
figure(6);
plot(f, angle(Y6_fft), 'r');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
title('Phase of DTFT for y6[n] after 6-Point Filter');
grid on;
Turnitin