Make function periodic on Matlab

Thread Starter

tquiva

Joined Oct 19, 2010
176
Problem:
Consider a periodic, with period unity, signal with a cycle that is square cornered pulse of width w with an amplitude of a and a middle of m. Use numeric Matlab to plot several cycles of the periodic signal for various values of the cycle parameters.

Here's my code:
Rich (BB code):
%--------------
dt=.01;t=-5:dt:5;f=-1/2:dt:1/2; % Time & Freq Vectors
a=2;w=4; % Parameters: a=amplitude, w=width
boxa = ...
    (a*1) .* (abs(t)<w/2) + ...
    (0) .* (2>=abs(t)>w/2);
eboxa=dt*boxa*boxa';boxa=boxa/sqrt(eboxa); % Energy of box
pboxa=(abs(boxa).^2)/eboxa; % Density of box
mboxa=dt*sum(t.*pboxa); % Middle of box
plot(t,box)
My problem here is, how would I make this single box into a periodic one with several cycles? I already tried adding several boxa's, but it did not work. I also tried using the Matlab function, square(x), but I'm not sure if that function would help me choose an amplitude and width of the box.

Can someone please help me?
 

Georacer

Joined Nov 25, 2009
5,181
After you have produced your one-period pulse, try the funcion
Rich (BB code):
multiboxa=horzcat(boxa,boxa,boxa);
Insert as many boxa's you want for multiple cycles.

Does that work for you?
 
Top