Computational routine
eng


genpulse

File content


/* Variable duty cycle pulse generator
 * Type 2 simulation function ver 1.0 - scilab-2.6&2.7
 * february 12th 2004 IRCOM Group R. Quere
 */

 /* REVISION HISTORY :
 * $Log$
 */

#include <math.h>

#include "machine.h"

/* This function returns a variable duty cycle pulse waveform
 *  The parameters of the pulse are in the rpar vector in the following order
 *  rpar[0]=Trise   Rise time of the pulse (default=0)
 *  rpar[1]=Tfall   Fall time of the pulse (default=0)
 *  rpar[2]=Thigh   Time duration in the high state (default=1)
 *  rpar[3]=Td      Time delay of the pulse (default=0)
 *  rpar[4]=Tp      Period of the pulse, if Tp=0 there is only one pulse (default=0)
 *  rpar[5]=Ahigh   Value of the pulse in the high state (default=0)
 *  rpar[6]=Alow    Value of the pulse in the low state (default=0)
 */


void genpulse(flag,nevprt,t,xd,x,nx,z,nz,tvec,ntvec,rpar,nrpar,
        ipar,nipar,inptr,insz,nin,outptr,outsz,nout)
integer *flag,*nevprt,*nx,*nz,*ntvec,*nrpar,ipar[],*nipar,insz[],*nin,outsz[],*nout;
double x[],xd[],z[],tvec[],rpar[];
double *inptr[],*outptr[],*t;
{
  /*déclaration des variables*/
  double *y;
  double t1, t2, t3, t4, tc, tp, Ahigh, Alow;

  y=(double *)outptr[0];

  t1=rpar[3];
  t2=t1+rpar[0];
  t3=t2+rpar[2];
  t4=t3+rpar[3];
  tp=rpar[4];
  Ahigh=rpar[5];
  Alow=rpar[6];

  if(*flag==4)
     *y=z[0];
  else if (*flag==1 || *flag==6)
     *y=z[0];
  else if (*flag==2)
   { if (tp == 0)
     {if (*t < t1)
         z[0]=Alow;
      else if (*t<t2)
         z[0]=(*t-t1)*(Ahigh-Alow)/(t2-t1)+Alow;
      else if (*t<t3)
         z[0]=Ahigh;
      else if (*t<t4)
         z[0]=(*t-t3)*(Alow-Ahigh)/(t4-t3)+Ahigh;
      else
        z[0]=0;
     }
     else
     { tc=*t-floor(*t/tp)*tp;
       if (tc < t1)
         z[0]=Alow;
       else if (tc<t2)
         z[0]=(tc-t1)*(Ahigh-Alow)/(t2-t1)+Alow;
       else if (tc<t3)
         z[0]=Ahigh;
       else if (tc<t4)
         z[0]=(tc-t3)*(Alow-Ahigh)/(t4-t3)+Ahigh;
       else
        z[0]=Alow;
     }
   }
}