Ahsanullah University of Science and Technology
Department of Electrical and Electronic Engineering
LAB REPORT
❖ Course No.: EEE 3218
❖ Course Title: Digital Signal Processing Lab
❖ Date of Submission: 02 July, 2025
Submitted By-
• Name: Mahmud Hasan Sami
• Student No.: 20220105094
• Year: 3rd
• Semester: 2nd
• Section: B-2
• Session: Fall 2024
• Programme: B.Sc in EEE
Post Lab:1- Sample Problem-1(a):- Plotting:
clear all;
close all;
clc;
x=1:0.1:10;
y=x.^2+2*x+5*x.*sin(x);
plot(x,y,'Linewidth',3);
Sample Problem-1(a):- Sub-plotting:
clear all;
close all;
clc;
t=-10:0.01:10;
signal1=t.^2+9*t+2;
signal2=t.^3+4*t.^2+5*t;
subplot(211);
plot(t,signal1,'Linewidth',2);
subplot(212);
plot(t,signal2,'Linewidth',2);
Sample Problem-2:-
clear all;
close all;
clc;
f=10000;
A=2;
t= (0:10^-8:1*10^-3);
y1=A*sin(2*pi*f*t);
subplot(411)
plot(t,y1,'Linewidth',2)
title('10 kHz Sinusoidal signal using sin()Function');
xlabel('Time(s)');
ylabel('Amplitude');
y2=A*cos(2*pi*f*t);
subplot(412)
plot(t,y2,'Linewidth',2)
title('10 kHz Sinusoidal signal using cos()Function');
xlabel('Time(s)');
ylabel('Amplitude');
y3=A*sind(360*f*t);
subplot(413)
plot(t,y3,'Linewidth',2)
title('10 kHz Sinusoidal signal using sind()');
xlabel('Time(s)');
ylabel('Amplitude');
y4=A*cosd(360*f*t);
subplot(414)
plot(t,y4,'Linewidth',2)
title('10 kHz Sinusoidal signal using cosd()');
xlabel('Time(s)');
ylabel('Amplitude');
Sample Problem-3:-
clear all;
close all;
clc;
f=1;
A=10;
initial_value=A/sqrt(2);
phi=pi/4; % Phase to start at A/sqrt(2)
T=1/f;
N=4; %4 Cycles
t=0:0.01:N*T;
y1=A*sin(2*pi*f*t+phi);
subplot(221)
plot(t,y1,'Linewidth',2)
title('1 Hz Sinusoidal signal using sin()');
xlabel('Time(s)');
ylabel('Amplitude');
y2=A*cos(2*pi*f*t+phi);
subplot(222)
plot(t,y2,'Linewidth',2)
title('1 Hz Sinusoidal signal using cos()');
xlabel('Time(s)');
ylabel('Amplitude');
phi_degree=45;
Degree=360*f*t+phi_degree;
y3=A*sind(Degree);
subplot(223)
plot(t,y3,'Linewidth',2)
title('1 Hz Sinusoidal signal using sind()');
xlabel('Time(s)');
ylabel('Amplitude');
y4=A*cosd(Degree);
subplot(224)
plot(t,y4,'Linewidth',2)
title('1 kHz Sinusoidal signal using cosd()');
xlabel('Time(s)');
ylabel('Amplitude');
Sample Problem-4:-
clear all;
close all;
clc;
t=linspace(-pi,pi);
A=1;
y=A*sin(t);
plot(t,y);
xlabel('Angle');
ylabel('Amplitude')
Question-Answer (LAB 1)
1) Can you mention name of some physical signals along with
their responding human organ? Are they Analog or Digital?
Ans: The human body interacts with its environment through
various physical signals, which are detected by specific organs.
These signals are typically analog in nature, meaning they vary
continuously over time rather than switching abruptly between
fixed states like digital signals. Example: Sound Waves, Light,
Temperature.
2) Are the terms data and signal synonyms? Briefly clarify with
example
Ans: No. Data is the raw information or message that we want
to transmit. Besides, Signal is the physical form used to carry
the data over a medium (like air, wire, fiber optics). It can be
electrical, optical, or electromagnetic.
3) Do you think all digital data are always represented by 1 and
0 only ? Briefly Clarify.
Ans: Digital data is always conceptually binary (based on 1 and
0), the actual representation depends on the medium and
technology used. The 1s and 0s are abstract symbols that map
to different physical states.
4) When speed of processing is the only factor to be considered,
whether Analog or Digital Processing should be used? Why?
Ans: If only speed is considered (ignoring other factors like
accuracy, flexibility, or noise immunity), then analog processing
is preferred due to its immediate and continuous nature.
5) Which processing requires less power? Analog or Digital?
Why?
Ans: Digital processing usually requires less power than analog
because: Digital circuits work in discrete steps, not
continuously.They can be optimized for low-power operation.
Pre-Lab Task (Lab 2):
Ahsanullah University of Science and Technology
Department of Electrical and Electronic Engineering
LAB REPORT
❖ Course No.: EEE 3218
❖ Course Title: Digital Signal Processing Lab
❖ Date of Submission: 09 July 2025
Submitted By-
• Name: Mahmud Hasan Sami
• Student No.: 20220105094
• Year: 3rd
• Semester: 2nd
• Section: B2
• Session: Fall 2024
• Programme: B.Sc in EEE
Problem 1: (Modifying sigadd→ Sigmult to multiply two signals)
Modified Function- sigmult:
function [y, y1, y2, n] = sigmult(n1, x1, n2, x2)
n = min(min(n1), min(n2)) : max(max(n1), max(n2));
y1 = zeros(1, length(n));
y2 = y1;
y1((n >= min(n1)) & (n <= max(n1))) = x1;
y2((n >= min(n2)) & (n <= max(n2))) = x2;
% Element-wise multiplication
y = y1 .* y2;
Code to Multiply Two DT signals:
clear all
close all
clc
n1= -2:2;
x1=[1 2 3 4 5]
subplot(311)
stem(n1,x1);
xlim([-3,2]);
n2=-3:1;
x2=[2 3 3 2 1]
subplot(312)
stem(n2,x2);
xlim([-3,2]);
[y, y1, y2, n] = sigmult(n1, x1, n2, x2)
subplot(313)
stem(n,y);
xlim([-3,2]);
Signal Plotting: (Screenshot)
Problem 2: Using function sigfold and sigadd, write a code that will decompose any real signal
into its even and odd counterparts. Plot the component.
Function sigfold:
function [y,n] = sigfold(x, m)
n = -fliplr(m); % generating n = -m index
y = fliplr(x);
end
Function sigadd:
function [y,y1,y2,n] = sigadd(n1, x1, n2, x2)
n = min(min(n1),min(n2)):max(max(n1),max(max(n2)));
y1 = zeros(1, length(n));
y2 = y1;
y1 (((n>=min(n1)) & (n<=max(n1)))) = x1;
y2 (((n>=min(n2)) & (n<=max(n2)))) = x2;
y = y1+y2;
end
To decompose a real signal into its Even and odd Parts (Code):
clear all;
close all;
clc;
n=-4:4;
x=[4,5,8,2,3,5,3,5,6];
subplot(311);
stem(n,x);
title('Original Signal x[n]');
[x1,n1] = sigfold(x, n) %to generate x[-n]
[x2,n2]= sigadd(n,x,n1,x1) %to genearate x[n]+x[-n]
xe=0.5.*x2; %to generate the even part of the signal
subplot(312);
stem(n,xe);
title('Even Part of Signal');
[x3,n3] = sigfold(x, n) %to generate x[-n]
[x4,n4]=sigadd(n,x,n3,-1.*x3)%to genearate x[n]-x[-n].
%Multiplying (-1) to get the Negative DT signals
xo=0.5.*x4;%to generate the odd part of the signal
subplot(313);
stem(n,xo);
title('Odd Part of Signal');
Problem 3: Verify that system2 is non-linear by writing a code just like
the linear one.
System 2 Function Code:
function [y,n] = system2(x,n)
y = x.^2+5*x;
end
Code to verify the system is Non-Linear:
clc;
clear all;
close all;
n = 0:9;
x1 = n+2;
x2 = n;
[y1,n1]=system2(2*x1,n);
[y2,n2]=system2(3*x2,n);
[y3,n3]=system2(2*x1+3*x2,n);
subplot 211
stem(n1,y1+y2,'Linewidth',3);
title('Superposition of the Individual outputs');
subplot 212
stem(n3,y3,'Linewidth',3);
title('Output of the superposition of the inputs');
Problem 4: If x[n]={1,1,2,3, 5", 8,13,21,34,55},using the functions sigfold and sigshift show
i) x[-n-3]
ii) x[-n+4].
Main Code:
clear all
close all
clc;
x=[1,1,2,3,5,8,13,21,34,55];
n=-4:5;
subplot(411)
stem(n,x);
title('Original Signal x[n]');
xlim([-4,5]);
[x1,n1] = sigfold(x, n) %to generate x[-n]
subplot(412)
stem(n1,x1);
title(' x[-n]');
xlim([-4,5]);
[x2,n2] = sigshift(x1,3,n1)
subplot(413)
stem(n2,x2);
title(' Required Signal: x[-n-3]');
xlim([-4,5]);
[x3,n3] = sigshift(x1,-4,n1)
subplot(414)
stem(n3,x3);
title(' Required Signal: x[-n+4]');
xlim([-4,5]);
Problem 5: Are time shifting and time reversal operations commutative? Verify this
by using problem 4.
Main Code:
clear all
close all
clc;
x=[1,1,2,3,5,8,13,21,34,55];
n=-4:5;
subplot(311)
stem(n,x);
title('Main DT Signal');
xlim([-4,5]);
%doing folding 1st then shifting
[x1,n1] = sigfold(x, n)
[x2,n2] = sigshift(x1,n1,3)
subplot(312)
stem(n2,x2);
title('Folding then shifting');
xlim([-4,5]);
%doing shifting 1st then folding
[x3,n3] = sigshift(x,n,3)
[x4,n4]= sigfold(x3,n3)
subplot(313)
stem(n4,x4);
title('Shifting then folding');
xlim([-4,5]);
No, shifting and time reversal are not commutative operations in
discrete-time (DT) signals, meaning the order in which you
apply them matters and will result in different final signals.
Problem-6: Even and odd component of the problem-4 DT
signal:
Main code:
clear all;
close all;
clc;
n=-4:4;
x=[1,1,2,3,5,8,13,21,34];
subplot(311);
stem(n,x);
title('Original Signal x[n]');
[x1,n1] = sigfold(x, n) %to generate x[-n]
[x2,n2]= sigadd(n,x,n1,x1) %to genearate x[n]+x[-n]
xe=0.5.*x2; %to generate the even part of the signal
subplot(312);
stem(n,xe);
title('Even Part of Signal');
[x3,n3] = sigfold(x, n) %to generate x[-n]
[x4,n4]=sigadd(n,x,n3,-1.*x3)%to genearate x[n]-x[-n].
%Multiplying (-1) to get the Negative DT signals
xo=0.5.*x4;%to generate the odd part of the signal
subplot(313);
stem(n,xo);
title('Odd Part of Signal');
Ahsanullah University of Science and Technology
Department of Electrical and Electronic Engineering
LAB REPORT
❖ Course No.: EEE 3218
❖ Course Title: Digital Signal Processing Lab
❖ Date of Submission: 23 July 2025
Submitted By-
• Name: Mahmud Hasan Sami
• Student No.: 20220105094
• Year: 3rd
• Semester: 2nd
• Section: B2
• Session: Fall 2024
• Programme: B.Sc in EEE
Post Lab Tast
Problem 1: (Solution)
clear all;
close all;
clc;
%y1[n]=x[n]*h1[n]
nx=-1:2;
x=[1,2,3,4];
nh1=-3:1;
h1=[1,1,2,3,5];
[y1,n1] = convolution_sum(nx, x, nh1, h1)
subplot(221);
stem(n1,y1);
title('y1[n]=x[n]*h1[n]');
%y2[n]=(x[n]*h1[n])*h2[n])
nh2=-2:1;
h2=[3,4,5,6];
[y2,n2] = convolution_sum(n1, y1, nh2, h2)
subplot(222);
stem(n2,y2);
title('y2[n]=(x[n]*h1[n])*h2[n])');
%y3[n]=h1[n]*h2[n]
[y3,n3] = convolution_sum(nh1, h1, nh2, h2)
subplot(223);
stem(n3,y3);
title('y3[n]=h1[n]*h2[n]');
%y4[n]=x[n]*(h1[n]*h2[n])
[y4,n4] = convolution_sum(nx, x, n3, y3)
subplot(224);
stem(n4,y4);
title('y4[n]=x[n]*(h1[n]*h2[n])');
Plotting:
Problem 2: Solution:
clear all;
close all;
clc;
%y[n]-4y[n-1]+4y[n-2]=x[n]-x[n-1]
%For 2nd order impulse response h[n]-4h[n-1]+4h[n-
2]=delta[n]-delta[n-1]
% assuming causal system h[-1] = h[-2] = ... = 0
n=-20:25;
x=(n==0); %delta[n]
h=zeros(1,length(n));
for i=3:length(n)
h(i)=x(i)-x(i-1)+4*h(i-1)-4*h(i-2);
end
subplot(311)
stem(n,h,'Linewidth', 3)
title('impulse response(by solving diff eqn) when input
was delta[n]')
%if the input was delta function i.e. x[n]= delta[n]
b=[1,-1];
a=[1,-4,4];
x1=(n==0);
h2=filter(b,a,x1);
subplot(312)
stem(n,h2,'Linewidth', 3)
title('impulse response (using filter function) when
input was delta[n]')
%if the input x[n]=(5+ 3cos(0.2pi*n)+4sin(0.6pi*n))u[n]
%using filter function
b=[1,-1];
a=[1,-4,4];
x2=(n>=0);
x3=(5+ 3*cos(0.2*pi*n)+4*sin(0.6*pi*n)).*x2;
h3=filter(b,a,x3);
subplot(313)
stem(n,h3,'Linewidth', 3)
title('impulse response (using filter function) when
input was (5+ 3cos(0.2pi*n)+4sin(0.6pi*n))u[n] ')
Plotting:
Problem 4: Solution:
clear all;
close all;
clc;
n=0:199;
x= cos(0.2*pi*n)+0.5*cos(0.6*pi*n);
%Signal y[n]
[y1,ny1] = sigshift(x,n,20);
y2=0.1*y1;
[y3,n3] = sigadd(n, x, ny1, y2) %y[n]=x[n]+0.1x[n-20]
subplot(311)
stem(n3,y3);
title('y[n]=x[n]+0.1x[n-20]');
%For Auto correlation: y[n]*y[-n]
[y4,n4]= sigfold(y3,n3); %y[-n]
[ryy,nyy]= convolution_sum(n4,y4,n3,y3);
subplot(312)
stem(nyy,ryy);
title('For Auto correlation: y[n]*y[-n]');
% For cross correlation: y[n]*x[-n]
[x1,n1]= sigfold(x,n);
[rxy,nxy]= convolution_sum(n3,y3,n1,x1);
subplot(313)
stem(nxy,rxy);
title('For cross correlation: y[n]*x[-n]');
%Auto-correlation will always have a maximum at lag, D
= 0.
%The cross-correlation plot will show a peak at the lag
where y[n]=x[n-D]
%Here D=0, Because the cross correlations peak is also
in D=0
%So delay between x[n] and y[n] should be 0.
Plotting:
Problem 5: Solution:
clear all;
close all;
clc;
nx=0:3;
x=[1,2,1,1];
ny=-1:3;
y=[3,5,8,13,21];
% cross correlation: x[n]*y[-n]
[y1,ny1] = sigfold(y, ny)
[rxy,nxy] = convolution_sum(nx, x, ny1, y1)
subplot(211)
stem(nxy,rxy)
title('For cross correlation: x[n]*y[-n]');
% cross correlation: y[n]*x[-n]
[x1,n1] = sigfold(x, nx)
[ryx,nyx] = convolution_sum(ny, y, n1, x1)
subplot(212)
stem(nyx,ryx)
title('For cross correlation: y[n]*x[-n]');
Plotting:
So. Cross-correlation is non-commutative.
PreLab problems:
Solved (Sami)
1)
clear all;
close all;
clc;
[u, n] = unit_step(0, -10, 10)
[u_shifted,n_shifted]= sigshift(u,n,2)
[u_folded,n_folded]= sigfold(u_shifted,n_shifted)
x1=3*u_folded;
subplot(411)
stem(n_folded,x1)
xlim([-20,20])
[delta1,n1] = unit_impulse(0, -10, 10)
[delta_shifted1,n_shifted1]= sigshift(delta1,n1,4)
x2= -2* delta_shifted1;
subplot(412)
stem(n_shifted1,x2)
xlim([-20,20])
[delta2,n2] = unit_impulse(0, -10, 10)
[delta_shifted2,n_shifted2]= sigshift(delta2,n2,-4)
[delta_folded2,n_folded2]=
sigfold(delta_shifted2,n_shifted2)
subplot(413)
stem(n_folded2,delta_folded2)
xlim([-20,20])
[y1,ny1] = sigadd(n_folded,x1,n_shifted1,x2)
[y2,ny2] = sigadd(ny1,y1,n_folded2,delta_folded2)
subplot(414)
stem(ny2,y2)
xlim([-20,20])
2)
clc;
clear all;
close all;
n=-20:100;
b=[1 -1 0 3];
a=[1 0 3 2];
x= 2*(n==1);
% x = zeros(1, 10);
% x(2) = 2; % since MATLAB indices start from 1, n=1
is index 2
h=filter(b,a,x);
stem(n,h);
3)
clear all;
close all;
clc;
n=0:99;
x= 0.2*cos(0.6*pi*n)+0.5*sin(0.2*pi*n);
%Signal y[n]
[y1,ny1] = sigshift(x,n,-5);
[y2,ny2] = sigfold(y1, ny1);
y3= 2*x-0.5*y2;
subplot(211)
stem(ny2,y3);
[x1,n1]= sigfold(x,n);
[rxy,nxy]= convolution_sum(n1,x1,ny2,y3);
subplot(212)
stem(nxy,rxy);