How to Create A Triangle waveform in MATLAB

Discussion in 'Programmer's Corner' started by Willson Toh, Oct 1, 2011.

  1. Willson Toh

    Thread Starter New Member

    Oct 1, 2011
    1
    0
    Does anyone have an idea to create a Triangle waveform?

    The reason i require this is because i require to compare a Sinewave and a Triangle to create a SPWM.

    In another i need the MATLAB assistant to calculate the duty cycle in order to create a lookup table.

    Your help is very important for my understanding

    Regard
    Willson
     
  2. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Is the derivative of a sine function close enough to a triangle wave for your purpose?
     
  3. panic mode

    Senior Member

    Oct 10, 2011
    1,318
    304
    derivative of sine is another sine function (cos).
    try this

    clear;

    ymax=3.5;
    xmin=-10;
    xmax= 10;
    x0=0;
    T=4;
    step=0.03;
    n=(xmax-xmin)/step;
    y=1:n;
    x=1:n;

    for i=1:n
    x(i)=xmin+i*step;
    y(i)=ymax*abs(((mod(x(i),T))*2/T-1));
    end

    plot(x,y);
     
    Last edited: Oct 17, 2011
Loading...