% WRITTEN by M.S. Branicky % Last modified: 10/07/04 figure(1) clf; % PROBLEM 3.50(e) k=-4:4; Xk=(1/2)*(1-exp(-(j*pi*k+1)))./(1+j*2*pi*k); subplot(2,1,1), stem(k,abs(Xk),'filled'), ylabel('|X[k]|'); title('Problem 3.50(e)'); subplot(2,1,2), stem(k,angle(Xk),'filled'), ylabel('\angle X[k]'), xlabel('k'); line([-4 4],[0 0]) print -deps 'pr3_50e.eps' figure(2) clf; % PROBLEM 3.51(b) t=-2:0.011:2; omega0=4*pi; x=j*exp(j*1*omega0*t)-j*exp(j*-1*omega0*t)+exp(j*3*omega0*t)+exp(j*-3*omega0*t); plot(t,x), xlabel('t'), ylabel('x(t)'), grid on; title('Problem 3.51(b)'); print -deps 'pr3_51b.eps' figure(3) clf; % PROBLEM 3.100(c)(i) h=1/1000; t=0:h:1; x=2*(t>=1/2).*(t<=3/4); phi0=(t>=0); phi1=((t<1/2)-(t>1/2)); phi2=(t>=0)-2*(t>=1/4)+2*(t>=3/4); phi3=phi2.*phi1; phi4=(t>=0)-2*(t>=1/8)+2*(t>=3/8)-2*(t>=5/8)+2*(t>=7/8); phi5=phi4.*phi1; c0=1/2; c1=-1/2; c2=-1/2; c3=1/2; c4=0; c5=0; % Alternatively: c0=trapz(x.*phi0)*h, c1=trapz(x.*phi1)*h, ... xhat=c0*phi0+c1*phi1+c2*phi2+c3*phi3+c4*phi4+c5*phi5; plot(t,x,'-',t,xhat,'--'); xlabel('t'), axis([0 1 -0.1 2.1]); legend('x(t)','xhat(t)'); title('Problem 3.100(c)(i)'); print -deps 'pr3_100ci.eps' figure(4) clf; % PROBLEM 3.106 T=1; omega0=2*pi/T; allJ=[29 59 99]; t=-0.5:0.0001:0.5; xhat=0*t; for k=0:max(allJ), if (k==0), Bk=1/2; else if (rem(k,2)), Bk=2*(-1)^((k-1)/2)./(k*pi); else Bk=0; end; end; xhat=xhat+Bk*cos(k*omega0*t); if (find(k==allJ)), [k max(xhat)] ylabel1=sprintf('B[%d] cos(\\omega_0 t)',k); ylabel2=sprintf('x_{%d}(t)',k); plotfile=sprintf('pr3_106_%d.eps',k); titlestring=sprintf('Problem 3.106, k=%d',k); subplot(2,1,1), plot(t,Bk*cos(k*omega0*t)); ylabel(ylabel1); title(titlestring); subplot(2,1,2), plot(t,xhat); ylabel(ylabel2); xlabel('t'); print('-deps',plotfile); pause end; end;