bpmsimulation/simple_wave.c

Go to the documentation of this file.
00001 
00005 #include <math.h>
00006 
00007 #include <bpm/bpm_messages.h>
00008 #include <bpm/bpm_nr.h>
00009 #include <bpm/bpm_units.h>
00010 #include <bpm/bpm_simulation.h>
00011 
00039 int simple_wave( double amp, double phase, double ttrig, double freq, 
00040                  double tdecay, double ped, double ampnoise, double phasenoise,
00041                  double fs, int nbits, int *wf, int ns ) {
00042   // starttime for sampling, let's have it at 0 for the moment,
00043   // maybe later on we need to put it in the routine as an argument
00044   double t0S = 0. * usec; 
00045   double w, t, max;
00046   int i;
00047 
00048   if ( ! wf ) {
00049     bpm_error( "Invalid pointer argument in simple_wave(...)",
00050                __FILE__, __LINE__ );
00051     return BPM_FAILURE;
00052   }
00053   
00054   // maximum sample
00055   max = pow( 2., (double) nbits );
00056 
00057   for ( i=0; i<ns; i++ ) {
00058     // calculate sampling time from the sample number and the 
00059     // sampling frequency, we start sampling at t=t0S
00060     t = t0S + ( (double) i + 0.5 ) / fs;
00061     
00062     w = 0.;
00063     if ( t >= ttrig ) {
00064       w = amp 
00065         * exp( - ( t - ttrig ) / tdecay ) 
00066         * sin( 2. * PI * freq * ( t - ttrig ) + nr_rangauss( phase, phasenoise ) );
00067     } 
00068 
00069     // add the voltage offset + noise
00070     w += nr_rangauss( ped, ampnoise );
00071 
00072     // will the waveform
00073     if ( w < 0. ) wf[i] = 0;
00074     else if ( w > max ) wf[i] = (int) max;
00075     else wf[i] = (int) w;
00076 
00077   } /* for ( i=0; i<ns; i++ ) */
00078   
00079   return BPM_SUCCESS;
00080 }
00081 
00082 // end of file

Generated on Fri Nov 9 21:17:11 2007 for libbpm by  doxygen 1.5.1