BPM Processing Routines


Detailed Description

This set of routines contains the BPM digitised waveform processing routines to go from a sis digitised waveform to position and slope information.

General structure of the BPM signal processing

The BPM signal processing algorithms are centered around a few top-level routines which need to called by a standard user. All make use of a number of BPM data structures which hold BPM configuration data ( bpmconf_t ), processed BPM information ( bpmproc_t ) or BPM calibration information ( bpmcalib_t ). As the BPM processing algorithms make extensive use of the bpmdsp module, the BPM signals need to be encapsulated in a doublewf_t waveform before feeding them to these processing routines. The top-level processing routines have a mode bitword which provides some processing options that the user can feed into the processing algorithm.

Diode signal processing

Since the idea was to unify the processing into one coherent set of data structures, the diode or trigger information had to be fitted into the same framework as the BPM data. This is the function call :

    int process_diode( doublewf_t *signal, bpmconf_t *conf, bpmproc_t *proc );

So the diode pulse has to be fitted into a doublewf_t along with a bpmconf_t structure conf. The routine first checks the flag bpmconf_t::cav_type for the cavity type. This should be of type diode for the routine to proceed. It then calls the fit_diodepulse routine onto the signal, which returns the fitted t0 into the bpmproc_t structure as proc->t0.

Attention:
Note that there is the possibility to abuse a dipole or monopole signal as a trigger pulse. In this case the process_diode routine will determine the RMS of the noise in front of the digitised dipole/monopole signal (first 20 samples ) and return the timestamp in bpmproc_t::t0 of the first sample which is 10 times largers than this RMS value. For this behaviour, the bpmconf_t::cav_type setting is irrelevant but the bpmconf_t::forced_trigger value has to be set to 1. Note that this behaviour is normally not needed an for experimental purposes only.

Monopole signal processing

For monopole cavities one only needs to determine the amplitude and phase, so no post-processing to get to position and slope using a reference cavity and calibration information is needed. Therefore the process_monopole routine is basically a wrapper around the process_waveform routine which does exactly this determination of the amplitude and phase. The function call is :

    int process_monopole( doublewf_t *signal, bpmconf_t *bpm, bpmproc_t *proc, 
                          bpmproc_t *trig, unsigned int mode );

This routine basically is a wrapper around

    int process_waveform( doublewf_t *signal, bpmconf_t *bpm, bpmproc_t *proc, 
                          bpmproc_t *trig, unsigned int mode );

and handles all the processing steps flagged by the mode bitword. Chronologically it executes the following steps :

Dipole signal processing

Dipole cavity waveforms first need to undergo the same processing step as monopole waveforms, to determine their phase and amplitude. After that position and slope information need to be determined using the calibration information. The routine

    int process_dipole( doublewf_t *signal, bpmconf_t *bpm, bpmcalib_t *cal, bpmproc_t *proc, 
                        bpmproc_t *trig, bpmproc_t *ampref, bpmproc_t *phaseref, 
                        unsigned int mode );

is therefore a wrapper around the following two core routines :

    int process_waveform( signal, bpm, proc, trig, mode );
    int postprocess_waveform( bpm, proc, cal, ampref, phaseref, mode );

Attention:
If the PROC_CORR_GAIN (or PROC_CORR_AMP, PROC_CORR_PHASE) flag is set in the mode word, the process_dipole routine will correct the gains based upon the latest calibration tone information stored in the bpmproc_t::ddc_ct_amp etc variables and comparing them to the bpmcalib_t::ddc_ct_amp at the time of calibration. This is done by a call to correct_gain
The process_waveform is explained under the process_monopole cavity, the postprocess_waveform routine executes the following :

Processing flow

The question now is how to organise the processing flow from the digitised waveform data. Before being able to obtain positions and slopes, the user will need to have processed all the trigger ( diode ) pulses. And thereafter the monopole waveforms in the event. After that positions and slopes can be calculted using the process_diopole routine. Note that the monopole waveforms depend on the trigger information in the case of internal triggering using a trigger pulse, so a good way to proceed is first to all the trigger pulses, than all the monopole pulses and then all the dipole waveforms.

Alternatively the user can first use the routine process_waveform on all of the waveforms ( together with processing the trigger information ). After this is done, the user can use the postprocess_waveform routine to perform the post-processing on the dipole waveforms.

