Tugas PJJ Week 10 Praktik Pengolahan Sinyal Digital: For If Else End End
Tugas PJJ Week 10 Praktik Pengolahan Sinyal Digital: For If Else End End
Soal 1
Kodingan
clear
clc
n = -5 : 1 : 5
for i = 1:length(n)
if (n(i) < 0)
u(i) = 0
else
u(i) = 1
end
end
subplot(3,1,1)
stem(n,u,'-g','linewidth',2);
title('u(n)')
xlabel('n')
ylabel('Amplitudo')
for i = 1:length(n)
if (n(i)-4 < 0)
u1(i) = 0
else
u1(i) = 1
end
end
subplot(3,1,2)
stem(n,u1,'o','linewidth',2);
title('u(n-4)')
xlabel('n')
ylabel('Amplitude')
% x1(n) = u(n) - u(n-4)
for i = 1:length(n)
x1(i) = u(i) - u1(i);
end
subplot(3,1,3)
stem(n,x1,'r','linewidth',2);
title('x1(n) = u(n) - u(n-4)')
xlabel('n')
ylabel('Amplitude')
Hasil
Soal 2
Kodingan
clear
clc
n = -10:10;
for i = 1:length(n)
if (n(i)-3 >= 0)
u(i) = 1;
else
u(i) = 0;
end
end
subplot(2,1,1);
stem(n,u,'or','linewidth',2);
title('u[n-3]');
for i = 1:length(n)
x(i) = (1/2).^i .* u(i);
end
subplot(2,1,2);
stem(n,x,'c','linewidth',2);
title('x[n] = (1/2)^n * u[n-3]');
Hasil
Soal 3
Kodingan
clear
clc
n=-7:1:7;
for i=1:length(n)
if n(i)+2==0
d1(i)=0
else
d1(i)=1
end
end
subplot(3,1,1)
stem(n,d1,'-or'), title('d(n+2)')
for i=1:length(n)
if n(i)-2==0
d2(i)=1
else
d2(i)=0
end
end
subplot(3,1,2)
stem(n,d2,'-g'), title('d(n-2)')
for i=1:length(n)
y(i)=d1(i)-d2(i);
end
subplot(3,1,3)
stem(n,y,'-b'), title('y(i)=d1(i)-d2(i)')
Hasil
Soal 4
x(t) = 0 ≤ t ≤ 1 = 1
Kodingan
clear
clc
t = -10:0.1:10;
for i = 1:length(t)
if (t(i)>=0 & t(i)<= 1)
d(i) = 1;
elseif (t(i)>1 & t(i)< 2)
d(i) = -2
else d(i)=0;
end
end
plot(t,d,'-g','linewidth',2);
title('x(t)')
Hasil
Soal 5
x(1-t) + x(2-t)
Kodingan
clear
clc
t = -10:.1:10;
for i = 1:length(t)
if (1-t(i) >= 0 && 1-t(i) <= 1)
x(i) = 1;
elseif (1-t(i) > 1 && 1-t(i) < 5)
x(i) = -3;
else
x(i) = 0;
end
end
subplot(3,1,1);
plot(t,x,'-c','linewidth',2);
title('x[1-t]');
for i = 1:length(t)
if (2-t(i) >= 0 && 2-t(i) <= 1)
x1(i) = 1;
elseif (2-t(i) > 1 && 2-t(i) < 5)
x1(i) = -3;
else
x1(i) = 0;
end
end
subplot(3,1,2);
plot(t,x1,'-g','linewidth',2);
title('x[2-t]');
for i = 1:length(t)
y(i) = x(i) - x1(i);
end
subplot(3,1,3);
plot(t,y,'-b','linewidth',2);
title('y[t] = x[1-t] - x[2-t]');
Hasil