Question
Problem 3.9 Let have a bit of fun MATLAB. a) Download HW3_9.m script, open it in MATLAB editor and examine the script. This example graphically
Problem 3.9 Let have a bit of fun MATLAB.
a) Download HW3_9.m script, open it in MATLAB editor and examine the script. This example graphically illustrates the convolution process. Specifically, () = () (), where () = sin()(() ( 1)) [line 5 of a script) and () = 1.5(() ( 1.5)) [line 6]. The program steps through the convolution over the time interval (0.5 4) [line 11]. Other lines of code that may be of interest are line 8 (tau range), line 19 and line 27.
b) Run the script several times. Make the figure window bigger so you can see what is going on.
c) [Optional] Now would be a good time to check the problems 3.1 and 3.2.
d) Create (copy-rename) a new script called HW3_P6_rect.m to compute the convolution of () () where () = () ( 1) and () = ( + 2) (). You will need to change a few lines of code (5,6,8,11 and likely 19,27).
e) Modify your script to compute the convolution of () = ( + 2) () and () = () ( 1). You are likely to change lines 5 and 6 in your previous code.
f) Are results in part d and part e different? Why or why not? Note: further modifications of the code will allow you to check your answers for problem 3.9 and 3.10 For grading purposes, provide printout of figures in part d and part e, and answer question in part f.
___________________________________________________________________________________________________________________________________________
% HW3_9.m : TD Analysis, convolution
% Script M-file graphically demonstrates the convolution process.
figure(1) % Create figure window and make visible on screen
x = inline('1.5*sin(pi*t).*(t>=0&t<1)'); % Note that the 1.5*sin(.) function is
defined between 0 and 1
h = inline('1.5*(t>=0&t<1.5)-(t>=2&t<2.5)'); % This is effectively a definition
of 2 rect or boxcar functions
dtau = 0.005;
tau_start = -2; tau_end = 5;
tau = tau_start:dtau:tau_end; % define tau range
ti = 0; % set time index to zero
t_start = -0.5; t_end = 4;
tvec = t_start:.1:t_end;
y = NaN*zeros(1,length(tvec)); % Pre-allocate memory
for t = tvec,
ti = ti+1; % Time index
xh = x(t-tau).*h(tau); lxh = length(xh);
y(ti) = sum(xh.*dtau); % Trapezoidal approximation of convolution integral
subplot(2,1,1),plot(tau,h(tau),'k-',tau,x(t-tau),'k--',t,0,'ok');
axis([tau(1) tau(end) -2.0 2.5]); grid
patch([tau(1:end-1);tau(1:end-1);tau(2:end);tau(2:end)],...
[zeros(1,lxh-1);xh(1:end-1);xh(2:end);zeros(1,lxh-1)],...
[.8 .8 .8],'edgecolor','none');
xlabel('\tau'); legend('h(\tau)','x(t-\tau)','t',' h(\tau)x(t-\
tau)','Location','NorthEastOutside');
c = get(gca,'children'); set(gca,'children',[c(2);c(3);c(4);c(1)]);
subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok');
xlabel('t'); ylabel('y(t) = \int h(\tau)x(t-\tau) d\tau'); legend('output
y(t)','Location','NorthEastOutside');
axis([tau(1) tau(end) -1.0 2.0]); grid;
drawnow;
end
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started