About trigger pulses, internal vs. external clock

The SIS ADCs can be triggered by using an external clock in which case all the modules in the system are synchronised and no trigger pulses are needed. Because of the way the processing is setup in process_waveform, the user has to be mindfull of a number of things depending on whether the ADC modules are triggered internally ( and a trigger pulse is available ) or whether they are triggered externally, synchronised to the beam clock, in which case the starting time ( t0 ) of the pulses should be constant for each individual BPM signal.

External clock triggering

In this case, the t0 should be set in the BPM configuration under bpmconf_t::t0. During the processing this value will be used and copied to bpmproc_t::t0. The bpmconf_t::tOffset defines the offset from this t0 of the pulse of the sampling point in the waveform such that
    proc->ddc_tSample = proc->t0 + bpm->ddc_tOffset;
This mode will be assumed automatically in the absence of the 4th argument of process_waveform ( bpmproc_t *trig = NULL ).

Internal clock triggering

There the bpmconf_t::t0 value is ignored and no t0 value needs to be specified before hand since it will be fitted from the diode/trigger pulse. In this case the 4th argument of process_waveform needs to be present. Also,the bpmconf_t::tOffset keeps it's definition exaclty the same as in the external clock case. It is the time difference between the sample time and the starttime of the waveform t0, which in this case got fit instead of being fixed.

calibration tone information

The calibration tone information is kept in two locations. Firstly at the time of calibration, the user should make sure that the latest calibration tone information is set in the bpmcalib_t structure under bpmcalib_t::ddc_ct_amp and bpmcalib_t::ddc_ct_phase and analoguous for the parameters for the fitted processing. Than each time a calibration tone pulse is encountered, the user should pass the phase and amplitude of the calibration tone on to the bpmproc_t::ddc_ct_amp and bpmproc_t::ddc_ct_phase and therefore always keep the lateste calibration tone information in this location. Each call to

    int correct_gain( bpmproc_t *proc, bpmcalib_t *cal, unsigned int mode )

then corrects the phase and amplitude of the current pulse by scaling the amplitude with the ratio between the caltone amplitude at the time of calibration and the lastest one and shifting the phase by the phase difference between the phase of the calibration tone at the time of BPM calibration and the latest phase recorded in the bpmproc_t::ddc_ct_phase variable ( or bpmproc_t::fit_ct_phase ).

Attention:
I've include a mode bitword, which takes the flags PROC_CORR_GAIN to correct both amplitude and phase, and PROC_CORR_AMP, PROC_CORR_PHASE to correct only one parameter individually. This is done since e.g. for internal clocking, when the ADC's are not synchronised to each other, it is not really clear where to sample the waveform unless a trigger is supplied in the ADC. For external synchronized clocking, we can just give a fixed sample number, stored in the bpm configuration under bpmconf_t::ddc_ct_iSample.


Files

file  bpm_process.h
 libbpm main processing routines
file  check_saturation.c
file  correct_gain.c
file  ddc_sample_waveform.c
file  ddc_waveform.c
file  downmix_waveform.c
file  fft_waveform.c
file  fit_diodepulse.c
file  fit_fft.c
file  fit_waveform.c
file  get_IQ.c
file  get_pedestal.c
file  get_pos.c
file  get_slope.c
file  get_t0.c
file  postprocess_waveform.c
file  process_caltone.c
file  process_diode.c
file  process_dipole.c
file  process_monopole.c
file  process_waveform.c

Defines

#define PROC_DEFAULT
#define PROC_DO_FFT
#define PROC_DO_FIT
#define PROC_DO_DDC
#define PROC_DDC_CALIBFREQ
#define PROC_DDC_CALIBTDECAY
#define PROC_DDC_FITFREQ
#define PROC_DDC_FITTDECAY
#define PROC_DDC_FFTFREQ
#define PROC_DDC_FFTTDECAY
#define PROC_DDC_FULL
#define PROC_FIT_DDC
#define PROC_FIT_FFT
#define PROC_RAW_PHASE
#define PROC_CORR_AMP
#define PROC_CORR_PHASE
#define PROC_CORR_GAIN

Functions

