You are on page 1of 59

Hamza Ahmed Khan EE171032

Lab 1
Q1
t=[-2:1:2];
y=[zeros(1,2), ones(1,1),zeros(1,2)];
%y=[0 0 1 0 0];
subplot(2,2,1);
hold on
stem(t,y);
title('unit impluse')
ylabel('x(t)');
xlabel('t');
ylim([0 1.5]);
grid on
t1=[0:1:4];
y1=ones(1,5);
%t1=[-4:4];
%y1=[t1>=0];
subplot(2,2,2);
plot(t1,y1,'r');
ylabel('x(t)');
xlabel('t');
title('unit step');
hold on
stem(t1,y1);
grid on
legend('continuous','discrete');
xlim([-4 4]);
ylim([0 1.5]);
y2=[zeros(1,3),1,2];
subplot(2,2,3);
%y2=t.*[t>=0];
plot(t,y2,'r');
title('unit ramp')
hold on
stem(t,y2,'b');
ylabel('x(t)');
xlabel('t');
ylim([0 3]);
legend('continuous','discrete');
grid on
t2=[0:0.1:2];
y3=exp(2*t2);
subplot(2,2,4);
plot(t2,y3,'r');
hold on
stem(t2,y3);
xlim([-2 2])
title('exponential')
ylabel('x(t)');
xlabel('t');
legend('continuous','discrete');
grid on
Hamza Ahmed Khan EE171032

Q2

%For Rectangle:
t=-2:0.001:2;
y=rectpuls(t);
subplot(2,2,1)
plot (t,y);
title('rectangular pulse')
ylim([0 1.5])
grid on
%Triangle:
y1=tripuls(t);
subplot(2,2,2)
plot (t,y1);
title('Triangular pulse')
grid on
%Sawtooth:
fs = 10000;
t1 = 0:1/fs:1.5;
x =sawtooth(2*pi*50*t1);
subplot(2,2,3)
plot(t1,x)
title('Sawtooth')
axis([0 0.2 -1 1]);
grid on
%Square wave:
t2=0:0.001:20;
y2=square(t2);
subplot(2,2,4)
plot(t2,y2)
ylim([0 1.5])
title('Squarewave')
grid on
figure
%Sinc function:
t3 = -5:0.1:5;
y3 = sinc(t3);
plot(t3,y3)
title('Sinc function')
grid on
Hamza Ahmed Khan EE171032

Q3

F1 = 10 ;
F2 = 100 ;
t = [0 : 0.0005 : 0.2];
x1t = cos (2 * pi * F1 * t);
x2t = cos (2 * pi * F2 * t);
plot(t,x1t,t,x2t, 'LineWidth',2);
xlabel('cont time (sec)');
ylabel('Amp');
xlim([0 0.1]);
grid on;
legend('10Hz','100Hz');
figure
x=x1t+x2t;
plot(t,x)
xlabel('cont time (sec)')
ylabel('Amp');
grid on
Hamza Ahmed Khan EE171032

Q4) PART A:
t=[-3:1:3];
y=[-4, 5, 1, -3, -2, 0,3];
subplot(3,1,1);
hold on
stem(t,y);
title('unit impluse')
ylabel('x(t)');
xlabel('t');
grid on

PART B
t=[-1:1:5];
y=[6, -3, -1, 0,8 ,7,-2];
subplot(3,1,2);
hold on
stem(t,y);
title('unit impluse')
ylabel('x(t)');
xlabel('t');
grid on

PART C
t=[2:1:8];
y=[3, 2, 2, -1, 0, -2, 5];
subplot(3,1,3);
hold on
stem(t,y);
title('unit impluse')
ylabel('x(t)');
xlabel('t');
grid on

Q5) PART A:

t=[-2:0.01:10]
y=heaviside(t-2)
subplot(2,2,1)
plot(t,y)
axis([-4 12 0 2]);
grid on
Hamza Ahmed Khan EE171032

PART B:
t=[-2:0.01:10]
y=heaviside(t-4)-heaviside(t-7)
subplot(2,2,2)
plot(t,y)
axis([-4 12 0 2]);
grid on

PART C:
t=[-2:0.01:10]
z=3*heaviside(t)-3*heaviside(t-5)
subplot(2,2,3)
plot(t,z)
axis([-4 12 0 4]);
grid on

Q6 PART A:
%increasing damped wave
A=10;
f=1000;
n=5;
T=1/f;
t=[0:T/100:n*T];
s=A*exp(t*1000).*sin(2*pi*f*t);
subplot(2,1,1)
plot(t,s)

Q6) PART B:

%decreasing damped wave

A=10;
f=1000;
n=5;
T=1/f;
t=[0:T/100:n*T];
s=A*exp(-t*1000).*sin(2*pi*f*-t);
subplot (2,1,2)
plot(t,s)
Hamza Ahmed Khan EE171032

Lab 2
Q1)

t=[0:0.001:0.3];
A=2;
F=10;
y=A*sin(2*pi*F*t);
subplot(3,1,1)
plot(t,y)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Original Voltage Signal')
ylim([-4.5 4.5])
%Amplified signal
y1=2*y;
subplot(3,1,2)
plot(t,y1)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Amplified Voltage Signal')
ylim([-4.5 4.5])
%Attenuated signal
y2=0.5*y;
subplot(3,1,3)
plot(t,y2)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Attenuated Voltage Signal')
ylim([-4.5 4.5])
figure
plot(t,y,t,y1,t,y2)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Voltage Signals')
legend('Orignal Signal','Amplified Signal','Attenuated Signal')
ylim([-4.5 4.5])
Hamza Ahmed Khan EE171032

Q2)

