Tuesday, February 22, 2011

0

matlab program for triangular wave generation|triangle wave generator using matlab

  • Tuesday, February 22, 2011
  • tech
  • Share
  • %traingular wave
    a=input('enter the  no of periods');
    b=input('enter the amplitude');
    c=input('enter the no of cycles');
    %continous traingular wave
    m=2*b/a;                 %calculation of slope
    d=0;
    e=a/2;                   % half period 
    p=0;                     %pt of each -ve slope wrt
    subplot(121);
    for n=1:c                %no of cycles =no of loops
        x=d:.01:e;           %first half period
        plot(x,m*(x-(n-1)*a),'r');  %positive slope
        hold on
        p=e+a/2;
        x=e:.01:p;             %second half period
        plot(x,-1*m*(x-(n-1)*a)+b*2,'r');%negative slope
        hold on;
        d=d+a;                  % next +ve slope plot 
        e=e+a;                  %next -ve slope plot 
    end
    xlabel('no of cycles');
    ylabel('amplitude');
    title('continous trian wave');
    legend('triang wave');
    grid major;


    %discrite triangular wave
    subplot(122);
    m=2*b/a;
    d=0;
    e=a/2;
    p=0;
    for n=1:c
        x=d:.1:e;
        stem(x,m*(x-(n-1)*a));
        hold on
        p=e+a/2;
        x=e:.1:p;
        stem(x,-1*m*(x-(n-1)*a)+b*2);
        hold on;
        d=d+a;
        e=e+a;
    end
    output

    tags:matlab program for triangular wave generation trinagle wave using matlab

    0 Responses to “matlab program for triangular wave generation|triangle wave generator using matlab”

    Post a Comment