EXTERN int process_diode (doublewf_t *signal, bpmconf_t *conf, bpmproc_t *proc)
EXTERN int process_monopole (doublewf_t *signal, bpmconf_t *bpm, bpmcalib_t *cal, bpmproc_t *proc, bpmproc_t *trig, unsigned int mode)
EXTERN int process_dipole (doublewf_t *signal, bpmconf_t *bpm, bpmcalib_t *cal, bpmproc_t *proc, bpmproc_t *trig, bpmproc_t *ampref, bpmproc_t *phaseref, unsigned int mode)
EXTERN int process_waveform (doublewf_t *signal, bpmconf_t *bpm, bpmproc_t *proc, bpmproc_t *trig, unsigned int mode)
EXTERN int postprocess_waveform (bpmconf_t *bpm, bpmproc_t *proc, bpmcalib_t *cal, bpmproc_t *ampref, bpmproc_t *phaseref, unsigned int mode)
EXTERN int process_caltone (doublewf_t *signal, bpmconf_t *bpm, bpmproc_t *proc, unsigned int mode)
EXTERN int correct_gain (bpmproc_t *proc, bpmcalib_t *cal, unsigned int mode)
EXTERN int fit_waveform (doublewf_t *w, double t0, double i_freq, double i_tdecay, double i_amp, double i_phase, double *freq, double *tdecay, double *amp, double *phase)
EXTERN int fit_diodepulse (doublewf_t *w, double *t0)
EXTERN int fft_waveform (doublewf_t *w, complexwf_t *ft)
EXTERN int fit_fft_prepare (complexwf_t *ft, int *n1, int *n2, double *amp, double *freq, double *fwhm)
EXTERN int fit_fft (complexwf_t *ft, double *freq, double *tdecay, double *A, double *C)
EXTERN int check_saturation (doublewf_t *w, int nbits, int *iunsat)
EXTERN int downmix_waveform (doublewf_t *w, double frequency, complexwf_t *out)
EXTERN int ddc_waveform (doublewf_t *w, double frequency, filter_t *filt, complexwf_t *dc, doublewf_t *buf_re, doublewf_t *buf_im)
EXTERN int ddc_sample_waveform (doublewf_t *w, double frequency, filter_t *filt, int iSample, double t0, double tdecay, double *amp, double *phase, doublewf_t *buf_re, doublewf_t *buf_im)
EXTERN int get_pedestal (doublewf_t *wf, int range, double *offset, double *rms)
EXTERN int get_t0 (doublewf_t *w, double *t0)
EXTERN int get_IQ (double amp, double phase, double refamp, double refphase, double *Q, double *I)
EXTERN int get_pos (double Q, double I, double IQphase, double posscale, double *pos)
EXTERN int get_slope (double Q, double I, double IQphase, double slopescale, double *slope)


Define Documentation

#define PROC_DEFAULT

Definition at line 331 of file bpm_process.h.


Function Documentation

EXTERN int process_diode ( doublewf_t signal,
bpmconf_t conf,
bpmproc_t proc 
)

This routine processes a diode pulse, which should be found in the signal structure. It fills the proc structure with the t0. The routine checks what the signal type (conf->cav_type) is and when it really is a diode pulse, it will fit the pulse and return t0, otherwise (when the signal is a monopole or dipole signal), it will determine the onset of the waveform by looking where the signal's absolute value exceeds 10 * the noise RMS at the beginning of the waveform.

Parameters:
signal The bpm signal
conf The bpm configuration structure
proc The processed trigger structure (containing the t0)
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 9 of file process_diode.c.

References bpm_error(), bpmconf::cav_type, diode, doublewf_basic_stats(), fit_diodepulse(), bpmconf::forced_trigger, doublewf_t::fs, wfstat_t::mean, bpmconf::name, doublewf_t::ns, wfstat_t::rms, bpmproc::t0, and doublewf_t::wf.

EXTERN int process_monopole ( doublewf_t signal,
bpmconf_t bpm,
bpmcalib_t cal,
bpmproc_t proc,
bpmproc_t trig,
unsigned int  mode 
)

Top-level routine which is basically a wrapper around process_waveform and correct_gain to take into account the calibration tone data. See more in details documentation in those routines.