close all
clear all
clc
n=[-2:2];
y1=[0 2 3 3 0];
y2=[2 2 2 1 0];
subplot(4,1,1)
stem(n,y1)
grid on
xlabel('n')
ylabel('y1(n)')
title('Signal 1')
axis([-2.5 2.5 0 5])
subplot(4,1,2)
stem(n,y2)
grid on
xlabel('n')
ylabel('y2(n)')
title('Signal 2')
axis([-2.5 2.5 0 5])
Y=y1+y2;
subplot(4,1,3)
stem(n,Y)
grid on
xlabel('n')
ylabel('Y(n)')
title('Signal 1 + Signal 2')
axis([-2.5 2.5 0 5])
Y1=y1-y2;
subplot(4,1,4)
stem(n,Y1)
grid on
xlabel('n')
ylabel('Y1(n)')
title('Signal 1 - Signal 2')
axis([-2.5 2.5 0 5])

Q3)

clear all
t=[-2:0.001:2];
y=2*rectpuls(t);
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
axis([-2 2 0 4])
Hamza Ahmed Khan EE171032

grid on
y1=2*rectpuls(2*t);
subplot(3,1,2)
plot(t,y1)
xlabel('t')
ylabel('y(2t)')
title('Compressed signal')
axis([-2 2 0 4])
grid on
y2=2*rectpuls(0.5*t);
subplot(3,1,3)
plot(t,y2)
xlabel('t')
ylabel('y(0.5t)')
title('Epanded signal')
axis([-2 2 0 4])
grid on

Q4)

close all
clear all
t=[-2:0.1:2];
y=2*exp(t);
subplot(2,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
ylim([0 10])
grid on
t2=-fliplr(t);
y2=fliplr(y);
subplot(2,1,2)
plot(t2,y2)
xlabel('t')
ylabel('y(-t)')
title('Reflected signal')
ylim([0 10])
grid on
Hamza Ahmed Khan EE171032

Q5)
close all
clear all
clc
t=[-2:0.1:2];
y=2*tripuls(t);
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
grid on
ylim([0 3])
t1=t-1;
y1=2*tripuls(t1);
subplot(3,1,2)
plot(t1,y1)
xlabel('t')
ylabel('y(t-1)')
title('Delayed signal')
grid on
ylim([0 3])
t2=t+1;
y2=2*tripuls(t2);
subplot(3,1,3)
plot(t2,y2)
xlabel('t')
ylabel('y(t+1)')
title('Advanced signal')
grid on
ylim([0 3])

Q7) PART A:
t=0:0.001:2;
y=5*exp(3*t).*cos(2*pi*30*t);
subplot(2,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
grid on

PART B:
t=0:0.001:2;
y=5*exp(3*-t).*cos(2*pi*30*-t);
subplot(2,1,2)
plot(t,y)
xlabel('t')
ylabel('y(-t)')
grid on
Hamza Ahmed Khan EE171032

Q6) PART A:
t=[0:0.001:2];
y=2*sin(2*pi*10*t)
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
grid on

Q6) PART B:
t=[0:0.001:2];
y=2*sin(2*pi*10*3*t)
subplot(3,1,2)
plot(t,y)
xlabel('t')
ylabel('y(3t)')
grid on

Q6) PART C:
t=[0:0.001:2];
y=2*sin(2*pi*10*0.25*t)
subplot(3,1,3)
plot(t,y)
xlabel('t')
ylabel('y(0.25t)')
grid on

Q8) PART A:
t=-6:0.001:6;
y=4*rectpuls(t);
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
ylim ([0 5])
grid on
t=-6:0.001:6;
y=4*rectpuls(t-3);
subplot(3,1,2)
plot(t,y)
xlabel('t')
ylabel('y(t-3)')
title('Delayed Signal’)
ylim ([0 5])
grid on
t=-6:0.001:6;
y=4*rectpuls(t+3);
subplot(3,1,3)
plot(t,y)
Hamza Ahmed Khan EE171032

xlabel('t')
ylabel('y(t+3)')

title(‘Advanced Signal’)
ylim ([0 5])
grid on
Hamza Ahmed Khan EE171032

Lab 3
Q1)

t=[0:0.001:0.3];
A=2;
F=10;
y=A*sin(2*pi*F*t);
subplot(3,1,1)
plot(t,y)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Original Voltage Signal')
ylim([-4.5 4.5])
%Amplified signal
y1=2*y;
subplot(3,1,2)
plot(t,y1)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Amplified Voltage Signal')
ylim([-4.5 4.5])
%Attenuated signal
y2=0.5*y;
subplot(3,1,3)
plot(t,y2)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Attenuated Voltage Signal')
ylim([-4.5 4.5])
figure
plot(t,y,t,y1,t,y2)
grid on
xlabel('time/s')
ylabel('Voltage/V')
title('Voltage Signals')
legend('Orignal Signal','Amplified Signal','Attenuated Signal')
ylim([-4.5 4.5])
Hamza Ahmed Khan EE171032

Q2)

close all
clear all
clc
n=[-2:2];
y1=[0 2 3 3 0];
y2=[2 2 2 1 0];
subplot(4,1,1)
stem(n,y1)
grid on
xlabel('n')
ylabel('y1(n)')
title('Signal 1')
axis([-2.5 2.5 0 5])
subplot(4,1,2)
stem(n,y2)
grid on
xlabel('n')
ylabel('y2(n)')
title('Signal 2')
axis([-2.5 2.5 0 5])
Y=y1+y2;
subplot(4,1,3)
stem(n,Y)
grid on
xlabel('n')
ylabel('Y(n)')
title('Signal 1 + Signal 2')
axis([-2.5 2.5 0 5])
Y1=y1-y2;
subplot(4,1,4)
stem(n,Y1)
grid on
xlabel('n')
ylabel('Y1(n)')
title('Signal 1 - Signal 2')
axis([-2.5 2.5 0 5])

Q3)

