%question1 %define the tri function function y=tri(n) y=rampDT(n+10)-2*rampDT(n)+rampDT(n-10); %in the command window n = -50:50; y = tri(n); stem(n, y); xlabel('n'); ylabel('y'); title('Triangular waveform'); %question2 n=-150:150; N=25; %Period of the signal periodicTriangle=zeros(1,length(n)); for k=-5:5 periodicTriangle=periodicTriangle+tri(n-k*N); end figure(1) stem(n,tri(n),'r') figure(2) stem(n,periodicTriangle) %question3 %define the tricon function function y=tricon(t) y=ramp(t+10)-2*ramp(t)+ramp(t-10); %in the command window n = -50:50; y = tricon(n); plot(n, y); xlabel('n'); ylabel('y'); title('Triangular waveform'); %in the command window n=-150:150; N=25; %Period of the signal periodicTriangle=zeros(1,length(n)); for k=-5:5 periodicTriangle=periodicTriangle+tricon(n-k*N); end figure(1) plot(n,tricon(n),'r') figure(2) plot(n,periodicTriangle) %question4 %define the function function y = rect(t) y = u(t + 5) - u(t - 5); %define the function %in the command window t = -20:0.01:20; n = -20:20; xDT = rectDT(n); x = rect(t); figure(1) plot(t,x); figure(2) stem(n,xDT); %question5 %in the command window t=-150:150; T=30; %Period of the signal periodicRectangleCT=zeros(1,length(t)); for k=-5:5 periodicRectangleCT=periodicRectangleCT+rect(t-k*T); end figure(1) plot(t,rect(t),'r') figure(2) plot(t,periodicRectangleCT) %in the command window n=-150:150; N=30; %Period of the signal periodicRectangle=zeros(1,length(n)); for k=-5:5 periodicRectangle=periodicRectangle+rectDT(n-k*N); end figure(1) stem(n,rectDT(n),'r') figure(2) stem(n,periodicRectangle) %question8 %in the command window t=-9000:0.1:9000; xt=rect((t-3)/10); xt_sq=xt.^2; energy=trapz(t,xt_sq); disp('Energy of the signal is: '); disp(energy); %in the command window t = -9000:0.1:9000; xt = rect((t-3)/10); xt_sq = xt.^2; energy = trapz(t, xt_sq); disp(['Energy of the signal is: ', num2str(energy)]);