Parameters:
signal The doublewf_t encoded BPM signal
bpm The bpm configuration structure
cal The bpm calibration structure, needed for the gain correction
proc The processed data structure
trig The structure with processed trigger info for that waveform
mode A bitpattern encoding what exactly to process
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 11 of file process_monopole.c.

References bpm_error(), correct_gain(), bpmconf::name, and process_waveform().

EXTERN int process_dipole ( doublewf_t signal,
bpmconf_t bpm,
bpmcalib_t cal,
bpmproc_t proc,
bpmproc_t trig,
bpmproc_t ampref,
bpmproc_t phaseref,
unsigned int  mode 
)

Top-level routine which is a wrapper around process_waveform, correct_gain and postprocess_waveform. See more details in the documentation of those individual routines.

Parameters:
signal The doublewf_t encoded BPM signal
bpm The bpm configuration structure
cal The bpm calibration structure, needed for the gain correction
proc The processed data structure
trig The structure with processed trigger info for that waveform
ampref The already processed amplitude reference bpmproc_t structure
phaseref The already processed phase reference bpmproc_t structure
mode A bitpattern encoding what exactly to process
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 10 of file process_dipole.c.

References bpm_error(), correct_gain(), bpmconf::name, postprocess_waveform(), and process_waveform().

EXTERN int process_waveform ( doublewf_t signal,
bpmconf_t bpm,
bpmproc_t proc,
bpmproc_t trig,
unsigned int  mode 
)

Top-level routine to processes a BPM beam pulse waveform (decaying "sin"-like wave) and derive amplitude and phase from the signal. The routine needs to be fed with a doublewf_t containing the digitized signal. The signal is checked for saturation, it's pedestal is determined and removed, the pulse starttime (t0) is set from the configuration or the trigger. Then, depending on the mode bitpattern, an FFT is performed, the waveform is fitted and a digital downconversion is done. The results (amplitude and phase) are stored in the bpmproc_t structure of the BPM.

Relevant mode bit patterns for this routine are :

  • PROC_DO_FFT : The Fourier Transform of the waveform gets computed and stored as a complexwf_t in the bpmproc_t::ft variable.
  • PROC_FIT_FFT : An attempt to fit the Fourier Transform is made using a Lorentizan Lineshape. If successfull, the bpmproc_t::fft_freq and bpmproc_t::fft_tdecay variables will contain the fitted frequency and decaytime. I recommend however to use a 3th party fitting routine for this (e.g. MINUIT) and implement this in a user program.
  • PROC_DO_FIT : Attempts to fit a decaying sine wave to the waveform having the frequency, the decay time, the amplitude and phase as free parameters. If successfull, the bpmproc_t::fit_freq, bpmproc_t::fit_amp, bpmproc_t::fit_phase and bpmproc_t::fit_tdecay will contain the fit parameters. Again, I recommend to use a 3th party fitting routine for this.
  • PROC_DO_DDC : Will perform a digital downconversion on the waveform. The results are contained in bpmproc_t::ddc_amp and bpmproc_t::ddc_phase, determined at bpmproc_t::ddc_tSample, but extrapolated back to bpmproc_t::t0.
  • PROC_DDC_FITTDECAY, PROC_DDC_FFTTDECAY : Normally the ddc algoritm gets it's decay time for extrapolation back to t0 from the bpmconf_t::ddc_tdecay variable, if one of these flags are set it will get them from the fitted waveform or FFT if they were succesful.
  • PROC_DDC_FITFREQ, PROC_DDC_FFTFREQ : Analogous as the previous item, but now for the ddc frequency which is normally obtained from bpmconf_t::ddc_freq.
  • PROC_DDC_FULL : Will perform the DDC algorithm on the entire waveform and store the result in bpmproc_t::dc

Parameters:
signal The digitized signal converted into a doublewf_t
bpm A pointer to the bpmconf_t structure for the BPM channel
proc A pointer to the bpmproc_t structure for the BPM channel
trig A pointer to the bpmproc_t structure of the trigger for this BPM channel, if this parameter is NULL, externall clocking will be assumed and the t0 from the bpmconf_t structure will be used in the processing.
mode The processing mode bitword
Returns:
BPM_SUCCESS upon succes, BPM_FAILURE upon failure

Definition at line 12 of file process_waveform.c.

