Task #01: Code:-: Function
Task #01: Code:-: Function
Code:function [] = lab10_1( )
t=-3:0.01:3;
x0=1;
x1=(1/3)*exp(j*(-1)*2*pi*t)+(1/5)*exp(j*(1)*2*pi*t);
x2=(1/12)*exp(j*(-2)*2*pi*t)+(1/6)*exp(j*(2)*2*pi*t);
x3=(1/10)*exp(j*(-3)*2*pi*t)+(1/9)*exp(j*(3)*2*pi*t);
x=x0+x1+x2+x3;
subplot(3,2,1);
plot(t,real(x1));
axis([-3 3 -2 2]);
title('x1(t)');
subplot(3,2,2);
plot(t,real(x2));
axis([-3 3 -2 2]);
title('x2(t)');
subplot(3,2,3);
plot(t,real(x3));
axis([-3 3 -2 2]);
title('x3(t)');
subplot(3,2,4);
plot(t,real(x));
axis([-3 3 -1 4]);
title('x(t)');
end
Output:-
Task #02:
Code:function [] =lab10_2( )
t=-3:0.01:3;
x0=1;
x1=(2)*exp(j*(-1)*2*pi*t)+(2)*exp(j*(1)*2*pi*t);
x3=(-4*j)*exp(j*(-3)*2*pi*t)+(4*j)*exp(j*(3)*2*pi*t);
x=x0+x1+x3;
subplot(2,2,1);
plot(t,x1);
axis([-3 3 -15 15]);
title('x1(t)');
subplot(2,2,2);
plot(t,x3);
axis([-3 3 -15 15]);
title('x2(t)');
subplot(2,2,3);
plot(t,x);
axis([-3 3 -15 15]);
end
Output:-
Task #03:
Code:function [] = lab10_3()
t=-4:0.01:4;
n=5;
x0=1;
a1=exp(j*pi/4);
a2=2*exp(j*pi/3);
x1=a1*exp(j*(2)*2*n*t)+(conj(a1))*exp(j*(-2)*n*t);
x2=(a2)*exp(j*(4)*n*t)+(conj(a2))*exp(j*(-4)*n*t);
x=x0+x1+x2;
subplot(2,2,1);
plot(t,real(x1));
axis([-4 4 -10 10]);
title('x1(t)');
subplot(2,2,2);
plot(t,real(x2));
axis([-4 4 -10 10]);
title('x2(t)');
subplot(2,2,3);
plot(t,real(x));
axis([-4 4 -10 10]);
title('x(t)');
end
Output:-
Task #04:
Code:function [] = lab10_4()
k=-15:15;
t=1;
%for the dutycycle 1/4
t1=1/4;
ak1=sin(k*2*pi*(t1/t))./(k*pi);
ak1(16)=2*t1/t;
set(gcf,'defaultaxesfontsize',8);
subplot(3,1,1);
stem(k,ak1,'filled');
ylabel('ak');
title('FS Coefficients for Periodic Square Wave (T=1, T1=1/4)');
%for the dutycycle 1/8
t1=1/8;
ak2=sin(k*2*pi*(t1/t))./(k*pi);
ak2(16)=2*t1/t;
set(gcf,'defaultaxesfontsize',8);
subplot(3,1,2);
stem(k,ak2,'filled');
ylabel('ak');
title('FS Coefficients for Periodic Square Wave (T=1, T1=1/8)');
%for the dutycycle 1/16
t1=1/16;
ak3=sin(k*2*pi*(t1/t))./(k*pi);
ak3(16)=2*t1/t;
set(gcf,'defaultaxesfontsize',8);
subplot(3,1,3);
stem(k,ak3,'filled');
ylabel('ak');
title('FS Coefficients for Periodic Square Wave (T=1, T1=1/16)');
end
Output:-
Task #05:
Code:function [] = lab10_5( )
t=-1.5:0.005:1.5;
T=1;
T1=1/4;
w=2*pi/T;
m=10;
k=-m:m;
ak=sin(k*2*pi*(T1/T))./(k*pi);
ak(m+1)=2*T1/T;
x=zeros(1,length(t));
for k=-m:m
x=x+ak(k+m+1)*exp(j*k*w*t);
end
subplot(3,1,1);
plot(t,real(x));
xlabel('t');
ylabel('x(t)');
title('Reconstruction from Fourier Series with m=10 terms');
m1=20;
k=-m1:m1;
ak1=sin(k*2*pi*(T1/T))./(k*pi);
ak1(m1+1)=2*T1/T;
x1=zeros(1,length(t));
for k=-m1:m1
x1=x1+ak1(k+m1+1)*exp(j*k*w*t);
end
subplot(3,1,2);
plot(t,real(x1));
xlabel('t');
ylabel('x(t)');
title('Reconstruction from Fourier Series with m=20 terms');
m2=100;
k=-m2:m2;
ak2=sin(k*2*pi*(T1/T))./(k*pi);
ak2(m2+1)=2*T1/T;
x2=zeros(1,length(t));
for k=-m2:m2
x2=x2+ak2(k+m2+1)*exp(j*k*w*t);
end
subplot(3,1,3);
plot(t,real(x2));
xlabel('t');
ylabel('x(t)');
title('Reconstruction from Fourier Series with m=100 terms');
end
Output:-
Task #09:
Code:function [] = lab10_9( )
t=-1.5:0.005:1.5;
xcos=cos(2*pi*t);
xt=xcos>0;
T=1;
T1=0.25;
k=-15:15;
ak=sin(k*2*pi*(T1/T)./(k*pi));
ak(16)=T1/T;
M=5;
w=2*pi/T;
akm=xt.*exp(-j*M*w*t);
subplot(2,2,1)
stem(k,ak,'filled');
title('FS cofficent of the square waves');
axis([-15 15 0 1]);
subplot(2,2,2)
plot(t,akm);
end
Output:-