bpmsimulation/add_mode_response.c

Go to the documentation of this file.
00001 
00006 #include <bpm/bpm_simulation.h>
00007 
00008 int add_mode_response( complexwf_t *rf, bpmconf_t *bpm, bpmmode_t *mode, beamconf_t *beam ) {
00009 
00010   // add the excitation to the beam rf  
00011   filter_t    *resonator  = NULL;
00012   complex_t    amp;
00013   doublewf_t  *re = NULL;
00014   doublewf_t  *im = NULL;
00015   complexwf_t *response = NULL;
00016 
00017   // allocate the excitation wf
00018   re = doublewf( rf->ns, rf->fs );
00019 
00020   if ( ! re  ) {
00021     bpm_error( "Unable to allocate memory for buffer in add_mode_response()",
00022                __FILE__, __LINE__ );
00023     return BPM_FAILURE;
00024   }
00025 
00026   // the arrival time of the beam in the cavity
00027   // is stored in the beamconf_t structure
00028   add_excitation( beam->arrival_time, re );
00029 
00030   // mode resonator
00031   resonator = create_filter( "resonator", RESONATOR | BANDPASS, 0,
00032                              rf->ns, rf->fs, mode->frequency, 0., mode->Q );
00033   
00034   apply_filter( resonator, re->wf );
00035 
00036   doublewf_scale( re->fs/(2*PI*mode->frequency/mode->Q), re );
00037   im = doublewf_copy_new( re );
00038   if ( ! im  ) {
00039     bpm_error( "Unable to allocate memory for buffer in add_mode_response()",
00040                __FILE__, __LINE__ );
00041     doublewf_delete( re );
00042     return BPM_FAILURE;
00043   }
00044   
00045   doublewf_integrate( re );
00046 
00047   doublewf_scale( 2*PI*mode->frequency, re );
00048 
00049   
00050   // build the complex response
00051   response = complexwf( rf->ns, rf->fs );
00052   if ( ! response  ) {
00053     bpm_error( "Unable to allocate memory for buffer in add_mode_response()",
00054                __FILE__, __LINE__ );
00055     doublewf_delete( re );
00056     complexwf_delete( response );
00057     return BPM_FAILURE;
00058   }
00059 
00060   complexwf_setreal( response, re );
00061   complexwf_setimag( response, im );
00062 
00063 
00064   // now calculate the complex_t scale factor from the sensitivities
00065   amp = get_mode_amplitude( bpm, mode, beam );
00066 
00067   // scale the response
00068   complexwf_scale( amp, response );
00069 
00070   // add the response to the rf
00071   complexwf_add( rf, response );
00072 
00073 
00074   delete_filter( resonator );
00075   complexwf_delete( response );
00076   doublewf_delete( re );
00077   doublewf_delete( im );
00078 
00079   return BPM_SUCCESS;
00080 }

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