References bpmproc::ampnoise, bpm_error(), bpm_warning(), bpmconf::cav_decaytime, check_saturation(), bpmproc::dc, bpmproc::ddc_amp, bpmconf::ddc_buffer_im, bpmconf::ddc_buffer_re, bpmconf::ddc_filter, bpmconf::ddc_freq, bpmproc::ddc_iSample, bpmproc::ddc_phase, ddc_sample_waveform(), bpmproc::ddc_success, bpmconf::ddc_tdecay, bpmconf::ddc_tOffset, bpmproc::ddc_tSample, ddc_waveform(), bpmconf::digi_freq, bpmconf::digi_nbits, bpmconf::digi_nsamples, doublewf_bias(), bpmproc::fft_freq, bpmproc::fft_success, bpmproc::fft_tdecay, fft_waveform(), bpmproc::fit_amp, fit_fft(), bpmproc::fit_freq, bpmproc::fit_phase, bpmproc::fit_success, bpmproc::fit_tdecay, bpmconf::fit_tOffset, fit_waveform(), bpmproc::ft, get_pedestal(), bpmproc::iunsat, bpmconf::name, norm_phase(), bpmproc::saturated, bpmconf::t0, bpmproc::t0, bpmproc::voltageoffset, and complexwf_t::wf.

Referenced by process_dipole(), and process_monopole().

EXTERN int postprocess_waveform ( bpmconf_t bpm,
bpmproc_t proc,
bpmcalib_t cal,
bpmproc_t ampref,
bpmproc_t phaseref,
unsigned int  mode 
)

Top-level routine to Post-process a waveform for whith the amplitude and the phase have already been defined using process_waveform. This routine goes on to calculate I and Q from the phase and amplitudes as well as the postion and slope using the calibration information.

Relevant mode bit patterns for this routine are :

  • PROC_RAW_PHASE : when this bit is active in the mode word, the routine will not replace the phase in the bpmproc_t structure by the phase difference between the reference cavity and the processed cavity. Under normal circumstances you don't want this since it's only the phase difference which actually has any physical meaning.

Parameters:
signal The digitized signal converted into a doublewf_t
bpm A pointer to the bpmconf_t structure for the BPM channel
proc A pointer to the bpmproc_t structure for the BPM channel
cal A pointer to the bpmcalib_t structure for the BPM channel
ampref A pointer to the bpmproc_t structure of the amplitude reference channel for this BPM.
phaseref A pointer to the bpmproc_t structure of the phase reference channel for this BPM.
mode The processing mode bitword
Returns:
BPM_SUCCESS upon succes, BPM_FAILURE upon failure

Definition at line 10 of file postprocess_waveform.c.

References bpm_error(), bpmproc::ddc_amp, bpmproc::ddc_I, bpmcalib::ddc_IQphase, bpmproc::ddc_phase, bpmproc::ddc_pos, bpmcalib::ddc_posscale, bpmproc::ddc_Q, bpmproc::ddc_slope, bpmcalib::ddc_slopescale, bpmproc::ddc_success, bpmproc::fit_amp, bpmproc::fit_I, bpmcalib::fit_IQphase, bpmproc::fit_phase, bpmproc::fit_pos, bpmcalib::fit_posscale, bpmproc::fit_Q, bpmproc::fit_slope, bpmcalib::fit_slopescale, bpmproc::fit_success, get_IQ(), get_pos(), get_slope(), bpmconf::name, and norm_phase().

Referenced by process_dipole().

EXTERN int process_caltone ( doublewf_t signal,
bpmconf_t bpm,
bpmproc_t proc,
unsigned int  mode 
)

Top level routine to process the calibration tone via DDC, similar to process_waveform but it also updates the ddc_ct_amp and ddc_ct_phase variables in the bpmproc_t structure. No fitting is implemented in this routine.

Relevant mode bit patterns for this routine are analogous as in process_waveform

  • PROC_DO_FFT : see process_waveform
  • PROC_FIT_FFT : see process_waveform
  • PROC_DO_DDC : see process_waveform

Parameters:
signal The digitized signal converted into a doublewf_t
bpm A pointer to the bpmconf_t structure for the BPM channel
proc A pointer to the bpmproc_t structure for the BPM channel
mode The processing mode bitword
Returns:
BPM_SUCCESS upon succes, BPM_FAILURE upon failure

Definition at line 11 of file process_caltone.c.

