00001
00005 #include <bpm/bpm_messages.h>
00006 #include <bpm/bpm_simulation.h>
00007 #include <bpm/bpm_rf.h>
00008 #include <bpm/bpm_wf.h>
00009 #include <bpm/bpm_dsp.h>
00010
00011 doublewf_t* generate_diodesignal( doublewf_t *rf, double sens,
00012 filter_t *filt, triggertype_t diode ) {
00013
00014 if ( ! rf || ! filt ) {
00015 bpm_error( "Invalid pointer arguments in generate_diode(...)",
00016 __FILE__, __LINE__ );
00017 return BPM_FAILURE;
00018 }
00019
00020 doublewf_t *dc;
00021 double V_d;
00022 int i;
00023
00024 dc = doublewf( rf->fs, rf->ns );
00025
00026 if ( ! dc ) {
00027 bpm_error( "Can not allocate memory in generate_diode(...)",
00028 __FILE__, __LINE__ );
00029 return BPM_FAILURE;
00030 }
00031
00032 for (i=0;i<rf->ns;i++) {
00033
00034 V_d = mVolt * sens * ( rf->wf[i]^2 / 50 / 1e-6 ) ; convert uW into mV
00035
00036 if ( diode == positive ) {
00037 if ( rf->wf[i] > 0 ) { dc->wf[i] = V_d };
00038 }
00039
00040 if ( diode == negative ) {
00041 if ( rf->wf[i] < 0 ) { dc->wf[i] = -V_d };
00042 }
00043
00044 if ( diode == bipolar ) {
00045 dc->wf[i] = V_d;
00046 }
00047
00048 }
00049
00050 if ( filt ) apply_filter( filt, dc );
00051
00052 return dc;
00053 }
00054
00055