Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating a rect FUNCTION 1

Status
Not open for further replies.

eedre85

Electrical
Joined
Nov 28, 2006
Messages
3
Location
US
Hello,

I'd like to generate a function:

x(t) = rect[(t-1)/2]

therefore,

x(t) = 1; 0<=t<=2
x(t) = 0; otherwise

I've tried sampling using a for loop, but I can't seem to create a graphable collection of points ( I always end up with one point). What's the solution?

Here's a sample of my code:

clc;


w = -10:0.05:10;
t = -4:0.01:4;
x = 0;

X = 2*sinc(w/pi).*exp(-j*w);

%plot (w, X);

%xlabel('w');
%ylabel('X(w)');



if 0<=t<=2

x = 1;

else

x = 1;

end


plot (t,x);


This code gives me a straight line at 1 within my window.
 
EDIT:

...

else

x = 0;

end

...

This change makes no difference in the output.
 
t = -4:0.01:4;
x = t>=0 & t <=2;
plot(t,x)

That should do it

M

--
Dr Michael F Platten
 
Thank you so very much Dr. Platten.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top