References bpmproc::ampnoise, bpm_error(), bpm_warning(), check_saturation(), bpmproc::dc, bpmproc::ddc_amp, bpmconf::ddc_buffer_im, bpmconf::ddc_buffer_re, bpmproc::ddc_ct_amp, bpmconf::ddc_ct_filter, bpmconf::ddc_ct_freq, bpmconf::ddc_ct_iSample, bpmproc::ddc_ct_phase, bpmproc::ddc_phase, bpmproc::ddc_success, ddc_waveform(), bpmconf::digi_nbits, doublewf_bias(), bpmproc::fft_freq, bpmproc::fft_success, bpmproc::fft_tdecay, fft_waveform(), fit_fft(), bpmproc::ft, get_pedestal(), bpmproc::iunsat, bpmconf::name, norm_phase(), bpmproc::saturated, bpmproc::voltageoffset, and complexwf_t::wf.

EXTERN int correct_gain ( bpmproc_t proc,
bpmcalib_t cal,
unsigned int  mode 
)

Correct the processed amplitude and phase by using calibration tone information if the ddc and or fits were successfull. Since e.g. for internal clock it is not really sure the phase information can be used if there is no proper trigger, some mode bits can be flagged to only correct the amplitude.

Relevant mode bit patterns for this routine are :

  • PROC_CORR_AMP : Correct the amplitude
  • PROC_CORR_PHASE : Correct the phase
  • PROC_CORR_GAIN : Correct both of them

Parameters:
proc The bpmproc_t structure of the bpm
cal The bpmcalib_t structure of the bpm
mode Mode of correction
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 10 of file correct_gain.c.

References bpm_error(), bpmproc::ddc_amp, bpmcalib::ddc_ct_amp, bpmproc::ddc_ct_amp, bpmcalib::ddc_ct_phase, bpmproc::ddc_ct_phase, bpmproc::ddc_phase, bpmproc::ddc_success, bpmproc::fit_amp, bpmcalib::fit_ct_amp, bpmproc::fit_ct_amp, bpmcalib::fit_ct_phase, bpmproc::fit_ct_phase, bpmproc::fit_phase, and bpmproc::fit_success.

Referenced by process_dipole(), and process_monopole().

EXTERN int fit_waveform ( doublewf_t w,
double  t0,
double  i_freq,
double  i_tdecay,
double  i_amp,
double  i_phase,
double *  freq,
double *  tdecay,
double *  amp,
double *  phase 
)

Fits the waveform with a decaying sin wave using the lmder/lmdif routines from nr_levmar.c !

Attention:
Note that this routine is highly experimental, so don't use it for real production stuff. Instead I recommend using a proper minimisation package like MINUIT or so...
Parameters:
*w The waveform encoded as a doublewf_t
t0 t0 for the waveform
i_freq Initial frequency for the fit
i_tdecay Initial decay time for the fit
i_amp Initial amplitude for the fit
i_phase Initial phase for the fit
freq Fitted frequency
tdecay Fitted decay time
amp Fitted amplitude
phase Fitted phase
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 80 of file fit_waveform.c.

References bpm_error(), doublewf(), doublewf_delete(), doublewf_t::fs, doublewf_t::ns, and doublewf_t::wf.

Referenced by process_waveform().

EXTERN int fit_diodepulse ( doublewf_t w,
double *  t0 
)

Fits the diode pulse, basically a wrapper for get_t0, to conserve names and consistency in the library... is nothing more than a wrapper around get_t0, so see there...

Definition at line 10 of file fit_diodepulse.c.

References get_t0().

Referenced by process_diode().

EXTERN int fft_waveform ( doublewf_t w,
complexwf_t ft 
)

Performs a fast fourier transform of the waveform, after subtracting the pedestal, basically just a wrapper around the forward realfft routine from the DSP module. Please see it's documentation for more details...

Parameters:
*w the waveform
fft the complex returned fft spectrum
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 12 of file fft_waveform.c.

References bpm_error(), FFT_FORWARD, and realfft().

Referenced by process_caltone(), and process_waveform().

EXTERN int fit_fft_prepare ( complexwf_t ft,
int *  n1,
int *  n2,
double *  amp,
double *  freq,
double *  fwhm 
)

