00001
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007
00008 #include <bpm/bpm_alloc.h>
00009 #include <bpm/bpm_units.h>
00010 #include <bpm/bpm_messages.h>
00011 #include <bpm/bpm_process.h>
00012
00013 #ifndef DDC_FULL_DEBUG__
00014 #define DDC_FULL_DEBUG__
00015 #endif
00016
00017 #undef DDC_FULL_DEBUG__
00018
00019
00020
00039 int ddc_waveform( int *wf, int ns, int nbits, double fs, double t0,
00040 double freq, double tdecay, double filtBW, double epsFilt,
00041 double **out ) {
00042
00043 double **ddc;
00044 double *wfmod;
00045 int i;
00046 double ped, rms;
00047
00048 if ( ! wf ) {
00049 bpm_error( "Invalid waveform pointer in ddc_waveform(...)",
00050 __FILE__, __LINE__ );
00051 return BPM_FAILURE;
00052 }
00053
00054
00055 wfmod = alloc_simple_wave_double( ns );
00056 if ( ! wfmod ) {
00057 bpm_error( "Unable to allocate memory for wfmod in ddc_waveform(...)",
00058 __FILE__, __LINE__ );
00059 return BPM_FAILURE;
00060 }
00061
00062
00063 ddc = alloc_complex_wave_double( ns );
00064 if ( ! ddc ) {
00065 bpm_error( "Unable to allocate memory for ddc in ddc_waveform(...)",
00066 __FILE__, __LINE__ );
00067 return BPM_FAILURE;
00068 }
00069
00070
00071 if ( get_pedestal( wf, ns, 20, &ped, &rms ) == BPM_FAILURE ) {
00072 bpm_error( "Unable to retreive the pedestal in downmix_waveform(...)",
00073 __FILE__, __LINE__ );
00074 return BPM_FAILURE;
00075 }
00076
00077
00078
00079 for (i=0;i<ns;i++) wfmod[i] = wf[i] - ped;
00080
00081
00082 if ( downmix_waveform( wfmod, ns, fs, freq, t0, ddc ) == BPM_FAILURE ) {
00083 bpm_error( "Error in downmixing in ddc_sample_waveform(...)",
00084 __FILE__, __LINE__ );
00085 return BPM_FAILURE;
00086 }
00087
00088 if ( ddc_gaussfilter( ddc, ns, fs, filtBW, epsFilt, out ) == BPM_FAILURE ) {
00089 bpm_error( "Unable to filter the waveform in ddc_waveform(...)",
00090 __FILE__, __LINE__ );
00091 return BPM_FAILURE;
00092 }
00093
00094
00095 free_simple_wave_double( wfmod );
00096 free_complex_wave_double( ddc, ns );
00097
00098 return BPM_SUCCESS;
00099 }