bpmsimulation/simple_tone.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 
00037 int simple_tone( double amp, double phase, double freq,
00038                  double ped, double ampnoise, double phasenoise,
00039                  double fs, int nbits, int *wf, int ns ) {
00040 
00041   // starttime for sampling, let's have it at 0 for the moment,
00042   // maybe later on we need to put it in the routine as an argument
00043   double t0S = 0. * usec; 
00044   double w, t, max;
00045   int i;
00046 
00047   if ( ! wf ) {
00048     bpm_error( "Invalid pointer argument in simple_wave(...)",
00049                __FILE__, __LINE__ );
00050     return BPM_FAILURE;
00051   }
00052   
00053   // maximum sample
00054   max = pow( 2., (double) nbits );
00055 
00056   for ( i=0; i<ns; i++ ) {
00057     // calculate sampling time from the sample number and the 
00058     // sampling frequency, we start sampling at t=t0S
00059     t = t0S + ( (double) i + 0.5 ) / fs;
00060     
00061     w = amp * sin( 2. * PI * freq * t + nr_rangauss( phase, phasenoise ) );
00062     
00063     // add the voltage offset + noise
00064     w += nr_rangauss( ped, ampnoise );
00065 
00066     // will the waveform
00067     if ( w < 0. ) wf[i] = 0;
00068     else if ( w > max ) wf[i] = (int) max;
00069     else wf[i] = (int) w;
00070 
00071   } /* for ( i=0; i<ns; i++ ) */
00072   
00073   return BPM_SUCCESS;
00074 }
00075 
00076 // end of file

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