clear all
t=[-2:0.001:2];
y=2*rectpuls(t);
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
axis([-2 2 0 4])
grid on
y1=2*rectpuls(2*t);
Hamza Ahmed Khan EE171032

subplot(3,1,2)
plot(t,y1)
xlabel('t')
ylabel('y(2t)')
title('Compressed signal')
axis([-2 2 0 4])
grid on
y2=2*rectpuls(0.5*t);
subplot(3,1,3)
plot(t,y2)
xlabel('t')
ylabel('y(0.5t)')
title('Epanded signal')
axis([-2 2 0 4])
grid on

Q4)

close all
clear all
t=[-2:0.1:2];
y=2*exp(t);
subplot(2,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
ylim([0 10])
grid on
t2=-fliplr(t);
y2=fliplr(y);
subplot(2,1,2)
plot(t2,y2)
xlabel('t')
ylabel('y(-t)')
title('Reflected signal')
ylim([0 10])
grid on
Hamza Ahmed Khan EE171032

Q5)
close all
clear all
clc
t=[-2:0.1:2];
y=2*tripuls(t);
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
grid on
ylim([0 3])
t1=t-1;
y1=2*tripuls(t1);
subplot(3,1,2)
plot(t1,y1)
xlabel('t')
ylabel('y(t-1)')
title('Delayed signal')
grid on
ylim([0 3])
t2=t+1;
y2=2*tripuls(t2);
subplot(3,1,3)
plot(t2,y2)
xlabel('t')
ylabel('y(t+1)')
title('Advanced signal')
grid on
ylim([0 3])

Q7) PART A:
t=0:0.001:2;
y=5*exp(3*t).*cos(2*pi*30*t);
subplot(2,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
grid on

PART B:
t=0:0.001:2;
y=5*exp(3*-t).*cos(2*pi*30*-t);
subplot(2,1,2)
plot(t,y)
xlabel('t')
ylabel('y(-t)')
grid on

Q6) PART A:
t=[0:0.001:2];
Hamza Ahmed Khan EE171032

y=2*sin(2*pi*10*t)
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
grid on

Q6) PART B:
t=[0:0.001:2];
y=2*sin(2*pi*10*3*t)
subplot(3,1,2)
plot(t,y)
xlabel('t')
ylabel('y(3t)')
grid on

Q6) PART C:
t=[0:0.001:2];
y=2*sin(2*pi*10*0.25*t)
subplot(3,1,3)
plot(t,y)
xlabel('t')
ylabel('y(0.25t)')
grid on

Q8) PART A:
t=-6:0.001:6;
y=4*rectpuls(t);
subplot(3,1,1)
plot(t,y)
xlabel('t')
ylabel('y(t)')
title('Original signal')
ylim ([0 5])
grid on
t=-6:0.001:6;
y=4*rectpuls(t-3);
subplot(3,1,2)
plot(t,y)
xlabel('t')
ylabel('y(t-3)')
title('Delayed Signal’)
ylim ([0 5])
grid on
t=-6:0.001:6;
y=4*rectpuls(t+3);
subplot(3,1,3)
plot(t,y)
xlabel('t')
ylabel('y(t+3)')
Hamza Ahmed Khan EE171032

title(‘Advanced Signal’)
ylim ([0 5])
grid on
Hamza Ahmed Khan EE171032

Lab 4
Q.1
close all
clear all
clc
t=0:.01:6;
T=0:.01:12;
x=heaviside(t);
subplot(2,2,1)
plot(t,x)
title('x(t)')
grid on
h=heaviside(t)
subplot(2,2,2)
plot(t,h)
title('h(t)')
grid on
y=conv(x,h)*0.01;
subplot(2,1,2)
plot(T,y)
title('y(t)')
grid on

Fig. 1: Q.1
Hamza Ahmed Khan EE171032

Q.3
close all

clear all
clc
t=0:.01:6;
T=0:.01:12;
x=heaviside(t) - heaviside(t-2) ;
subplot(2,2,1)
plot(t,x)
title('x(t)')
grid on
h= triangularPulse(t);
subplot(2,2,2)
plot(t,h)
title('h(t)')
grid on
y=conv(x,h)*0.01;
subplot(2,1,2)
plot(T,y)
title('y(t)')
grid on

Fig. 3: Q.3
Hamza Ahmed Khan EE171032

Q.4 (a)

clc;
clear all;
close all;
A =[ 2 1 0.5 1 2];
N1 = 2:length(A)+1 ;
B= [ 1 0 1] ;
N2 = -2 : length(B)-3;
B = conv(A,B);
subplot(3,1,1);
stem(N1,A);
title('A[n]');
subplot(3,1,2);
stem(N2,B);
title('B[n]');
N= 0:length(C) - 1;
subplot(3,1,3);
stem(N,C);
title('Convoluted Output C[n]')

Fig. 4.1: Q.4 (a)


Hamza Ahmed Khan EE171032

Q.4 (b)
clc;
clear all;
close all;
A =[ 1 0.5 1 1 1 2];
N1 = 2:length(A)+1 ;
B = [ 1 0 0.5 2 2 1 2 1] ;
N2 = -2 : length(B)-3;
C = conv(A,B);
subplot(3,1,1);
stem(N1,A);
title('A[n]');
subplot(3,1,2);
stem(N2,B);
title('B[n]');
N= 0:length(C) - 1;
subplot(3,1,3);
stem(N,C);
title('Convoluted Output C[n]')

Q.5
t=0:0.01:2;
T=0:.01:4;
A= 2*sin(2*pi*10*t) ;
subplot(2,2,1)
plot(t,x)
title('A(t)')
grid on
B= 3*exp(-5*t);
subplot(2,2,2)
plot(t,B)
title('B(t)')
grid on
C=conv(A,B)*0.01;
subplot(2,1,2)
plot(T,C)
title('C(t)')
grid on
Hamza Ahmed Khan EE171032

Q.6
A = [0 1:10 5.*ones(1,5) zeros(1,40)];
N1 = 0:length(X)-1 ;
B = [1 zeros(1,20) 0.5 zeros(1,10)];
N2 = 0 : length(B)-1;
C = conv(A,B);
subplot(3,1,1);
stem(N1,A);
title('A[n]');
subplot(3,1,2);
stem(N2,B);
title('B[n]');
N= 0:length(C) - 1;

subplot(3,1,3);
stem(N,C);
title('Convoluted Output C[n]')
Hamza Ahmed Khan EE171032

Lab 5
Q1

Q2
Hamza Ahmed Khan EE171032

input

output

Q3
Hamza Ahmed Khan EE171032

input

output

q4
Hamza Ahmed Khan EE171032

Q5
Hamza Ahmed Khan EE171032

Q6
Hamza Ahmed Khan EE171032

Lab 6
Q1
close all
clear all
clc
eqn1 = 'Dy = exp(y)*sint';
y = dsolve(eqn1,'y(1)=1','t');
ezplot(y,[0 1])
grid on
xlabel('t')
ylabel('y(t)')
Hamza Ahmed Khan EE171032

Q2

close all
clear all
clc
eqn2 = '7*D2y + 2*Dy + y = t';
inits2 = 'y(0)=1, Dy(0)=2';
y=dsolve(eqn2,inits2,'t');
ezplot(y,[0 20])
grid on
xlabel('t')
ylabel('y(t)')
Hamza Ahmed Khan EE171032

Q3

function f=fun1(t,y)
f= ((2*sin(3*t))-y)/3;

clear all
close all
clc
[tv1 f1]=ode23('fun1',[0 6],1);
[tv2 f2]=ode45('fun1',[0 6],1);
plot(tv1,f1,'-.',tv2,f2,'--')
title('y''=((2*sin(3*t))-y)/3, y(0)=1, t in [0, 6]')
grid
axis([0 6 0 1.3])
legend('ode23', 'ode45')
Hamza Ahmed Khan EE171032

Q4 a)

