You are on page 1of 3

LAB-01

AIM- Introduction of plotting using basic function.

MATLAB CODE-

%1st function program


clc;
t=0:0.01:1;
N=length(t);
xt=zeros(1,N);
for n=1:N
temp=0;
for k=1:3
temp=temp+(1/(2*k-1))*sin(2*pi*(2*k-1)*t(n));
end
xt(n)=temp;
end
plot (t,xt);
xlabel('t');
ylabel('xt');

RESULT-

0.8

0.6

0.4

0.2

0
xt

-0.2

-0.4

-0.6

-0.8

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
MATLAB CODE-

% code for sine wave


close all;
clear all;
clc;
t=0:0.01:1;
N=length(t);
xt=zeros(1,N);
for n=1:N
temp=0;
for k=1:3
temp=sin(2*pi*(2*k-1)*t(n));
end
xt(n)=temp;
end
plot (t,xt);
xlabel('t');
ylabel('xt');

RESULT-

0.8

0.6

0.4

0.2

0
xt

-0.2

-0.4

-0.6

-0.8

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t
MATLAB CODE-

%2nd code for to reduce steps


clc;
clear all;
close all;
t=0:0.01:1;
xt=zeros(1,length(t));
temp=0;
for k=1:3
temp=temp+(1/(2*k-1))*sin(2*pi*(2*k-1)*t);
end
xt=temp;
plot (t,xt);
xlabel('t');
ylabel('xt');

RESULT-

0.8

0.6

0.4

0.2

0
xt

-0.2

-0.4

-0.6

-0.8

-1
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
t

You might also like