%Question(1): %A)1- n1=[-12:12]; x1=[-2,-1,0,1,2]; x1=[x1 x1 x1 x1 x1]; stem(n1,x1); title('Plotting five periods'); xlabel('n1'); ylabel('x1'); figure %A)2- n2=[0:20]; x2=exp(0.1*n2).*[stepseg(0,0,20)-stepseg(20,0,20)]; x2=[x2 x2 x2]; %n2=[0:62]; n2=[-21:41]; stem(n2,x2); title('Plotting three periods'); xlabel('n2'); ylabel('x2=e^(0.1*n2)*[u(n)-u(n-20)]'); figure %A)3- n3=[0:10]; x3=sin(0.1*pi*n3).*[stepseg(0,0,10)-stepseg(10,0,10)]; x3=[x3 x3 x3 x3]; n3=[-22:21]; stem(n3,x3); title('Plotting four periods'); ylabel('x3=sin(0.1*pi*n3)*[u(n)-u(n-10)]'); xlabel('n3'); figure %A)4- n4=[0:24] x4a=[1,2,3]; x4b=[1,2,3,4]; x4a=[x4a x4a x4a x4a x4a x4a x4a x4a 1]; %to suits the n[0:24] 25 elements x4b=[x4b x4b x4b x4b x4b x4b 1]; %to suits the n[0:24] 25 elements x4=x4a+x4b; stem(n4,x4); title('The sum of two periodic signals'); xlabel('n4'); ylabel('x4'); figure %------------------------------------------------------------------------------- %B) x=[2,4,-3,1,-5,4,7]; n=[-3,3]; %B)1- [x1,n1]=sigshift(x,n,3); %x(n-3) [x2,n2]=sigshift(x,n,-4); %x(n+4) [x12,n12]=sigadd(2*x1,n1,3*x2,n2); %x12=2*x(n-3)+3*x(n+4) [xfinal,nfinal]=sigadd(x12,n12,-1*x,n); %xfinal=2*x(n-3)+3*x(n+4)-x(n) stem(nfinal,xfinal); xlabel('nfinal'); ylabel('2*x(n-3)+3*x(n+4)-x(n)'); figure %B)2- [x1,n1]=sigshift(x,n,-4); %x1=x(n+4) [x2,n2]=sigshift(x,n,-5); %x2=x(n+5) [x12,n12]=sigadd(4*x1,n1,5*x2,n2); %x12=4*x(n+4)+5*x(n+5) [xfinal,nfinal]=sigadd(x12,n12,2*x,n); %xfinal=4*x(n+4)+5*x(n+5)+2*x(n) stem(nfinal,xfinal); xlabel('nfinal'); ylabel('4*x(n+4)+5*x(n+5)+2*x(n)'); figure %B)3- [x1,n1]=sigshift(x,n,-3); %x1=x(n+3) [x2,n2]=sigshift(x,n,2); %x2=x(n-2) [x3,n3]=sigshift(x,n,-1); %x3=x(n+1) [x4,n4]=sigfold(x3,n3) %x4=x(1-n) [x12,n12]=sigmult(x1,n1,x2,n2); %x12=x(n+3)*x(n-2) [x34,n34]=sigmult(x3,n3,x4,n4); %x34=x(n+1)*x(1-n) [xfinal,nfinal]=sigadd(x12,n12,x34,n34) %xfinal=x(n+3)*x(n-2)+x(n+1)*x(1-n) stem(xfinal,nfinal); xlabel('nfinal'); ylabel('x(n+3)*x(n-2)+x(n+1)*x(1-n)'); figure %B)4- x=[zeros(1,7) x zeros(1,7)]; n=[-10:10]; [x1,n1]=sigshift(x,n,-2); %x1=x(n+2); [x2,n2]=sigmult(x1,n1,cos(0.1*pi*n),n); %x2=x(n+2)*cos(2*pi*n) [x3,n3]=sigmult(x,n,exp(0.5*n),n); %x3=e^(0.5*n)*x(n) [xfinal,nfinal]=sigadd(2*x3,n3,x2,n2); %xfinal=2*e^(0.5*n)*x(n)+x(n+2)*cos(2*pi*n) stem(xfinal,nfinal) xlabel('nfinal'); ylabel('2*e^(0.5*n)*x(n)+x(n+2)*cos(2*pi*n)'); figure %------------------------------------------------------------------------------- %Question(2): %i) x1=[1,2,4]; nx=[0:2]; h1=[1,1,1,1,1]; nh=[-2:2]; [y,ny]=conv_m(x1,nx,h1,nh); stem(ny,y); title('Convolution'); xlabel('ny'); ylabel('y=x1*h1'); figure %ii) x2=[0,1,-2,3,-4]; nx=[0:4]; h2=[0.5,1,2,1,0.5]; nh=[-2:2]; [y1,ny1]=conv_m(x2,nx,h2,nh); stem(ny1,y1); title('Convolution'); xlabel('ny'); ylabel('y=x1*h1'); figure %iii) x3=[1,2,3,4]; nx=[0:3]; h3=[4,3,2,1]; nh=[0:3]; [y3,ny3]=conv_m(x3,nx,h3,nh) stem(ny3,y3); title('convolution'); xlabel('ny3'); ylabel('y=x*h'); figure %iv) x4=[1,2,3,4]; h4=[1,2,3,4]; n4=[0:3]; [y4,ny4]=conv_m(x4,n4,h4,n4); stem(ny4,y4); title('convolution'); xlabel('ny3'); ylabel('y=x*h'); figure %------------------------------------------------------------------------------ %Question(3):