close all
clear all
clc
eqn2 = 'D2y + 3*Dy + 2*y = (t^2)+(5*t)+3';
inits2 = 'y(0)=2, Dy(0)=3';
y=dsolve(eqn2,inits2,'t');
ezplot(y,[0 5])
grid on
xlabel('t')
ylabel('y(t)')

Q5 a
Hamza Ahmed Khan EE171032

Q5 b
Hamza Ahmed Khan EE171032

Lab 7
Q.1

n =0:30;

a= 0.9;
y= a.^n;
stem (n,y);
subplot (3,2,1);

a= -0.9;
y= a.^n;
stem (n,y);
subplot (3,2,2);

a= 1;
y= a.^n;
stem (n,y);
subplot (3,2,3);

a= -1;
y= a.^n;
stem (n,y);
subplot (3,2,4);

a= 1.1;
y= a.^n; Fig. 1: Q.1

stem (n,y);
subplot (3,2,5);

a= -1.1;
y= a.^n;
stem (n,y);
subplot (3,2,6);

Q.2
clear all;
close all;
clc;
% Generate the complex exponential signal
t = 0:.01:20;
w=1; % 2piF=1
ce = exp(j*w*t); % complex exponential function
h = plot3(t,real(ce),imag(ce),'k-');
set(h,'LineWidth',3);
Hamza Ahmed Khan EE171032

grid on;
rotate3d on; % to rotate the figure
xlabel('Time');
ylabel('Real Axis');
zlabel('Imaginary Axis');
campos([70 -14 7]); % "Plot the projections onto the back planes"
hold on;
plot3(t,real(ce),-1*ones(size(t)),'r--','LineWidth',2)
plot3(t,ones(size(t)),imag(ce),'g--','LineWidth',2)
plot3(zeros(size(t)),real(ce),imag(ce),'b--','LineWidth',2)
title('Complex:Black Real:Red Imaginary:Green');

Fig. 2: Q.2
It’s a positive frequency phasor

Q.3

clear all;
close all;
clc;
% Generate the complex exponential signal
Hamza Ahmed Khan EE171032

t = 0:.01:20;
w=1; % 2piF=1
ce = exp(-j*w*t); % complex exponential function
h = plot3(t,real(ce),imag(ce),'k-');
set(h,'LineWidth',3);
grid on;
rotate3d on; % to rotate the figure
xlabel('Time');
ylabel('Real Axis');
zlabel('Imaginary Axis');
campos([70 -14 7]); % "Plot the projections onto the back planes"
hold on;
plot3(t,real(ce),-1*ones(size(t)),'r--','LineWidth',2)
plot3(t,ones(size(t)),imag(ce),'g--','LineWidth',2)
plot3(zeros(size(t)),real(ce),imag(ce),'b--','LineWidth',2)
title('Complex:Black Real:Red Imaginary:Green');

Fig. 3: Q.3

Q.4
Hamza Ahmed Khan EE171032

clear all;
close all;
clc;
t=linspace(-3,3,200);
y=0;
for n=1:2:50;
y=y+((2/(n*pi))*sin(n*pi*t));
if n==1
y1=y;
subplot(2,2,1);
plot(t,y1,'r','Linewidth',2)
grid on
title('One Frequency')
xlabel('Time (sec)')
ylabel('Amplitude')
axis tight
end
if n==3
y1=y;
subplot(2,2,2);
plot(t,y1,'b','Linewidth',2)
grid on
title('3 Frequencies')
xlabel('Time (sec)')
ylabel('Amplitude')
axis tight
end
if n==15
y1=y;
subplot(2,2,3);
plot(t,y1,'m','Linewidth',2)
grid on
title('21 Frequencies')
xlabel('Time (sec)')
ylabel('Amplitude') Fig. 4: Q.4
We have to reach at infinity for a perfect square
wave

