bpmsimulation/generate_monopole.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 
00013 int generate_monopole( bpmconf_t *bpm, beamconf_t *beam, bpmsignal_t *sig ) {
00014 
00015 
00016   if ( ! bpm || ! beam || ! sig ) {
00017     bpm_error( "Invalid pointer arguments in generate_monopole(...)",
00018                __FILE__, __LINE__ );
00019     return BPM_FAILURE;
00020   }
00021 
00022   // Compute the monopole response of the BPM
00023   double amp, phase;
00024   get_monopole_response( beam->charge, bpm->cav_chargesens, beam->arrival_time, bpm->cav_freq,
00025                          &amp, &phase );
00026 
00027   // Generate the waveoform
00028   double **RF = alloc_complex_wave_double( rf_nsamples );
00029   add_wave( amp, phase, bpm->cav_freq, beam->arrival_time + bpm->digi_trigtimeoffset, bpm->cav_decaytime, RF );
00030 
00031   // Mix down
00032   double **LO = alloc_simple_wave_double( rf_nsamples );
00033   double **IF = alloc_complex_wave_double( rf_nsamples );
00034 
00035   // Arbitrarily set the LO amplitude to 10dBm = 0.01 W == sqrt(0.01 * 50) V
00036   double lo_amp = sqrt( 0.5 ); 
00037   
00038   //rf_addLO( lo_amp, bpm->rf_LOfreq, bpm->cav_phasetype, 0, 0, LO );
00039   //rf_mixer( RF, LO, IF );
00040   
00041   // Filter the signal
00042   //rf_filter( IF, bpm->rf_filtertype, bpm->rf_nfiltpars, bpm->rf_filterpars );
00043 
00044   // Amplify
00045   //rf_amplify( IF, bpm->rf_gain );
00046   
00047   // Add some noise - currently assume ADC goes from -1V -> +1V
00048   double conv = (double) pow( 2, bpm->digi_nbits ) / 2.;
00049   double noise = bpm->digi_ampnoise / conv;
00050   //add_amplnoise( noise, IF );
00051   
00052   // digitise the waveform - currently assume ADC goes from -1V -> +1V
00053   int *wf = alloc_simple_wave_int( bpm->digi_nsamples );
00054   //digitise( IF, bpm->digi_nbits, bpm->digi_voltageoffset, bpm->digi_freq, conv, 
00055 //          bpm->digi_nsamples, wf);
00056   
00057   // Finally, store the waveform in the signal structure
00058   sig->wf = wf;
00059   sig->ns = bpm->digi_nsamples;
00060   
00061   // Clean up
00062   free_complex_wave_double( RF, rf_nsamples );
00063   free_complex_wave_double( IF, rf_nsamples );
00064   free_simple_wave_double( LO );
00065 
00066   return BPM_SUCCESS;
00067 }
00068 
00069 // end of file

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