## Periodic Rectangular function vector

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

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

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

## RE: Periodic Rectangular function vector

## RE: Periodic Rectangular function vector

size(yp)

after you've run the above

Cheers

Greg Locock

New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

## RE: Periodic Rectangular function vector

I want generate the rectangular function just with an

if else loop...

Thanks again!

## RE: Periodic Rectangular function vector

TTFN

FAQ731-376: Eng-Tips.com Forum Policies

## RE: Periodic Rectangular function vector

## RE: Periodic Rectangular function vector

Fe (IronX32)

## RE: Periodic Rectangular function vector

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])