axis tight

end

if n==49
y1=y;
subplot(2,2,4);
plot(t,y1,'k','Linewidth',2)
grid on
title('49 Frequencies')
xlabel('Time (sec)')
ylabel('Amplitude')
axis tight
end
end
Hamza Ahmed Khan EE171032

Q.5

Fig. 5: Q.5

Fig. 6: Q.5

Q.6

Fig. 7: Q.6
Hamza Ahmed Khan EE171032

Fig. 8: Q.6

Fig. 9: Q.6
Hamza Ahmed Khan EE171032

Lab 8
Q1
syms t s
x1=t^3*sin(5*t)
x2=t/exp(t)
x3=cos(2*t)
X1=laplace(x1,t,s)
X2=laplace(x2,t,s)
X3=laplace(x3,t,s)

pretty(X1)
pretty(X2)
pretty(X3)

x1 = t^3*sin(5*t)

x2 = t*exp(-t)

x3 = cos(2*t)

X1 =(240*s^3)/(s^2 + 25)^4 - (120*s)/(s^2 + 25)^3

X2= 1/(s + 1)^2

X3 =s/(s^2 + 4)

240 s 120 s

---------- - ----------

2 4 2 3

(s + 25) (s + 25)

--------

(s + 1)

------

2
Hamza Ahmed Khan EE171032

s +4

Q2
syms t s
X1=(3*s+5)/(s^3+6*s^2+5*s);
X2=exp(-10*s);
x1=ilaplace(X1)
x2=ilaplace(X2)
pretty(X1)
pretty(X2)

x1 =(3*dirac(t))/20 + 1/4

x2 =dirac(t - 10)

3s+5

-------

20 s

exp(-10 s)

Q3
syms t s
H=tf([1 -1],[1 3 2])
h=ilaplace((s-1)/(s^2+3*s+2))
ezplot(h)
figure
pzmap(H)
Hamza Ahmed Khan EE171032

Q.4
close all
clear all
clc
syms t s
X=(s+5)/(s^2 +2*s+3);
x=ilaplace(X)
simplify(x)
pretty(ans)
A=tf([1 5],[1 2 3])
a=ilaplace((s+5)/(s^2 +2*s+3))
subplot(3,1,1);
ezplot(a)

Y=(2*(s^2) + 5*s +12)/(s^2 + 2*s +10) ;


y=ilaplace(Y)
simplify(y)
pretty(ans)
B=tf([2 5 12],[1 2 10])
b=ilaplace((2*(s^2) + 5*s +12)/(s^2 + 2*s +10))

subplot(3,1,2);
ezplot(b)

Z=(2*(s^2) + 5*s +12)/((s^2 +2*s +10)*(s+2));


z=ilaplace(Z)
simplify(z)
pretty(ans)
C=tf([2 5 12],[1 2 16 20])
c=ilaplace((2*(s^2) + 5*s +12)/((s^2 +2*s +10)*(s+2)))
subplot(3,1,3);
ezplot(c)

figure
subplot(3,1,1);
pzmap(A)
subplot(3,1,2);
pzmap(B)
subplot(3,1,3);
pzmap(C)

x =exp(-t)*(cos(2^(1/2)*t) + 2*2^(1/2)*sin(2^(1/2)*t))

ans =exp(-t)*(cos(2^(1/2)*t) + 2*2^(1/2)*sin(2^(1/2)*t))

exp(-t) (cos(sqrt(2) t) + 2 sqrt(2) sin(sqrt(2) t))


Hamza Ahmed Khan EE171032

A= s+5

-------------

s^2 + 2 s + 3

Continuous-time transfer function.

a =exp(-t)*(cos(2^(1/2)*t) + 2*2^(1/2)*sin(2^(1/2)*t))

y =2*dirac(t) + exp(-t)*(cos(3*t) - 3*sin(3*t))

ans =2*dirac(t) + exp(-t)*(cos(3*t) - 3*sin(3*t))

2 dirac(t) + exp(-t) (cos(3 t) - sin(3 t) 3)

B = 2 s^2 + 5 s + 12

----------------

s^2 + 2 s + 10

Continuous-time transfer function.

b =2*dirac(t) + exp(-t)*(cos(3*t) - 3*sin(3*t))

z =exp(-2*t) + cos(3*t)*exp(-t)

ans =exp(-2*t) + cos(3*t)*exp(-t)

exp(-2 t) + cos(3 t) exp(-t)

C = 2 s^2 + 5 s + 12 Fig 3.Q4.

-----------------------

s^3 + 2 s^2 + 16 s + 20

Continuous-time transfer
function.

c =exp(-2*t) + cos(3*t)
*exp(-t)
Hamza Ahmed Khan EE171032

Fig 4.Q4.

Q5
close all

clear all

clc

syms t s

%h(s)

h=laplace(-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t));

simplify(h)

pretty(ans)

ezplot(h)

%pole and zero map

H=tf([1 -5],[1 4 4])

subplot(3,1,2)

pzmap(H)

%convolution

figure

t=0:.01:6;

T=0:.01:12;

x=3*exp(t).*cos(2*t);

h2= -1.25+3.5*t.*exp(-2*t)+1.25*exp(-2*t);

subplot(2,2,1)

plot(t,x)

title('x(t)')

grid on
Hamza Ahmed Khan EE171032

subplot(2,2,2)

plot(t,h2)

title('h(t)')

grid on

y=conv(x,h2)*0.01;

subplot(2,1,2)

plot(T,y)

title('y(t)')

grid on

ans =

(s - 5)/(s*(s + 2)^2)

Fig 5.Q5.

s-5

----------

s (s + 2)

H=

s-5

-------------

s^2 + 4 s + 4

Continuous-time transfer function.

