Experiment-4 Submitted By-Hritik Agarwal Enroll-19102131 Batch-A5 INLAB Q1) %INLAB EXERCISE %Q1) n=-20:20 x1=2*sin((2*pi*n)/8).*(n>=0) x2=-4*exp((-n)/6) %a)x1[n]x2[n] x=x1.*x2 subplot(3,2,1) stem(n,x) xlabel('n') ylabel('x[n]') title('x1[n]x2[n]') %b)4x1[n]+2x2[n] x=4*x1+2*x2 subplot(3,2,2) stem(n,x) xlabel('n') ylabel('x[n]') title('4x1[n]+2x2[n]') %c)x1[2n]x2[3n] ds1=2 ds2=3 n_x1=n(mod(n,ds1)==0) ds_x1=x1(n_x1(1)-n(1)+1:ds1:n_x1(end)-n(1)+1) n_x2=n(mod(n,ds2)==0) ds_x2=x2(n_x2(1)-n(1)+1:ds2:n_x2(end)-n(1)+1) new_n=unique(floor(n_x2/ds2)) x=ds_x1(5:17).*ds_x2 subplot(3,2,3) stem(new_n,x) xlabel('n') ylabel('x[n]') title('x1[2n]x2[3n]') %d)x1[2n]/x2[-n] ds1=2 n_x1=n(mod(n,ds1)==0) ds_x1=x1(n_x1(1)-n(1)+1:ds1:n_x1(end)-n(1)+1) new_n=unique(floor(n/ds1)) ds_x2=x2(length(x2):-1:1) x=ds_x1./ds_x2(11:31) subplot(3,2,4) stem(new_n,x) xlabel('n') ylabel('x[n]') title('x1[2n]/x2[-n]') %e)3x1[n/2]+2x2[n/3] ds_x1=zeros(1,81) for i =-40:40 if mod(i,2)==0 ds_x1(i+41)=3.*x1((i/2)+21) end end ds_x2=zeros(1,121) for i =-60:60 if mod(i,3)==0 ds_x2(i+61)=2.*x2((i/3)+21) end end ds_x2(21:101)=ds_x2(21:101)+ds_x1(1:81) subplot(3,2,5) stem(-60:60,ds_x2) xlabel('n') ylabel('x[n]') title('3x1[n/2]+2x2[n/3]') Q2) %Q2) n=-7:7 x=[-4,-6,-5,-4,-3,-2,-1,0,1,2,2/3,2/4,2/5,2/6,2/7] subplot(321) stem(n,x) xlabel('n') ylabel('x[n]') title('x[n]') %a)x[-n] ds_x1=x(length(x):-1:1) subplot(322) stem(n,ds_x1) xlabel('n') ylabel('x1[n]') title('x[-n]') %b)x[3-n] subplot(323) stem(n+3,ds_x1) xlabel('n') ylabel('x2[n]') title('x[3-n]') %c)x[2n] n_x3=n(mod(n,2)==0) ds_x3=x(n_x3(1)-n(1)+1:2:n_x3(end)-n(1)+1) new_n=unique(floor(n_x3/2)) subplot(324) stem(new_n,ds_x3) xlabel('n') ylabel('x3[n]') title('x[2n]') %d)x[n/2] ds_x4=zeros(1,29) for i =-14:14 if mod(i,2)==0 ds_x4(i+15)=x((i/2)+8) end end subplot(325) stem(-14:14,ds_x4) xlabel('n') ylabel('x4[n]') title('x[n/2]') Q3) %Q3) t=-1:0.01:1 x=(t+1).*(t>=-1)-(t+1).*(t>=0)-(t-1).*(t>=0)+(t-1).*(t>=1) subplot(221) plot(t,x) xlabel('t') ylabel('x(t)') title('x(t)') %a)x(3t) subplot(222) plot(t/3,x) xlabel('t') ylabel('x(t)') title('x(3t)') %b)x(3t+2) subplot(223) plot((t-2)/3,x) xlabel('t') ylabel('x2(t)') title('x(3t+2)') %c)x(2-t) subplot(224) plot(-(t-2),x) xlabel('t') ylabel('x4(t)') title('x(2-t)') POSTLAB Q1) %POST LAB EXERCISE %Q1) plot t=-1:0.01:7 x=2*t.*(t>=-1)-(2*t-2).*(t>=1)-(t-3).*(t>=2)+(t-4).*(t>=4)-(t-5).*(t>=5)+(t-6).*(t>=7) plot(t,x) xlabel('t') ylabel('x(t)') title('x(t)') Q2) %Q2) n=-4:2 x=[0,-1,0,2,1,1,0] subplot(2,2,1) stem(n,x) xlabel('n') ylabel('x(n)') title('x(n)') %a)x(2n) n_x=n(mod(n,2)==0) ds_x=x(n_x(1)-n(1)+1:2:n_x(end)-n(1)+1) new_n=unique(floor(n/2)) subplot(2,2,2) stem(new_n,ds_x) xlabel('n') ylabel('x(n)') title('x(2n)') %b)x(3n-1) n_x=n(mod((n+1),3)==0) ds_x=x(n_x(1)-n(1)+1:3:n_x(end)-n(1)+1) subplot(2,2,3) stem(-1:1,ds_x) xlabel('n') ylabel('x(n)') title('x(3n-1)') %c)x(3-n) ds_x=[x(length(n):-1:5),x(4),x(1:3)] subplot(224) stem(n+3,ds_x) xlabel('n') ylabel('x(n)') title('x(3-n)') Q3) %Q3) t=-2:0.001:8 x=(2*t-4).*(t>=-2)+(5*t).*(t>=0)-(5*t-20).*(t>=4)+(2*t+14).*(t>=8) subplot(2,2,1) plot(t,x) xlabel('t') ylabel('x(t)') title('x(t)') %a)3x(t+1) subplot(2,2,2) plot(t-1,3.*x) xlabel('t') ylabel('x1(t)') title('3x(t+1)') %b)x(4t) subplot(223) plot(t/4,0.5.*x) xlabel('t') ylabel('x(t)') title('x(4t)') %c)x((t-1)/2) subplot(2,2,4) plot(2*t+1,-2.*x) xlabel('t') ylabel('x(t)') title('x((t-1)/2)')