Ibrahim Siregar Matlab Soal Bab 2

download Ibrahim Siregar Matlab Soal Bab 2

of 3

Transcript of Ibrahim Siregar Matlab Soal Bab 2

  • % soal 2.1n=-5:5;n0=-2;n1=4;x=2*[(n-n0)==0]-[(n-n1)==0];figure(1);subplot(2,2,1);stem(n,x);axis([-5 5 -2 3]);title('deretan soal 1.a');xlabel('a');ylabel('x[n]')n=0:20;x1=n.*([(n)>=0]-[(n-10)>=0]);x2=10*exp(-0.3*(n-10)).*([(n-10)>=0]-[(n-20)>=0]);x=x1+x2;subplot(2,2,2);stem(n,x);axis([0 20 -2 12]);title('deretan soal 1.b');xlabel('n');ylabel('x[n]')n=0:50;x=cos(0.04*pi*n)+0.2*randn(size(n));subplot(2,2,3);stem(n,x);title('deretan soal 1.c');xlabel('n');ylabel('x[n]')n=-10:9;x=[5,4,3,2,1];xrep=x'*ones(1,4);xrep=(xrep(:))';subplot(2,2,4);stem(n,xrep);title('deretan soal 1.d');xlabel('n');ylabel('x[n]');

    %soal 2.3n=-10:10;alpha=-0.1+0.3j;x=exp(alpha*n);figure(3);subplot(2,2,1); stem(n,real(x)); title('deret real');xlabel('n'); ylabel('x[n]');subplot(2,2,2); stem(n,imag(x)); title('deret imajiner');xlabel('n'); ylabel('x[n]');subplot(2,2,3); stem(n,abs(x)); title('deret magnitudo');xlabel('n'); ylabel('x[n]');subplot(2,2,4); stem(n,(180/pi)*angle(x)); title('deret phasa');xlabel('n'); ylabel('x[n]');

    %soal 2.4n=[0:10];x=[(n)>=0]-[(n-10)>=0];figure(4); clf;subplot(2,2,1); stem(n,x); title('pulsa rectangular');xlabel('n'); ylabel('x[n]'); axis([-10,10,0,1.2]);m=-fliplr(n);m1=min([m,n]); m2=max([m,n]); m=m1:m2;nm=n(1)-m(1); n1=1:length(n);x1=zeros (1,length(m));x1(n1+nm)=x;x=x1;s=x+m;xe=0.5*(x+fliplr(x));x0=0.5*(x-fliplr(x));subplot(2,2,2); stem(m,xe); title('sinyal ganjil');xlabel('n'); ylabel('x even[n]'); axis([-10,10,-1,1.1]);

  • subplot(2,2,3); stem(s,x1); title('pulsa rectangular');xlabel('n'); ylabel('xs[n]'); axis([-10,10,0,1.2]);subplot(2,2,4); stem(m,x0); title('sinyal genap');xlabel('n'); ylabel('x odd[n]'); axis([-10,10,-1,1.1]);

    %soal 2.5n=[-5:50];x=[(n)>=0]-[(n-10)>=0]; %nx=[-5:50];h=((0.9).^n).*[(n)>=0]; %nh=[-5:50];%nya=nx(1)+nh(1); nyt=nx(length(x))+(length(h));%ny=[nya:nyt];%deret konvolusi adalah jumlah deret input+ jumlah deret responnyany=[-10:100];y=conv(x,h);figure(5);subplot(2,2,1); stem(n,x); axis([-5,50,0,2]); title('deretan input');xlabel('n'); ylabel('x[n]');subplot(2,2,2); stem(n,h); axis([-5,50,0,2]); title('respon implus');xlabel('n'); ylabel('h[n]');subplot(2,2,[3 4]); stem(ny,y); axis([-5,50,0,7]); title('output konvolusi');xlabel('n'); ylabel('y[n]');

    %soal 2.6x=[3 11 7 0 -1 4 2]; nx=-3:3;h=[2 3 0 -5 2 1]; nh=-1:4;nya=nx(1)+nh(1); nyt=nx(length(x))+ nh(length(h));ny=[nya:nyt];y=conv(x,h);figure(6);subplot(2,2,1); stem(nx,x); axis([-5 5 -7 12]); title('input');xlabel('n'); ylabel('x[n]');subplot(2,2,3); stem(nh,h); axis([-5 5 -7 12]); title('respon implus');xlabel('n'); ylabel('h[n]');subplot(2,2,[2 4]); stem(ny,y); axis([-5 5 -7 12]); title('konvolusi');xlabel('n'); ylabel('y[n]');

    %soal 2.9b=[1];a=[1, -1, 0.9];n=[-20:120];x=[(n)==0];h=filter(b,a,x);figure(9);subplot(2,1,1); stem(n,h); title('respons implus'); xlabel('n'); ylabel('h[n]');x=[(n)>=0];h=filter(b,a,x);subplot(2,1,2); stem(n,h); title('respons step'); xlabel('n'); ylabel('s[n]');

    %soal 2.10b=[1];a=[1, -0.9];n=-5:50;

  • x=[(n)>=0]-[(n-10)>=0];y=filter(b,a,x);figure(10); subplot(1,1,1);subplot(2,1,1); stem(n,y); axis([-5, 50, -0.5, 7]); title('output kovolusi');xlabel('n'); ylabel('y[n]');