Fig 6.Q5.
Hamza Ahmed Khan EE171032

Lab 9
Q1
syms s t Y
f = dirac(t);
F = laplace(f);
Y1 = s*Y - 1;
Y2 = s*Y1 - 2;
lap_eq=7*Y2 + 2*Y1 + Y - F;
S =solve(lap_eq,Y)
sol = ilaplace(S)
ezplot(sol, [0 10])

S = (7*s + 17)/(7*s^2 + 2*s + 1)

sol =exp(-t/7)*(cos((6^(1/2)*t)/7) +
(8*6^(1/2)*sin((6^(1/2)*t)/7))/3)

Q2
syms s t Y
f = t^2+5*t+3;
F = laplace(f);
Y1 = s*Y - 2;
Y2 = s*Y1 - 3;
lap_eq=Y2 + 3*Y1 + 2*Y - F;
S =solve(lap_eq,Y)
sol = ilaplace(S)
subplot(3,1,1)
ezplot(sol, [0 10])

f = 10*exp(-3*t);
F = laplace(f);
Y1 = s*Y - 2;
Y2 = s*Y1 - 3;
lap_eq= Y2 +3*Y1 + 2*Y - F;
S = solve(lap_eq, Y)
subplot(3,1,2)
sol = ilaplace(S)
ezplot(sol,[0,10])

f = 5*cos(3*t+30);
F = laplace(f);
Y1 = s*Y - 2;
Y2 = s*Y1 - 3;
lap_eq= Y2 +3*Y1 + 2*Y - F;
S = solve(lap_eq, Y)
sol = ilaplace(S)
Hamza Ahmed Khan EE171032

subplot(3,1,3)
ezplot(sol,[0,10])
S =(2*s + 3/s + 5/s^2 + 2/s^3 + 9)/(s^2 + 3*s + 2)

sol =t + 7*exp(-t) - (9*exp(-2*t))/2 + t^2/2 - 1/2

S =(2*s + 10/(s + 3) + 9)/(s^2 + 3*s + 2)

sol =12*exp(-t) - 15*exp(-2*t) + 5*exp(-3*t)

S =(2*s - (5*(3*sin(30) - s*cos(30)))/(s^2 + 9) + 9)/(s^2 + 3*s


+ 2)

sol =(9*cos(3*t)*sin(30))/26 + (9*sin(3*t)*cos(30))/26 +


(7*sin(3*t)*sin(30))/26 - exp(-t)*(cos(30)/2 + (3*sin(30))/2 -
7) + exp(-2*t)*((10*cos(30))/13 + (15*sin(30))/13 - 5) -
(7*cos(3*t)*cos(30))/26

Q3
syms s t Y
f = 0;
F = 0;
Y1 = s*Y - 0;
Y2 = s*Y1 - 1;
lap_eq= Y2 - 3*Y1 + 4*Y - F;
S = solve(lap_eq, Y)
sol = ilaplace(S)
subplot(2,1,1)
ezplot(sol,[0,10])

f = exp(t)+1;
F = laplace(f);
Y1 = s*Y - 0;
Y2 = s*Y1 - 1;
lap_eq= Y2 - Y - F;
S = solve(lap_eq, Y)
sol = ilaplace(S)
subplot(2,1,2)
ezplot(sol,[0,10])

S = 1/(s^2 - 3*s + 4)

sol =(2*7^(1/2)*exp((3*t)/2)*sin((7^(1/2)*t)/2))/7

S =(1/(s - 1) + 1/s + 1)/(s^2 - 1)

sol =exp(-t)/4 + (3*exp(t))/4 + (t*exp(t))/2 – 1


Hamza Ahmed Khan EE171032

Q4
syms s t Y
f = (heaviside(t-2)-heaviside(t-5))*t;
F = laplace(f);
Y1 = s*Y - 4;
Y2 = s*Y1 - 5;
lap_eq= Y2 +2*Y1 + 10*Y - F;
S = solve(lap_eq, Y)
sol = ilaplace(S)
ezplot(sol,[0,10])
ylim([-2,5])

S =(4*s + (2*exp(-2*s))/s + exp(-2*s)/s^2 - (5*exp(-5*s))/s - exp(-5*s)/s^2 + 13)/(s^2 + 2*s + 10)

sol =heaviside(t - 2)*(t/10 + (exp(2 - t)*(cos(3*t - 6) - (4*sin(3*t - 6))/3))/50 - 11/50) - heaviside(t -


5)*(t/10 + (exp(5 - t)*(cos(3*t - 15) - (4*sin(3*t - 15))/3))/50 - 13/25) + 4*exp(-t)*(cos(3*t) - sin(3*t)/3) +
(13*sin(3*t)*exp(-t))/3 - 2*heaviside(t - 2)*((exp(2 - t)*(cos(3*t - 6) + sin(3*t - 6)/3))/10 - 1/10) +
5*heaviside(t - 5)*((exp(5 - t)*(cos(3*t - 15) + sin(3*t - 15)/3))/10 - 1/10)
Hamza Ahmed Khan EE171032

Lab 10
Q1

Code 1:

num=[2 5 3 6];

den=[1 6 11 6];

[r,p,k]=residue(num,den) printsys(num,den,'S')

r = -6.000

-4.0000

3.0000

p = -3.0000

-2.0000

-1.0000

k= 2

num/den =

2 S^3 + 5 S^2 + 3 S + 6

-----------------------

S^3 + 6 S^2 + 11 S + 6

Code 2:

num=[2 5 3 6];

den=[1 6 11 6];

[z,p,k]=tf2zp(num,den)

disp('Zeros of the function is = ')

disp(z)

disp('Poles of the function is = ')

disp(p)

disp('Gain of the function is = ')

disp(k)
Hamza Ahmed Khan EE171032

z = -2.3965 + 0.0000i

-0.0518 + 1.1177i