This routine prepares the fft fit of the waveform. It starts by getting the position of the maximum in the spectrum (first nyquist band only). Then from this position runs left and right to determine where the amplitude drops to half of the peak amplitude and have an initial estimation of the FWHM. It will then set twice the FWHM width as the fit range in which to perform the fit, this is than returned by the samplnumbers n1 and n2.

Parameters:
ft The complexwf_t fourier transform
n1 The first sample to start the fit from
n2 The last sample to take into account in the following fit
amp Initial estimation of the amplitude for the fit
freq Initial estimation of the frequency for the fit
fwhm Initial estimation of the FWHM for the fit.
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure.

Definition at line 72 of file fit_fft.c.

References bpm_error(), complexwf_t::fs, complexwf_t::ns, and complexwf_t::wf.

Referenced by fit_fft().

EXTERN int fit_fft ( complexwf_t ft,
double *  freq,
double *  tdecay,
double *  A,
double *  C 
)

Fits the power spectrum of the FT of a waveform frequency and decay time. Internally it makes a call to fit_fft_prepare to get an initial estimation of the parameters and goes on by applying the nr_lmder routine to minimise the fourier transform power spectrum agains a lorentzian lineshape defined by

\[ L = \frac{p_0}{ ( f - p_1 )^2 + \left( \frac{p_2}{2} \right)^2 } + p_3 \]

Where

  • p0 = the amplitude of the power spectrum
  • p1 = the frequency of the fourier transform peak
  • p2 = the full width at half maximum
  • p3 = a constant offset

Parameters:
ft The complexwf_t encoded fourier transform
freq The returned frequency (p1)
tdecay The returned tdecay (p2)
a p0 (amplitude of powerspectrum ) of the fit ( can be NULL if not interested )
c p3 (offset) of the fit ( can be NULL if not interested )
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 148 of file fit_fft.c.

References bpm_error(), fit_fft_prepare(), complexwf_t::fs, complexwf_t::ns, and complexwf_t::wf.

Referenced by process_caltone(), and process_waveform().

EXTERN int check_saturation ( doublewf_t w,
int  nbits,
int *  iunsat 
)

Checks the saturation, so computes the first sample where no saturation occurs. If no saturation occurred in the waveform, this sample - stored in iunsat - will be set to 0. A saturated sample is found when it's ADC value is more (resp. less) than then maximum allowed ADC value ( 2^nbits ) minus a threshold set to 15. ( resp. the minium allowed ADC value, being 0 ) plus a threshold set to 15.

Attention:
The waveform contained in the doublewf_t SHOULD NOT have been pedestal corrected. This routine will assume the waveform runs between 0 and 2^nbits.
Note the return code of the routine is slightly different than whan is conventional in libbpm since I wanted to encode whether saturation was found or not as the return code of the routine.

Parameters:
w The waveform to check, encoded as a doublewf_t
nbits The number of digitiser bits (e.g. 12 or 14 )
iunsat The returned last unsaturated sample
Returns:
1 when saturation was present, 0 when not, -1 when failure occurred

Definition at line 11 of file check_saturation.c.

References bpm_error(), doublewf_t::ns, and doublewf_t::wf.

Referenced by process_caltone(), and process_waveform().

EXTERN int downmix_waveform ( doublewf_t w,
double  frequency,
complexwf_t out 
)

Downmixes the input waveform agains a complex LO using a frequency f and phase 0, the real part of the resulting complex waveform was mixed against a cosine-like wave, the imaginary part against a sinus-like. Note that this is just the downmixing itself, no filtering whatsoever is applied here.

Parameters:
w The input waveform, encoded as a doublewf_t
freq The frequency of the digital LO
out The complex output downmixed waveform
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure.

Definition at line 10 of file downmix_waveform.c.

References bpm_error(), doublewf_t::fs, complex_t::im, doublewf_t::ns, complex_t::re, doublewf_t::wf, and complexwf_t::wf.

EXTERN int ddc_waveform ( doublewf_t w,
double  frequency,
filter_t filt,
complexwf_t dc,
doublewf_t buf_re,
doublewf_t buf_im 
)

As this is a pure wrapper around the ddc routine out of the dsp packate, please see the documentation there.

Definition at line 12 of file ddc_waveform.c.

References bpm_error(), and ddc().

