PLOTTING UNIT STEP FUNCTION USING
DIFFERENT COMMANDS IN M-FILE
FOR CONTINUOUS TIME ‘t’:
UNIT STEP FUNCTION PLOT:
1ST METHOD:
%unit step function
t=-8:0.01:8
unit=(sign(t+eps)+1)/2
plot(t,unit,'linewidth',3),grid on
legend({'Unit Step Signal'},'FontSize',14,'FontName','Times New Roman')
xlabel({'Time(second)'},'FontSize',14,'FontName','Times New Roman')
ylabel({'Unit'},'FontSize',14,'FontName','Times New Roman')
title ({'Unit Step Function'},'FontSize',14,'FontName','Times New Roman')
gtext({'Unit Step'},'FontSize',14,'FontName','Times New Roman')
axis([min(t)-1 max(t)+1 min(unit)-1 max(unit)+1])
OUTPUT:
2nd METHOD:
USING HEAVISIDE COMMAND:
t=-7:0.01:7
plot(t,heaviside(t),'r','linewidth',3),grid on
legend({'Unit Step Signal'},'FontSize',14,'FontName','Times New Roman')
xlabel({'Time(second)'},'FontSize',14,'FontName','Times New Roman')
ylabel({'Unit'},'FontSize',14,'FontName','Times New Roman')
title ({'Heaviside Step Function'},'FontSize',14,'FontName','Times New
Roman')
gtext({'Heaviside Step Function'},'FontSize',14,'FontName','Times New Roman')
OUTPUT:
FOR DISCRETE TIME:
1st METHOD:
DISCRET UNIT STEP FUNCTION:
%Discret Time Unit Step Function
n=-10:10
unit=(sign(n+eps)+1)/2
stem(n,unit,'linewidth',3),grid on
legend({'Unit Step Signal'},'FontSize',14,'FontName','Times New Roman')
xlabel({'Samples'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u[n]'},'FontSize',14,'FontName','Times New Roman')
title ({'Discrete Time Step Function'},'FontSize',14,'FontName','Times New
Roman')
gtext({'Discrete Time'},'FontSize',14,'FontName','Times New Roman')
axis([min(n)-1 max(n)+1 min(unit)-1 max(unit)+1])
OUTPUT:
2nd METHOD:
DISCRETE HEAVISIDE STEP FUNCTION:
An alternative form of the unit step, as a function of a discrete variable n using half convention:
where n is any integer value.
CODE:
t=-10:10
n=-5:length(t)
stem(n,heaviside(n),'y','linewidth',3),grid on
legend({'Unit Step Signal'},'FontSize',14,'FontName','Times New Roman')
xlabel({'Time(second)'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u[n]'},'FontSize',14,'FontName','Times New Roman')
title ({'Heaviside Discrete Step Function'},'FontSize',14,'FontName','Times
New Roman')
gtext({'Heaviside Discrete Step Function'},'FontSize',14,'FontName','Times
New Roman')
OUTPUT:
CONTINUOUS TIME:(UNIT STEP FUNCTION)
USING LOOP:
%UNIT STEP FUNCTION USING LOOP FOR CONTINUOUS TIME
t=-3:0.01:3
for i=1:length(t)
if t(i)>=0
x(i)=1;
elseif t(i)<0
x(i)=0
end
end
plot(t,x,'linewidth',3),grid on
legend({'Unit Step Signal u(t)'},'FontSize',14,'FontName','Times New Roman')
xlabel({'Time(seconds)'},'FontSize',14,'FontName','Times New Roman')
ylabel({'x(t)'},'FontSize',14,'FontName','Times New Roman')
title ({'Unit Step Function'},'FontSize',14,'FontName','Times New Roman')
gtext({'Unit Step Function'},'FontSize',14,'FontName','Times New Roman')
axis([min(t) max(t) min(x)-1 max(x)+1])
OUTPUT:
ANOTHER WAY OF PLOTTING STEP FUNCTION:
t=-3:0.001:3
u=0.*(t<0)+1.*(t>0);
plot(t,u,'linewidth',3),grid on
legend({'Unit Step Signal u(t)'},'FontSize',14,'FontName','Times New Roman')
xlabel({'Time(second)'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u(t)'},'FontSize',14,'FontName','Times New Roman')
title ({'Unit Step Function'},'FontSize',14,'FontName','Times New Roman')
gtext({'Unit Step Function'},'FontSize',14,'FontName','Times New Roman')
axis([min(t) max(t) min(u)-1 max(u)+1])
OUTPUT:
DISCRETE TIME : (UNIT STEP FUNCTION)
USING LOOP:
%UNIT STEP FUNCTION USING LOOP FOR DISCRETE TIME
n=-3:0.01:3
for i=1:length(n)
if n(i)>=0
x(i)=1;
elseif n(i)<0
x(i)=0
end
end
stem(n,x,'linewidth',3),grid on
legend({'Discrete Unit Step Signal u(t)'},'FontSize',14,'FontName','Times New
Roman')
xlabel({'Samples'},'FontSize',14,'FontName','Times New Roman')
ylabel({'x[n]'},'FontSize',14,'FontName','Times New Roman')
title ({'Discrete Time Unit Step Function'},'FontSize',14,'FontName','Times
New Roman')
gtext({'Discrete Time Unit Step Function'},'FontSize',14,'FontName','Times
New Roman')
axis([min(t) max(t) min(x)-1 max(x)+1])
OUTPUT:
ANOTHER WAY OF PLOTTING DISCRETE TIME SIGNALS:
n=-3:0.001:3
u=0.*(n<0)+1.*(n>0);
stem(n,u,'linewidth',3),grid on
legend({'Discrete Unit Step Signal u[n]'},'FontSize',14,'FontName','Times New
Roman')
xlabel({'Samples'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u[n]'},'FontSize',14,'FontName','Times New Roman')
title ({'Discrete Time Unit Step Function'},'FontSize',14,'FontName','Times
New Roman')
gtext({'Discrete Time Unit Step Function'},'FontSize',14,'FontName','Times
New Roman')
axis([min(t) max(t) min(x)-1 max(x)+1])
OUTPUT:
SUB-PLOTTING POLAR AND NON-POLAR FUNCTION:
%SUB-PLOTTING Ae^(jwt+theta) AND A(cos(wt+theta)+jsin(wt+theta))
figure(1)
t=0:0.001:10
f=0.5
A=2
theta=0
y11=A*exp(j*2*pi*f*t+theta)
s(1)=subplot(2,1,1)
plot(t,y11,'k','linewidth',3),grid on
legend(s(1),'y11','FontSize',14,'FontName','Times New Roman')
xlabel (s(1),'Time(second)','FontSize',14,'FontName','Times New Roman')
ylabel (s(1),'y11(t)','FontSize',14,'FontName','Times New Roman')
title (s(1),'Non Polar Form Of A Complex
Function','FontSize',14,'FontName','Times New Roman')
y22=A*(cos(2*pi*f*t+theta)+j*sin(2*pi*f*t+theta))
s(2)=subplot(2,1,2)
plot(t,y22,'linewidth',3),grid on
legend(s(2),'y22','FontSize',14,'FontName','Times New Roman')
xlabel (s(2),'Time(second)','FontSize',14,'FontName','Times New Roman')
ylabel (s(2),'y22(t)','FontSize',14,'FontName','Times New Roman')
title (s(2),'Polar Form Of A Complex
Function','FontSize',14,'FontName','Times New Roman')
OUTPUT:
SUB-PLOTTING SINE AND COSINE:
%SUB-PLOTTING Asin(wt+theta) and Acos(wt+theta)
figure(1)
t=0:0.001:10
f=0.5
A=2
theta=0
y11=A*sin(2*pi*f*t+theta)
s(1)=subplot(2,1,1)
plot(t,y11,'k','linewidth',3),grid on
legend(s(1),'y11','FontSize',14,'FontName','Times New Roman')
xlabel (s(1),'Time(second)','FontSize',14,'FontName','Times New Roman')
ylabel (s(1),'y11(t)','FontSize',14,'FontName','Times New Roman')
title (s(1),'Sin Function','FontSize',14,'FontName','Times New Roman')
y22=A*cos(2*pi*f*t+theta)
s(2)=subplot(2,1,2)
plot(t,y22,'linewidth',3),grid on
legend(s(2),'y22','FontSize',14,'FontName','Times New Roman')
xlabel (s(2),'Time(second)','FontSize',14,'FontName','Times New Roman')
ylabel (s(2),'y22(t)','FontSize',14,'FontName','Times New Roman')
title (s(2),'Cos Function','FontSize',14,'FontName','Times New Roman')
OUTPUT:
SUB-PLOTTING SIN AND COS WITH DISCRETE TIME:
%SUB-PLOTTING Asin(wn+theta) and Acos(wn+theta)
figure(1)
n=-10:10
f=0.5
A=2
theta=0
y11=A*sin(2*pi*f*n+theta)
s(1)=subplot(2,1,1)
stem(n,y11,'k','linewidth',3),grid on
legend(s(1),'y11','FontSize',14,'FontName','Times New Roman')
xlabel (s(1),'Sample Time','FontSize',14,'FontName','Times New Roman')
ylabel (s(1),'y11[n]','FontSize',14,'FontName','Times New Roman')
title (s(1),'Sin Function','FontSize',14,'FontName','Times New Roman')
y22=A*cos(2*pi*f*n+theta)
s(2)=subplot(2,1,2)
stem(n,y22,’b’,'linewidth',3),grid on
legend(s(2),'y22','FontSize',14,'FontName','Times New Roman')
xlabel (s(2),'Sample Time','FontSize',14,'FontName','Times New Roman')
ylabel (s(2),'y22[n]','FontSize',14,'FontName','Times New Roman')
title (s(2),'Cos Function','FontSize',14,'FontName','Times New Roman')
OUTPUT:
SUB-PLOTTING REAL VALUE EXONENTIAL FUNCTIONS WITH
CONTINUOUS TIME:
% if b is +ive then increasing exp or if b is -ive then decreasing exp
t=-2:0.001:2
b1=-2
b2=2
A=1
y33=A*exp(b1*t)
y44=A*exp(b2*t)
s(1)=subplot(2,1,1)
plot(t,y33,'b','linewidth',3),grid on
legend(s(1),'y33')
xlabel(s(1),'Time(second)','FontSize',14,'FontName','Times New Roman')
ylabel(s(1),'Decaying exponential','FontSize',14,'FontName','Times New
Roman')
title(s(1),'Decaying','FontSize',14,'FontName','Times New Roman')
s(2)=subplot(2,1,2)
plot(t,y44,'k','linewidth',3),grid on
legend(s(2),'y44','FontSize',14,'FontName','Times New Roman')
xlabel('Time (second)','FontSize',14,'FontName','Times New Roman')
ylabel('Growing exponential','FontSize',14,'FontName','Times New Roman')
title('Growing','FontSize',14,'FontName','Times New Roman')
OUTPUT:
REAL VALUE EXPONENTIAL FUNCTION WITH DISCRETE SMAPLING:
% if b is +ive then increasing exp or if b is -ive then decreasing exp
n=-3:3
b1=-2
b2=2
A=1
y33=A*exp(b1*n)
y44=A*exp(b2*n)
s(1)=subplot(2,1,1)
stem(n,y33,'b','linewidth',3),grid on
legend(s(1),'y33[n]')
xlabel(s(1),'Time(second)','FontSize',14,'FontName','Times New Roman')
ylabel(s(1),'Decaying exponential','FontSize',14,'FontName','Times New
Roman')
title(s(1),'Decaying','FontSize',14,'FontName','Times New Roman')
axis(s(1),[min(n)-1 max(n)+1 min(y33) max(y33)])
s(2)=subplot(2,1,2)
stem(n,y44,'k','linewidth',3),grid on
legend(s(2),'y44[n]','FontSize',14,'FontName','Times New Roman')
xlabel('Time (second)','FontSize',14,'FontName','Times New Roman')
ylabel('Growing exponential','FontSize',14,'FontName','Times New Roman')
title('Growing','FontSize',14,'FontName','Times New Roman')
axis(s(2),[min(n)-1 max(n)+1 min(y33) max(y33)])
OUTPUT:
SUB-PLOTTING CONTINUOUS AND DISCRETE SIGNALS IMPULSES:
figure(1)
%unit impulse
n=-3:3
y=zeros(1,7)
y(1,4)=1
f(1)=subplot(2,1,1)
stem(n,y,'linewidth',3),grid on
legend(f(1),'y[n]','FontSize',14,'FontName','Times New Roman')
xlabel(f(1),'Sample Time','FontSize',14,'FontName','Times New Roman')
ylabel(f(1),'y[n]','FontSize',14,'FontName','Times New Roman')
title(f(1),'Impulse for Discrete Signal','FontSize',14,'FontName','Times New
Roman')
%for continious
t=-5:0.001:5
Impulse=1.*(t==0)
%=1.*(t==1)-1.*(t==-1)+2.*(t==2)
f(2)=subplot(2,1,2)
plot(t,Impulse,'linewidth',3),grid on
legend(f(2),'I(t)','FontSize',14,'FontName','Times New Roman')
xlabel (f(2),'Sample Time','FontSize',14,'FontName','Times New Roman')
ylabel (f(2),'I(t)','FontSize',14,'FontName','Times New Roman')
title (f(2),'Impulse For Continuous Signal','FontSize',14,'FontName','Times
New Roman')
OUTPUT:
3-D PLOTTIING : (CONTINUOUS TIME)
t=-10:0.01:10
x1=cos(2*pi/3*t)
y1=sin(2*pi/3*t)
plot3(t,x1,y1,'linewidth',3),grid on
xlabel('Time (seconds)','FontSize',14,'FontName','Times New Roman')
ylabel('x1 projection','FontSize',14,'FontName','Times New Roman')
zlabel('y1 projection','FontSize',14,'FontName','Times New Roman')
title('3-D GRAPHING','FontSize',14,'FontName','Times New Roman')
OUTPUT:
3-D PLOT FOR DISCRETE TIME:
n=-10:10
x1=cos(2*pi/3*n)
y1=sin(2*pi/3*n)
plot3(n,x1,y1,'linewidth',3),grid on
xlabel('Samples','FontSize',14,'FontName','Times New Roman')
ylabel('x1 projection','FontSize',14,'FontName','Times New Roman')
zlabel('y1 projection','FontSize',14,'FontName','Times New Roman')
title('3-D GRAPHING','FontSize',14,'FontName','Times New Roman')
OUTPUT: