Simple Convolution Plot Errors
Show older comments
I am trying to plot a convolution example from my text book. Somewhere in the setting up of the plot dimensions/colors etc i made an error and i cannot find it. any help would be greatly appreciated.
The current compile error is on
axis ([tau (1) tau(end) -2.0 2.5]);
thank you.
% MS2p4.m : MATLAB Session 2, Program 4
% Script M-file graphically demonstrates the convolution process.
clc
clear
figure (1) % Create figure window and make visible on screen
x = inline('1.5*sin(pi*t).*(t>=0 & t<1)');
h = inline('1.5*(t>=0&t<1.5) - (t>=2&t<2.5)');
dtau = 0.005; tau = -1:dtau:4;
ti = 0; tvec = -.25:.1:3.75;
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 interal
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]);
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');
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');
axis ([tau(1) tau(end) -1.0 2.0]); grid;
drawnow;
axis ([tau(1) tau(end) -1.0 2.0]); grid;
drawnow;
end
Accepted Answer
More Answers (0)
Categories
Find more on Pole and Zero Locations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!