Referenced by process_caltone(), and process_waveform().

EXTERN int ddc_sample_waveform ( doublewf_t w,
double  frequency,
filter_t filt,
int  iSample,
double  t0,
double  tdecay,
double *  amp,
double *  phase,
doublewf_t buf_re,
doublewf_t buf_im 
)

TO BE IMPLEMENTED !!!

This routine will contain a quicker version of the ddc algorithm that doesn't filter the entire waveform and only applies the filter at the sampling point. However, I need to make custom a apply_filter routine which is universally valid for all types of filters (IIR as well).

Definition at line 19 of file ddc_sample_waveform.c.

References bpm_error().

Referenced by process_waveform().

EXTERN int get_pedestal ( doublewf_t wf,
int  range,
double *  offset,
double *  rms 
)

Find the mean pedestal using the first 20 (or how ever many are required) sample values, store the results in the offset and rms. This routine in fact just calls the doublewf_basic_stats routine and gets the appropriate values from the wfstat_t structure.

Parameters:
wf The signal encoded as a doublewf_t
range The maximum sample to go to average over. The pedestal gets determined from the first "range" samples of the waveform
*offset Returns the mean value of the samples, so voltage offset (pedestal value)
*rms Returns the RMS on that
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 10 of file get_pedestal.c.

References bpm_error(), doublewf_basic_stats(), wfstat_t::mean, and wfstat_t::rms.

Referenced by get_t0(), process_caltone(), and process_waveform().

EXTERN int get_t0 ( doublewf_t w,
double *  t0 
)

Finds the t0 value from a diode peak, used in the case of internall triggering when a trigger pulse needs to be specified to calculate beam arrival

Attention:
This routine needs some optimisation in terms of speed and some general checking in terms of correctness. Probably some re-writing using the bpmwf structures would be good...
Parameters:
w A pointer to the doublewf_t signal
t0 returns t0
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 46 of file get_t0.c.

References bpm_error(), bpm_verbose, bpm_warning(), doublewf_t::fs, get_pedestal(), nr_fit(), doublewf_t::ns, and doublewf_t::wf.

Referenced by fit_diodepulse().

EXTERN int get_IQ ( double  amp,
double  phase,
double  refamp,
double  refphase,
double *  Q,
double *  I 
)

Gets the I and Q from the amplitude and phase of the waveform and it's respective references. The I and Q are calculated respectively as :

\[ I = \frac{A}{A_{ref}} \cos( \phi - \phi_{ref} ) \]

and

\[ Q = \frac{A}{A_{ref}} \sin( \phi - \phi_{ref} ) \]

Parameters:
amp The amplitude of the considered waveform
phase The phase of the considered waveform
refamp The amplitude of the reference cavity
refphase The phase of the reference cavity
Q The returned Q value
I The returned I value
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 8 of file get_IQ.c.

References bpm_error(), and bpm_warning().

Referenced by postprocess_waveform().

EXTERN int get_pos ( double  Q,
double  I,
double  IQphase,
double  posscale,
double *  pos 
)

Returns the beam given I and Q values, IQphase and scale, it is calcualted as

\[ x = c \left[ I \cos (\phi_{IQ} ) + Q \sin ( \phi_IQ )\right] \]

Where c is the positionscale and x the position.

Parameters:
Q The Q value (obtained from get_IQ)
I The I value (obtained from get_IQ)
IQphase The IQ phase rotation
posscale The position scale
pos The returned position
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 8 of file get_pos.c.

References bpm_error().

Referenced by postprocess_waveform().

EXTERN int get_slope ( double  Q,
double  I,
double  IQphase,
double  slopescale,
double *  slope 
)

Returns the beam slope given I and Q values, IQphase and scale, it is calcualted as

\[ x' = c \left[ - I \sin (\phi_{IQ} ) + Q \cos ( \phi_IQ )\right] \]

Where c is the positionscale and x the position.

Parameters:
Q The Q value (obtained from get_IQ)
I The I value (obtained from get_IQ)
IQphase The IQ phase rotation
slopescale The slope scale
slope The returned slope
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 8 of file get_slope.c.

References bpm_error().

Referenced by postprocess_waveform().


Generated on Wed Jun 25 17:32:49 2008 for libbpm by  doxygen 1.5.6