-0.0518 - 1.1177i

p = -3.0000

-2.0000

-1.0000

k= 2

Zeros of the function is =

-2.3965 + 0.0000i

-0.0518 + 1.1177i

-0.0518 - 1.1177i

Poles of the function is =

-3.0000

-2.0000

-1.0000

Gain of the function is =

code :3
num = [ 1 ];
den = [ 2 5 3 ];
tutorial_tf = tf(num, den)
bode(tutorial_tf)
grid on

tutorial_tf =

---------------

2 s^2 + 5 s + 3

Continuous-time transfer function.


Hamza Ahmed Khan EE171032

Q2
num=[2 5 3 6];
den=[1 6 11 6];
[z,p,k]=tf2zp(num,den)
disp('Zeros of the function is = ')
disp(z)
disp('Poles of the function is = ')
disp(p)
disp('Gain of the function is = ')
disp(k)
H=tf (num,den)
u=4;
step(u*H)

z = -2.3965 + 0.0000i

-0.0518 + 1.1177i

-0.0518 - 1.1177i

p = -3.0000

-2.0000

-1.0000

k= 2

Zeros of the function is =

-2.3965 + 0.0000i

-0.0518 + 1.1177i

-0.0518 - 1.1177i

Poles of the function is =

-3.0000

-2.0000

-1.0000

Gain of the function is = 2

H=

2 s^3 + 5 s^2 + 3 s + 6

-----------------------
Hamza Ahmed Khan EE171032

s^3 + 6 s^2 + 11 s + 6

Continuous-time transfer function.

Q3
num=[2 5 3 6];
den=[1 6 11 6];
[z,p,k]=tf2zp(num,den)
disp('Zeros of the function is = ')
disp(z)
disp('Poles of the function is = ')
disp(p)
disp('Gain of the function is = ')
disp(k)
H=tf (num,den)
u=2;
impulse(u*H)

z = -2.3965 + 0.0000i

-0.0518 + 1.1177i

-0.0518 - 1.1177i

p = -3.0000

-2.0000

-1.0000

k= 2

Zeros of the function is =

-2.3965 + 0.0000i

-0.0518 + 1.1177i

-0.0518 - 1.1177i

Poles of the function is =

-3.0000

-2.0000

-1.0000

Gain of the function is = 2

H=

2 s^3 + 5 s^2 + 3 s + 6

-----------------------
Hamza Ahmed Khan EE171032

s^3 + 6 s^2 + 11 s + 6

Continuous-time transfer function

Q4
num=[1 5];
den=[1 2 3];
[a,b,c]=residue(num,den)
[z,p,k]=tf2zp(num,den)
H=tf (num,den)
Subplot(3,1,1)
bode(H);

num=[2 5 12];
den=[1 2 10];
[e,f,g]=residue(num,den)
[z,p,k]=tf2zp(num,den)
H=tf (num,den)
Subplot(3,1,2)
bode(H);

num=[2 5 12];
den=[1 4 14 20 ];
[h,i,j]=residue(num,den)
[z,p,k]=tf2zp(num,den)
H=tf (num,den)
Subplot(3,1,3)
bode(H);

a = 0.5000 - 1.4142i

0.5000 + 1.4142i

b = -1.0000 + 1.4142i

-1.0000 - 1.4142i

c = []

z = -5

p =-1.0000 + 1.4142i

-1.0000 - 1.4142i

k= 1

H=

s+5

-------------
Hamza Ahmed Khan EE171032

s^2 + 2 s + 3

Continuous-time transfer function.

e = 0.5000 + 1.5000i

0.5000 - 1.5000i

f = -1.0000 + 3.0000i

-1.0000 - 3.0000i

g= 2

z = -1.2500 + 2.1065i

-1.2500 - 2.1065i

p =-1.0000 + 3.0000i

-1.0000 - 3.0000i

k= 2

H=

2 s^2 + 5 s + 12

----------------

s^2 + 2 s + 10

Continuous-time transfer function.

h = 0.5000 - 0.0000i

0.5000 + 0.0000i

1.0000 + 0.0000i

i = -1.0000 + 3.0000i

-1.0000 - 3.0000i

-2.0000 + 0.0000i

j = []

z =-1.2500 + 2.1065i

-1.2500 - 2.1065

p = -1.0000 + 3.0000i

-1.0000 - 3.0000i
Hamza Ahmed Khan EE171032

-2.0000 + 0.0000i

k=

H=

2 s^2 + 5 s + 12

-----------------------

s^3 + 4 s^2 + 14 s + 20

Continuous-time transfer function.


Hamza Ahmed Khan EE171032

Lab 11
TASK 1:
x=1:0.01:10
eq=0
for n=1:2:3
eq=eq+((4/n*pi)*sin(n*pi*x/2*pi));
subplot(4,1,1)
plot(x,eq)
end
eq1=0
for n=1:2:21
eq1=eq1+((4/n*pi)*sin(n*pi*x/2*pi));
subplot(4,1,2)
plot(x,eq1)
end
eq2=0
for n=1:2:49
eq2=eq2+((4/n*pi)*sin(n*pi*x/2*pi));
subplot(4,1,3)
plot(x,eq2)
end
eq3=0
for n=1:2:99
eq3=eq3+((4/n*pi)*sin(n*pi*x/2*pi));
subplot(4,1,4)
plot(x,eq3)
end

TASK 2:
x=1:0.01:10;
eq=0
for n=1:3
eq=eq+((1/n*pi)*sin(n*pi*x/2*pi));
end
eq=1/2-eq
subplot(4,1,1)
plot(x,eq)
eq1=0
for n=1:21
eq1=eq1+((1/n*pi)*sin(n*pi*x/2*pi));
end
eq1=1/2-eq1
subplot(4,1,2)
plot(x,eq1)
eq2=0
for n=1:49
eq2=eq2+((1/n*pi)*sin(n*pi*x/2*pi));
end
eq2=1/2-eq2
subplot(4,1,3)
plot(x,eq2)
eq3=0
for n=1:99
Hamza Ahmed Khan EE171032

