Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Periodic Rectangular function vector

Status
Not open for further replies.

Settler

Structural
May 22, 2010
88
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!!
 
Replies continue below

Recommended for you

What does the help file say?

TTFN
faq731-376
7ofakss
 
Still I want it as a vector, meaning I want to produce an array. I guess if...else will work...
 
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!
 
I would like to use it. If I cannot find it, I'll use the rectpuls option....
 
Use Simulink "lookup table" or "pulse generator"

[peace]
Fe (IronX32)
 
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])
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor