PLease show all the work and steps. Thank you For all the questions below, use a
ID: 2248491 • Letter: P
Question
PLease show all the work and steps. Thank you
For all the questions below, use a time resolution of 1ms for your time axis: t [-2:0.001:2]. Remember your script should be self-sufficient. The answers to the questions below should be displayed one after the other after each key stroke as we discussed in the Matlab tutorial video!! Question 1 (40 points). Plot the following signals using Matlab. Label the signals as a(t), b(t), ct), and d(t). When you run your script, it should automatically plot all four signals in a single figure window with properly labeled)and (y) axis-as shown below b(t) c(t) d(t) Question 2 (20 points). Use Matlab to calculate the energy of the signals a(t), b(t), c(t) and d(t) you plotted as part of Question 1. Label signal energies as a_energy, b energy, etc. When you run your script, it should automatically calculate and display energies of the signals a, b, c and d one at a time with each key stroke. Question 3 (40 points). Plot the following time modified versions of the signals in question 1. Matlab should display a single plot for each part of this question with each key stroke. a. a(t/2+1) b. -b(-t-1) C. C(-2t+4)-1 d. dt+2)+1 When you run your script, it should automatically plot each signal in a single figure window with properly labeled (x) and (y) axis -and should proceed to next plot when you press any keyExplanation / Answer
close all
t=-2:0.001:2; % Initialising time
a=zeros(1,length(t));% Initialising the arrays that will store the signals
b=zeros(1,length(t));
c=zeros(1,length(t));
d=zeros(1,length(t));
%% Generating a(t)
% a(t) is a triangular waveform in the interval [-1,1] centered at origin
% and Zero elsewhere
ind1=intersect(find(t>=-2),find(t<-1));% find the indices of array 't' whose elements lie in the interval[-2,-1)
ind2=intersect(find(t>1),find(t<=2));% find the indices of array 't' whose elements lie in the interval(1,2]
ind=union(ind1,ind2);
a(ind)=0;
ind3=intersect(find(t>=-1),find(t<=0));% find the indices of array 't' whose elements lie in the interval[-1,0]
a(ind3)=t(ind3)+1;% In the interval t=[-1,0] a(t)=t+1
ind4=intersect(find(t>0),find(t<=1));% find the indices of array 't' whose elements lie in the interval(0,1]
a(ind4)=-t(ind4)+1;%% In the interval t=[-1,0] a(t)=-t+1
subplot(2,2,1)
plot(t,a,'r')
xlabel('t');
ylabel('a(t)');
title('a(t) vs t');
axis([-3,3,-3,3])
axis equal
grid
%% Generating b(t)
%b(t) is a rectangular function with amplitude 1 in [-1,1] and zero
%elsewhere
ind1=intersect(find(t>=-2),find(t<-1));% find the indices of array 't' whose elements lie in the interval[-2,-1)
ind2=intersect(find(t>1),find(t<=2));% find the indices of array 't' whose elements lie in the interval(1,2]
ind=union(ind1,ind2);
b(ind)=0;
ind3=intersect(find(t>=-1),find(t<=1));% find the indices of array 't' whose elements lie in the interval[-1,0]
b(ind3)=1;
subplot(2,2,2)
plot(t,b,'r')
xlabel('t');
ylabel('b(t)');
title('b(t) vs t');
axis([-3,3,-3,3])
axis equal
grid
%% Generating c(t)
ind1=intersect(find(t>=-2),find(t<-1));% find the indices of array 't' whose elements lie in the interval[-2,-1)
ind2=intersect(find(t>1),find(t<=2));% find the indices of array 't' whose elements lie in the interval(1,2]
ind=union(ind1,ind2);
c(ind)=0;
ind3=intersect(find(t>=-1),find(t<=0));% find the indices of array 't' whose elements lie in the interval[-1,0]
c(ind3)=-t(ind3);% In the interval t=[-1,0] c(t)=-t
ind4=intersect(find(t>0),find(t<=1));% find the indices of array 't' whose elements lie in the interval(0,1]
c(ind4)=t(ind4);%% In the interval t=[-1,0] c(t)=t
subplot(2,2,3)
plot(t,c,'r')
xlabel('t');
ylabel('c(t)');
title('c(t) vs t');
axis([-3,3,-3,3])
axis equal
grid
%% Generating d(t)
ind1=intersect(find(t>=-2),find(t<-1));% find the indices of array 't' whose elements lie in the interval[-2,-1)
ind2=intersect(find(t>1),find(t<=2));% find the indices of array 't' whose elements lie in the interval(1,2]
ind=union(ind1,ind2);
d(ind)=0;
ind3=intersect(find(t>=-1),find(t<=0));% find the indices of array 't' whose elements lie in the interval[-1,0]
d(ind3)=-1;% In the interval t=[-1,0] d(t)=-1
ind4=intersect(find(t>0),find(t<=1));% find the indices of array 't' whose elements lie in the interval(0,1]
d(ind4)=1;%% In the interval t=[-1,0] d(t)=1
subplot(2,2,4)
plot(t,d,'r')
xlabel('t');
ylabel('d(t)');
title('d(t) vs t');
axis([-3,3,-3,3])
axis equal
grid
part(b): type calculate_energy(a,b,c,d) in the matlab command window after executing the above code for part(a)
function [ ] = calculate_energy(a,b,c,d)
% Calculate energy of the signals a,b,c,d and display them
% energy in a signal is defined as the area under the square of the
% absolute value of the signal
% Since all the signals are defined only for an interval of t, they will
% have finite energy
a_energy=sum(abs(a.^2))*0.001;
fprintf('energy in signal a:a_energy =%f ',a_energy);
pause on
pause
b_energy=sum(abs(b.^2))*0.001;
fprintf('energy in signal b:b_energy =%f ',b_energy);
pause off
pause on
pause
c_energy=sum(abs(c.^2))*0.001;
fprintf('energy in signal c:c_energy =%f ',c_energy);
pause off
pause on
pause
d_energy=sum(abs(d.^2))*0.001;
fprintf('energy in signal d:d_energy =%f ',d_energy);
pause off
end
couldnt solve part(c)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.