%question1 %first write function in part a) function y=xcon(t) y=(exp(-2*t)).*(u(t)-u(t-4)); %write function in part b) function y=xdis(n) y=(exp(-n)).*(stepDT(n)-stepDT(n-4)); %periodic function of xcon t=-150:150; N=25; periodicxcon=zeros(1,length(t)); for k=-5:5 periodicxcon=periodicxcon+xcon(t-k*N); end plot(t,periodicxcon) %periodic function of xdis n=-150:150; N=25; periodicxdis=zeros(1,length(n)); for k=-5:5 periodicxdis=periodicxdis+xdis(n-k*N); end stem(n,periodicxdis) %energy of xcon t=-10:10; xcon_square=(xcon(t)).^2; energy=trapz(t,xcon_square); disp('energy of the signal is: '); disp(energy); %energy of xdis n=-10:10; xdis_square=(xdis(n)).^2; energy=sum(xdis_square); disp('energy of the signal is: '); disp(energy); %question2 %first define functions and plot them %function in part a) function y=xxa(n) y=(cos((pi*n)/3)).*(stepDT(n)-stepDT(n-6)); %function in part b) function y=xxb(n) y=(((-1).^n)/3).*(stepDT(n)); %in the command window n=-10:10; subplot(2,1,1) stem(n,xxa(n),'g') subplot(2,1,2) stem(n,xxb(n),'m') %energy of xxa, notice that energy stays same % as range of n is increased n=-9000:9000; xxa_square=(xxa(n)).^2; xxa_energy=sum(xxa_square); disp('energy of xxa is: '); disp(xxa_energy); %energy of xxb, notice that energy becomes infinite when %range of n is increased n=-9000:9000; xxb_square=(xxb(n)).^2; xxb_energy=sum(xxb_square); disp('energy of xxb is: '); disp(xxb_energy); % question3 %first, define and plot the functions %function in part a) function y = stepDT(n) y = (n >= 0); ss = find(round(n)~= n); %F ind noninteger values of n if(~isempty(ss)) y(ss) = NaN; end %function in part b) function y=xx3b(n) y=(-1).^n; %function in part c) function y=xx3c(n) y=exp((-j*pi*n)/2); %let's plot the signals n=-50:50; subplot(3,1,1) stem(n,unitstepDT(n),'g') subplot(3,1,2) stem(n,xx3b(n),'m') subplot(3,1,3) stem(n,xx3c(n),'y') %power of the first signal, notice that energy becomes infinity %when range of n is increased n=-1000:1000; unitstepDT_square=(unitstepDT(n)).^2; energy=sum(unitstepDT_square); power=energy/length(n); disp (['energy is: ',num2str(energy)]); disp (['power is: ',num2str(power)]); %power of signal xx3b, notice that energy becomes infinity %when range of n is increased n=-1000:1000; xx3b_square=(xx3b(n)).^2; energy=sum(xx3b_square); power=energy/length(n); disp (['energy is: ',num2str(energy)]); disp (['power is: ',num2str(power)]); %power of signal xx3c, notice that energy becomes infinity %when range of n is increased and also notice that we take %the square of magnitude because signal is complex n=-1000:1000; xx3c_square=(abs(xx3c(n))).^2; energy=sum(xx3c_square); power=energy/length(n); disp (['energy is: ',num2str(energy)]); disp (['power is: ',num2str(power)]); % question4 %first define functions function y=gncomplex(n) y=abs((j/4).^n).*stepDT(n); %in the command window n=-20:20; evenpart=(gncomplex(n) + gncomplex(-n))/2; oddpart=(gncomplex(n) - gncomplex(-n))/2; subplot(3,1,1) stem(n,evenpart,'r') subplot(3,1,2) stem(n,oddpart,'k') subplot(3,1,3) stem(n,evenpart+oddpart,'b') ne=-100:100; energy_even=sum(((gncomplex(ne) + gncomplex(-ne))/2).^2); disp('Energy of the even part is: ') disp(energy_even) energy_odd=sum(((gncomplex(ne) - gncomplex(-ne))/2).^2); disp('Energy of the odd part is: ') disp(energy_odd) energy=sum((gncomplex(ne)).^2); disp('Energy of the signal is: ') disp(energy) disp('Energy of the even+odd is: ') disp(energy_even+energy_odd) % question5 %first define signal function function y=xk(k) y = sinc(k/2) .* exp(-j*(2*pi*k)/4); %in the command window n=-100:100; xk_square=(abs(xk(n))).^2; xk_energy=sum(xk_square); disp('energy of xk is: '); disp(xk_energy)