Showing posts with label graph. Show all posts
Showing posts with label graph. Show all posts

Tuesday, April 20, 2010

Plotting Discontinuous Graph

From one of the problem in here :









I've got some clue from here. So, here is my solution :
t = -5:0.01:5;     % total range of the graph

q1 = t<-4;            % range 1
q2 = t>=-4 & t<3;     % range 2 
q3 = t>=3;            % range 3

y = zeros(size(t));    % initialization

y(q1) = 0;             % curve 1
y(q2) = t(q2) + 2;     % curve 2
y(q3) = t(q3) - 2;     % curve 3

plot(t,y); axis([-5 5 -4 7])

And here is the graph :
















Okay. The x(t) above is quite simple. How if it is --in example-- an polynomial equation? The concept remains the same. But, don't forget to use the dot operator, because we will power each of array member.

Monday, April 19, 2010

Plotting Continuous Signal #1 - Unit Step Function

x(t) = 4u(t) + 2sin(3t)




Matlab's inline function is convenient for creating unit step function.

Code :
t = -pi:0.01:pi;
u = inline('t >= 0');  
y = 4*u(t) + 2*sin(3*t);

plot(t,y,'r');grid on;
axis([-4 4 -3 7]);
xlabel('t'); ylabel('x(t)');
title('x(t) = 4u(t) + 2sin(3t)')

(From exercise 1C, chapter 1, book Fundamentals of Signals and Systems, 2nd ed. (Edward W. Kanen, Bonnie S. Heck))