×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*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.

# Periodic Rectangular function vector

 Forum Search FAQs Links MVPs

## Periodic Rectangular function vector

(OP)
I was asked to generate vector x(t), where x(t) is a rectangular pulse with width of 0.5 and period 1.
I wrote the following expression. The only thing is that I'm worried if it's a vector or not (as my English is bad).

fs = 1000;                              % sample freq
D = [0:1:4]';                           % pulse delay times
t = 0 : 1/fs : 4000/fs;                 % signal evaluation time
w = 0.5;                               % width of each pulse
yp = pulstran(t,D,'rectpuls',w);

Thank you very much in advance!!

### RE: Periodic Rectangular function vector

What does the help file say?

### RE: Periodic Rectangular function vector

(OP)
Still I want it as a vector, meaning I want to produce an array. I guess if...else will work...

### RE: Periodic Rectangular function vector

(OP)
well the thing is that I don't want to use those functions.

I want generate the rectangular function just with an

if else loop...

Thanks again!

### RE: Periodic Rectangular function vector

Is this for school?

### RE: Periodic Rectangular function vector

(OP)
I would like to use it. If I cannot find it, I'll use the rectpuls option....

### RE: Periodic Rectangular function vector

Use Simulink "lookup table" or "pulse generator"

Fe (IronX32)

### RE: Periodic Rectangular function vector

(OP)
I finally used this way:

fs=1000;            %Sample frequency
t=0:1/fs:4;         %Time evaluation

y = cos(2*pi*t);

% we find positive elements and represent them as 1
y(find(y >= 0)) = 1;

% we find negative elements and represent them as 0
y(find(y < 0)) = 0;

plot(t,y),axis([0 4 -0.2 1.2])

#### 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.

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

Click Here to join Eng-Tips and talk with other members! Already a Member? Login

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!