You are on page 1of 5

MUHAMMAD ASIM SHAIKH (EE-171089)

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
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
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
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
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)

You might also like