Make function periodic on Matlab

Discussion in 'Homework Help' started by tquiva, Dec 2, 2011.

  1. tquiva

    Thread Starter Member

    Oct 19, 2010
    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:
    Code ( (Unknown Language)):
    1. %--------------
    2. dt=.01;t=-5:dt:5;f=-1/2:dt:1/2; % Time & Freq Vectors
    3. a=2;w=4; % Parameters: a=amplitude, w=width
    4. boxa = ...
    5.     (a*1) .* (abs(t)<w/2) + ...
    6.     (0) .* (2>=abs(t)>w/2);
    7. eboxa=dt*boxa*boxa';boxa=boxa/sqrt(eboxa); % Energy of box
    8. pboxa=(abs(boxa).^2)/eboxa; % Density of box
    9. mboxa=dt*sum(t.*pboxa); % Middle of box
    10. 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?
  2. Georacer


    Nov 25, 2009
    After you have produced your one-period pulse, try the funcion
    Code ( (Unknown Language)):
    2. multiboxa=horzcat(boxa,boxa,boxa);
    Insert as many boxa's you want for multiple cycles.

    Does that work for you?