eq3=eq3+((1/n*pi)*sin(n*pi*x/2*pi));
end;
eq3=1/2-eq3
subplot(4,1,4)
plot(x,eq3)

TASK 3:
x=1:0.01:10;
eq=0
for n=1:2:3
eq=eq+((8*(-1)^((n-1)/2)/n^2*pi^2)*sin(n*pi*x/2*pi));
end
subplot(4,1,1)
plot(x,eq)
eq1=0
for n=1:2:9
eq1=eq1+((8*(-1)^((n-1)/2)/n^2*pi^2)*sin(n*pi*x/2*pi));
end
subplot(4,1,2)
plot(x,eq1)
eq2=0
for n=1:2:21
eq2=eq2+((8*(-1)^((n-1)/2)/n^2*pi^2)*sin(n*pi*x/2*pi));
end
subplot(4,1,3)
plot(x,eq2)

TASK 4A:
f0=10;
t = 0:0.0001:0.5;
harm1 = cos(2*pi*10*t);
harm2 = 2*cos(2*pi*20*t+45/180*pi);
add = harm1 + harm2;
harm3 = 1*cos(2*pi*30*t+60/180*pi);
add2 = add + harm3;
figure(1)
subplot(2,3,1);
plot(t,harm1)
title('Fundamental/First
Harmonic')
ylim([-4 4])
subplot(2,3,2);
plot(t,harm2)
title('Second Harmonic')
ylim([-4 4])
subplot(2,3,3);
plot(t,harm3)
title('Third Harmonic')
ylim([-4 4])
subplot(2,3,4);
plot(t,add)
title('First + Second Harmonics')
ylim([-4 4])
subplot(2,3,5);
Hamza Ahmed Khan EE171032

plot(t,add2)
title('First + Second +Third Harmonics')
ylim([-4 4])

TASK 4B:
f0=10;
t = 0:0.0001:0.5;
harm1 = cos(2*pi*10*t);
harm2 =
1*cos(2*pi*20*t+45/180*pi);
add = harm1 + harm2;
harm3 =
1*cos(2*pi*30*t+60/180*pi);
add2 = add + harm3;
figure(1)
subplot(2,3,1);
plot(t,harm1)
title('Fundamental/First
Harmonic')
ylim([-4 4])
subplot(2,3,2);
plot(t,harm2)
title('Second Harmonic')
ylim([-4 4])
subplot(2,3,3);
plot(t,harm3)
title('Third Harmonic')
ylim([-4 4])
subplot(2,3,4);
plot(t,add)
title('First + Second Harmonics')
ylim([-4 4])
subplot(2,3,5);
plot(t,add2)
title('First + Second +Third Harmonics')
ylim([-4 4])

TASK 4C:
f0=10;
t = 0:0.0001:0.5;
harm1 = cos(2*pi*10*t);
harm2 =
2*cos(2*pi*20*t+0/180*pi);
add = harm1 + harm2;
harm3 =
1*cos(2*pi*30*t+60/180*pi);
add2 = add + harm3;
figure(1)
subplot(2,3,1);
plot(t,harm1)
title('Fundamental/First
Harmonic')
ylim([-4 4])
Hamza Ahmed Khan EE171032

subplot(2,3,2);
plot(t,harm2)
title('Second Harmonic')
ylim([-4 4])
subplot(2,3,3);
plot(t,harm3)
title('Third Harmonic')
ylim([-4 4])
subplot(2,3,4);
plot(t,add)
title('First + Second Harmonics')
ylim([-4 4])
subplot(2,3,5);
plot(t,add2)
title('First + Second +Third Harmonics')
ylim([-4 4])

TASK 4D:
f0=10;
t = 0:0.0001:0.5;
harm1 = cos(2*pi*10*t);
harm2 = 2*cos(2*pi*20*t+45/180*pi);
add = harm1 + harm2;
harm3 = 1*cos(2*pi*30*t+60/180*pi);
add2 = add + harm3;
harm4 = cos(2*pi*10*t);
add3 = add2 + harm4;
figure(1)
subplot(2,4,1);
plot(t,harm1)
title('Fundamental/First
Harmonic')
ylim([-4 4])
subplot(2,4,2);
plot(t,harm2)
title('Second Harmonic')
ylim([-4 4])
subplot(2,4,3);
plot(t,harm3)
title('Third Harmonic')
ylim([-4 4])
subplot(2,4,4);
plot(t,harm4)
title('Fourth Harmonic')
ylim([-4 4])
subplot(2,4,5);
plot(t,add)
title('First + Second Harmonics')
ylim([-4 4])
subplot(2,4,6);
plot(t,add2)
title('First + Second +Third Harmonics')
ylim([-4 4])
subplot(2,4,7);
plot(t,add3)
Hamza Ahmed Khan EE171032

title('First + Second +Third +Fourth Harmonics')


ylim([-4 4])

TASK 5:
x=1:0.01:10;
eq=0
for n=1:3
eq=eq+((((-1)^n*4)/(n^2*pi^2))*cos(n*pi*x));
end
eq=1/3-eq
subplot(4,1,1)
plot(x,eq)
eq1=0
for n=1:9
eq1=eq1+((((-1)^n*4)/(n^2*pi^2))*cos(n*pi*x));
end
eq1=1/3-eq1
subplot(4,1,2)
plot(x,eq1)
eq2=0
for n=1:21
eq2=eq2+((((-1)^n*4)/(n^2*pi^2))*cos(n*pi*x));
end
eq2=1/3-eq2
subplot(4,1,3)
plot(x,eq2)

You might also like