bpmsimulation/generate_dipole.c

Go to the documentation of this file.
00001 
00005 #include <bpm/bpm_messages.h>
00006 #include <bpm/bpm_simulation.h>
00007 #include <bpm/bpm_rf.h>
00008 #include <bpm/bpm_alloc.h>
00009 
00014 int generate_dipole( bpmconf_t *bpm, beamconf_t *beam, bpmsignal_t *sig ) {
00015 
00016   if ( ! bpm || ! beam || ! sig ) {
00017     bpm_error( "Invalid pointer arguments in generate_dipole(...)",
00018                __FILE__, __LINE__ );
00019     return BPM_FAILURE;
00020   }
00021 
00022   // Compute the dipole response of the BPM
00023   double amp, phase;
00024   int dir = ( bpm->cav_polarisation == horiz ? 0 : 1);
00025   get_dipole_response( beam->charge, bpm->cav_chargesens, 
00026                        beam->bpmhit[dir], bpm->cav_possens,
00027                        beam->bpmslope[dir], bpm->cav_tiltsens,
00028                        beam->arrival_time, bpm->cav_freq,
00029                        &amp, &phase );
00030 
00031   // Generate the waveform
00032   double **RF = alloc_complex_wave_double( rf_nsamples );
00033   add_wave( amp, phase, bpm->cav_freq, beam->arrival_time + bpm->digi_trigtimeoffset, bpm->cav_decaytime, RF );
00034 
00035   // Mix down
00036   double *LO  = alloc_simple_wave_double( rf_nsamples );
00037   double **IF = alloc_complex_wave_double( rf_nsamples );
00038 
00039   // Arbitrarily set the LO amplitude to 10dBm = 0.01 W == sqrt(0.01 * 50) V
00040   double lo_amp = sqrt( 0.5 ); 
00041   
00042   //rf_addLO( lo_amp, bpm->rf_LOfreq, bpm->cav_phasetype, atan(1.), 0., LO );
00043   //rf_mixer( RF, LO, IF );
00044   
00045   // Filter the signal
00046   //rf_filter( IF, bpm->rf_filtertype, bpm->rf_nfiltpars, bpm->rf_filterpars );
00047 
00048   // Amplify
00049   //rf_amplify( IF, bpm->rf_gain );
00050   
00051   // Add some noise - currently assume ADC goes from -1V -> +1V
00052   double conv = (double) pow( 2, bpm->digi_nbits ) / 2.;
00053   double noise = bpm->digi_ampnoise / conv;
00054   //add_amplnoise( noise, IF );
00055   
00056   // digitise the waveform - currently assume ADC goes from -1V -> +1V
00057   int *wf = alloc_simple_wave_int( bpm->digi_nsamples );
00058   //digitise( IF, bpm->digi_nbits, bpm->digi_voltageoffset, bpm->digi_freq, conv, 
00059 //          bpm->digi_nsamples, wf);
00060   
00061   // Finally, store the waveform in the signal structure
00062   sig->wf = wf;
00063   sig->ns = bpm->digi_nsamples;
00064   
00065   // Clean up
00066   free_complex_wave_double( RF, rf_nsamples );
00067   free_complex_wave_double( IF, rf_nsamples );
00068   free_simple_wave_double( LO );
00069   
00070   return BPM_SUCCESS;
00071 }
00072 
00073 // end of file

Generated on Thu Jan 10 10:18:04 2008 for libbpm by  doxygen 1.5.1