×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Generating a rect FUNCTION

Generating a rect FUNCTION

Generating a rect FUNCTION

(OP)
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.

RE: Generating a rect FUNCTION

(OP)
EDIT:

...

else

x = 0;

end

...

This change makes no difference in the output.

RE: Generating a rect FUNCTION

t = -4:0.01:4;
x = t>=0 & t <=2;
plot(t,x)

That should do it

M

--
Dr Michael F Platten

RE: Generating a rect FUNCTION

(OP)
Thank you so very much Dr. Platten.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources