BPM signal processing


Files

file  add_scalar_waveform.c
file  basic_stats.c
file  bpm_process.h
 libbpm main processing routines
file  copy_waveform.c
file  ddc_gaussfilter.c
file  ddc_gaussfilter_step.c
file  ddc_sample_waveform.c
file  ddc_waveform.c
file  downmix_waveform.c
file  fft_waveform.c
file  fit_ddc.c
file  fit_diodepulse.c
file  fit_fft.c
file  fit_waveform.c
file  freq_to_sample.c
file  get_IQ.c
file  get_pedestal.c
file  get_pos.c
file  get_slope.c
file  get_t0.c
file  handle_saturation.c
file  int_to_double_waveform.c
file  mult_scalar_waveform.c
file  mult_waveform.c
file  process_diode.c
file  process_dipole.c
file  process_monopole.c
file  process_waveform.c
file  sample_to_freq.c
file  sample_to_time.c
file  time_to_sample.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_STOREFULL
#define PROC_FIT_DDC

Functions

EXTERN int process_diode (bpmconf_t *, bpmsignal_t *, bpmproc_t *)
EXTERN int process_waveform (enum bpmtype_t type, bpmconf_t *bpm, bpmcalib_t *cal, bpmsignal_t *sig, bpmproc_t *proc, bpmproc_t *trig, unsigned int mode)
EXTERN int process_monopole (bpmconf_t *bpm, bpmcalib_t *cal, bpmsignal_t *sig, bpmproc_t *proc, bpmproc_t *trig, unsigned int mode)
EXTERN int process_dipole (bpmconf_t *bpm, bpmcalib_t *cal, bpmsignal_t *sig, bpmproc_t *proc, bpmproc_t *trig, bpmproc_t *ref, unsigned int mode)
EXTERN int fit_waveform (int *wf, int ns, double t0, double fs, double i_freq, double i_tdecay, double i_amp, double i_phase, double *freq, double *tdecay, double *amp, double *phase)
EXTERN int fit_diodepulse (int *wf, int ns, double fs, double *t0)
EXTERN int fit_ddc (double *ddc, int ns, double *tdecay)
EXTERN int fit_fft_prepare (double **fft, int ns, double fs, int *n1, int *n2, double *amp, double *freq, double *fwhm)
EXTERN int fit_fft (double **fft, int ns, double fs, double *freq, double *tdecay, double *A, double *C)
EXTERN int fft_waveform (int *wf, int ns, double **fft)
EXTERN int fft_waveform_double (double *wf, int ns, double **fft)
EXTERN int handle_saturation (int *wf, int ns, int imax, int nbits, int threshold, int *iunsat)
EXTERN int downmix_waveform (double *wf, int ns, double fs, double freq, double t0, double **out)
EXTERN int ddc_gaussfilter_step (double **ddc, int ns, double fs, int istart, int istop, double tfilter, double filtBW, double *out)
EXTERN int ddc_gaussfilter (double **ddc, int ns, double fs, double filtBW, double epsFilt, double **out)
EXTERN int ddc_waveform (int *wf, int ns, int nbits, double fs, double t0, double freq, double tdecay, double filtBW, double epsFilt, double **out)
EXTERN int ddc_sample_waveform (int *wf, int ns, int nbits, double fs, double t0, double t0Offset, double freq, double tdecay, double filtBW, double epsFilt, double *amp, double *phase)
EXTERN int get_pedestal (int *wf, int ns, int range, double *offset, double *rms)
EXTERN int basic_stats (int *wf, int ns, int range, int nbits, double *offset, double *rms, int *max, int *min, int *unsat_sample)
EXTERN int int_to_double_waveform (double *wf_double, int *wf_int, int ns)
EXTERN int copy_waveform (double *wf_src, double *wf_dst, int ns)
EXTERN int add_scalar_waveform (double *wf, int ns, double add)
EXTERN int mult_scalar_waveform (double *wf, int ns, double mult)
EXTERN int mult_waveform (double *wf1, double *wf2, int ns)
EXTERN int get_t0 (int *wf, int ns, double fs, 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)
EXTERN int time_to_sample (double fs, int ns, double t, int *iS)
EXTERN int sample_to_time (double fs, int ns, int iS, double *t)
EXTERN int freq_to_sample (double fs, int ns, double f, int *iS)
EXTERN int sample_to_freq (double fs, int ns, int iS, double *f)


Function Documentation

EXTERN int process_diode ( bpmconf_t bpm,
bpmsignal_t sig,
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.

Parameters:
bpm The bpm configuration structure
sig The bpm signal
proc The processed waveform structure
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 19 of file process_diode.c.

References bpm_error(), bpmconf::cav_type, bpmconf::digi_freq, bpmconf::digi_nsamples, diode, fit_diodepulse(), bpmconf::name, bpmproc::t0, and bpmsignal::wf.

EXTERN int process_waveform ( enum bpmtype_t  type,
bpmconf_t bpm,
bpmcalib_t cal,
bpmsignal_t sig,
bpmproc_t proc,
bpmproc_t trig,
unsigned int  mode 
)

Processes a general decaying sin wave according to the bitpattern given in mode the type needs to be specified to see whether the waveform type that is processed is correct to which what is expected. This routines is both used by process_monopole ( which essentially does nothing more than wrap around this routine) and process_dipole which after this routine goes on to calculated the IQ and positions and tilt

Parameters:
type the bpm type
bpm the bpm configuration structure
cal the current valid calibration for the bpm
sig the waveform structure
proc the processed data structure
trig a pointer to the structure with processed trigger info for that waveform
mode processing mode
Returns:
BPM_SUCCESS upon succes, BPM_FAILURE upon failure

Definition at line 27 of file process_waveform.c.

References bpmproc::ampnoise, bpm_error(), bpm_warning(), bpmconf::cav_decaytime, bpmconf::cav_freq, bpmconf::cav_type, bpmproc::ddc_amp, bpmproc::ddc_phase, ddc_sample_waveform(), bpmproc::ddc_success, ddc_waveform(), bpmcalib::ddcepsFilt, bpmcalib::ddcfiltBW, bpmproc::ddcwf, bpmconf::digi_freq, bpmconf::digi_nbits, bpmconf::digi_nsamples, bpmproc::fft_freq, bpmproc::fft_success, bpmproc::fft_tdecay, fft_waveform(), bpmproc::fftwf, bpmproc::fit_amp, fit_fft(), bpmproc::fit_freq, bpmproc::fit_phase, bpmproc::fit_success, bpmproc::fit_tdecay, fit_waveform(), bpmcalib::freq, get_pedestal(), handle_saturation(), MHz, bpmconf::name, nsec, PROC_DDC_FFTFREQ, PROC_DDC_FFTTDECAY, PROC_DDC_FITFREQ, PROC_DDC_FITTDECAY, PROC_DDC_STOREFULL, PROC_DO_DDC, PROC_DO_FFT, PROC_DO_FIT, bpmconf::rf_LOfreq, sample_to_time(), bpmproc::t0, bpmcalib::t0Offset, bpmcalib::tdecay, usec, bpmproc::voltageoffset, and bpmsignal::wf.

Referenced by process_dipole(), and process_monopole().

EXTERN int process_monopole ( bpmconf_t bpm,
bpmcalib_t cal,
bpmsignal_t sig,
bpmproc_t proc,
bpmproc_t trig,
unsigned int  mode 
)

Processes a monopole waveform according to the bitpattern given in mode. Is basically a wrapper for process_waveform() !

Parameters:
bpm the bpm configuration structure
cal the current valid calibration for the bpm
sig the waveform structure
proc the processed data structure
trig a pointer to 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 23 of file process_monopole.c.

References monopole, and process_waveform().

EXTERN int process_dipole ( bpmconf_t bpm,
bpmcalib_t cal,
bpmsignal_t sig,
bpmproc_t proc,
bpmproc_t trig,
bpmproc_t ref,
unsigned int  mode 
)

Process dipole waveform

Parameters:
bpm Configuration structure for the bpm waveform to be processed
cal Calibration strcture with calib info to use
sig The BPM signal itself
proc The resuling processed signal
trig The already processed trigger waveform
ref The already processed reference waveform
mode Processing mode
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 22 of file process_dipole.c.

References bpm_error(), bpmproc::ddc_amp, bpmproc::ddc_I, bpmproc::ddc_phase, bpmproc::ddc_pos, bpmproc::ddc_Q, bpmproc::ddc_slope, bpmproc::ddc_success, dipole, bpmproc::fit_amp, bpmproc::fit_I, bpmproc::fit_phase, bpmproc::fit_pos, bpmproc::fit_Q, bpmproc::fit_slope, bpmproc::fit_success, get_IQ(), get_pos(), get_slope(), bpmcalib::IQphase, bpmconf::name, bpmcalib::posscale, process_waveform(), and bpmcalib::slopescale.

EXTERN int fit_waveform ( int *  wf,
int  ns,
double  t0,
double  fs,
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 !

Parameters:
*wf the waveform
ns number of samples
t0 t0 for the waveform
fs the sampling frequency
i_freq initial frequency for fit
i_tdecay initial tdecay
i_amp initial amp
i_phase initial phase
freq fitted frequency
tdecay fitted tdecay
amp fitted amplitude
phase fitted phase
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 101 of file fit_waveform.c.

References alloc_simple_wave_double(), bpm_error(), fcnwf(), fcnwfjac(), FIT_AMP, FIT_FREQ, FIT_FS, FIT_MAX_ITER, FIT_PHASE, FIT_T0, FIT_TDECAY, free_simple_wave_double(), get_pedestal(), LM_INFO_SZ, and LM_INIT_MU.

Referenced by process_waveform().

EXTERN int fit_diodepulse ( int *  wf,
int  ns,
double  fs,
double *  t0 
)

Fits the diode pulse, basically a wrapper for get_t0, to conserve names and consistency in the library...

see get_t0()

Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 17 of file fit_diodepulse.c.

References get_t0().

Referenced by process_diode().

EXTERN int fit_ddc ( double *  ddc,
int  ns,
double *  tdecay 
)

Fits the ddc to get the decay time, gets inital pars from ddc wf itself

NOT IMPLEMENTED YET !

Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 15 of file fit_ddc.c.

References bpm_error().

EXTERN int fit_fft_prepare ( double **  fft,
int  ns,
double  fs,
int *  n1,
int *  n2,
double *  amp,
double *  freq,
double *  fwhm 
)

Prepares the fft fit of the waveform, fits only in the first nyquist band, scans the fft for the maximum value and returns !

Definition at line 77 of file fit_fft.c.

References bpm_error(), FIT_WINDOW_FACTOR, and MHz.

Referenced by fit_fft().

EXTERN int handle_saturation ( int *  wf,
int  ns,
int  imax,
int  nbits,
int  threshold,
int *  iunsat 
)

Handles the saturation, so computes the first sample where no saturation occurs, or imax if bigger...

Parameters:
wf the waveform
ns number of samples
imax maximum sample to look after
nbits number of digitiser bits
threshold is the distance from 0 that an adc value needs to be for it not to be saturated, as well as distance from 2^nbits
iunsat the returned last unsaturated sample
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 25 of file handle_saturation.c.

References bpm_error(), and bpm_warning().

Referenced by basic_stats(), ddc_sample_waveform(), and process_waveform().

EXTERN int downmix_waveform ( double *  wf,
int  ns,
double  fs,
double  freq,
double  t0,
double **  out 
)

Performs the DDC on the input waveform

Parameters:
wf input waveform (with the pedestal substracted!)
ns number of samples in the waveform
fs sampling frequency
freq frequency of the signal
t0 sampling point
out complex output DDC waveform

Definition at line 21 of file downmix_waveform.c.

References bpm_error().

Referenced by ddc_sample_waveform(), and ddc_waveform().

EXTERN int ddc_gaussfilter_step ( double **  ddc,
int  ns,
double  fs,
int  istart,
int  istop,
double  tfilter,
double  filtBW,
double *  out 
)

Performs one step in the gaussian filter

Parameters:
ddc the complex ddc wavform
ns number of samples
fs sampling frequency
istart starting sample for moving window
istop stop stample for moving window
tfilter filter time
filtBW filter bandwith
out a double[2] that will contain the resulting filtered Re and Im values at tfilter
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 25 of file ddc_gaussfilter_step.c.

References bpm_error(), bpm_warning(), and sample_to_time().

Referenced by ddc_gaussfilter(), and ddc_sample_waveform().

EXTERN int ddc_gaussfilter ( double **  ddc,
int  ns,
double  fs,
double  filtBW,
double  epsFilt,
double **  out 
)

Applies a gaussian filter to the total waveform with the given filter bandwidth and cut-off parameters

Parameters:
ddc complex double array with the downconverted waveform
ns number of samples
fs sampling frequency
filtBW filter bandwidth in MHz
epsFilt filter cutoff parameter
out complex double array with the filtered waveform
Returns:
BPM_SUCCESS upon succcess, BPM_FAILURE upon failure

Definition at line 23 of file ddc_gaussfilter.c.

References bpm_error(), ddc_gaussfilter_step(), sample_to_time(), and time_to_sample().

Referenced by ddc_waveform().

EXTERN int ddc_waveform ( int *  wf,
int  ns,
int  nbits,
double  fs,
double  t0,
double  freq,
double  tdecay,
double  filtBW,
double  epsFilt,
double **  out 
)

Does the DDC of the full waveform and stores it into the ampwf and phasewf waveforms this routine calls the simple ddc(...) routine to do one step. Note that this one doesn't need t0 or t0Offset as it will scan through the entire waveform...

Parameters:
wf the waveform
ns the number of samples
nbits the number of digitiser bits
fs the sampling frequency
t0 the trigger time
freq the frequency of the waveform to downmix with
tdecay the decay time of the waveform
filtBW the gaussian filter bandwith
epsFilt the gaussian filter cut-off parameter
out contains the downconverted, filtered complex waveform
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 39 of file ddc_waveform.c.

References alloc_complex_wave_double(), alloc_simple_wave_double(), bpm_error(), ddc(), ddc_gaussfilter(), downmix_waveform(), free_complex_wave_double(), free_simple_wave_double(), and get_pedestal().

Referenced by process_waveform().

EXTERN int ddc_sample_waveform ( int *  wf,
int  ns,
int  nbits,
double  fs,
double  t0,
double  t0Offset,
double  freq,
double  tdecay,
double  filtBW,
double  epsFilt,
double *  amp,
double *  phase 
)

Does a quick DDC of the waveform and stores it into the ampwf and phasewf waveforms this routine calls the simple ddc(...) routine to do one step... the sampling point is determined by t0 + t0Offset

Parameters:
wf the waveform
ns the number of samples
nbits the number of digitiser bits
fs the sampling frequency
t0 the trigger time
t0Offset the sampling point
freq the frequency of the waveform to downmix with
tdecay the decay time of the waveform
filtBW the gaussian filter bandwith
epsFilt the gaussian filter cut-off parameter
amp amplitude at the sampling point
phase phase at the sampling point
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 40 of file ddc_sample_waveform.c.

References alloc_complex_wave_double(), bpm_error(), ddc(), ddc_gaussfilter_step(), downmix_waveform(), free_complex_wave_double(), handle_saturation(), time_to_sample(), and usec.

Referenced by process_waveform().

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

Find the mean pedestal using the first 20 (or how ever many are required) sample values

Parameters:
wf a pointer to the waveform data
ns the number of samples in the waveform
range the maximum sample to go to average over
*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 22 of file get_pedestal.c.

References bpm_error(), and bpm_warning().

Referenced by ddc_waveform(), fit_waveform(), get_t0(), and process_waveform().

EXTERN int basic_stats ( int *  wf,
int  ns,
int  range,
int  nbits,
double *  offset,
double *  rms,
int *  max,
int *  min,
int *  unsat_sample 
)

Find the mean pedestal using the first 20 (or how ever many are required) sample values

Parameters:
wf a pointer to the waveform data
ns the number of samples in the waveform
range the maximum sample to go to average over
nbits the number of digitiser bits
offset returns the mean value of the samples, so voltage offset (pedestal value)
rms returns the RMS on that
max returns max value of wf
min returns min value of wf
unsat_sample returns last unsaturated sample
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 26 of file basic_stats.c.

References bpm_error(), bpm_warning(), and handle_saturation().

EXTERN int int_to_double_waveform ( double *  wf_double,
int *  wf_int,
int  ns 
)

Cast int waveform values into double waveform values

Parameters:
*wf_double waveform double
*wf_int waveform int
ns the number of samples
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 20 of file int_to_double_waveform.c.

References bpm_error().

EXTERN int copy_waveform ( double *  wf_dst,
double *  wf_src,
int  ns 
)

Copies wf_src to wf_dst

Parameters:
wf_dst destination waveform
wf_src source waveform
ns the number of samples
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 20 of file copy_waveform.c.

References bpm_error().

EXTERN int mult_scalar_waveform ( double *  wf,
int  ns,
double  mult 
)

Multiply all values by a factor mult

Parameters:
*wf the waveform
ns the number of samples
mult the factor to multiply all points in waveform
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 20 of file mult_scalar_waveform.c.

References bpm_error().

EXTERN int mult_waveform ( double *  wf1,
double *  wf2,
int  ns 
)

Multiply all values by a factor mult

Parameters:
*wf1 the waveform1, on return wf1 = wf1*wf2
*wf2 the waveform2
ns the number of samples
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 20 of file mult_waveform.c.

References bpm_error().

EXTERN int get_t0 ( int *  wf,
int  ns,
double  fs,
double *  t0 
)

Finds the t0 value from a diode peak

Parameters:
wf a pointer to the waveform data
ns the number of samples in the waveform
fs sampling frequency
t0 returns t0 in usec
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 56 of file get_t0.c.

References bpm_error(), bpm_verbose, bpm_warning(), find_t0_endfit(), find_t0_startfit(), get_pedestal(), and nr_fit().

Referenced by fit_diodepulse().

EXTERN int time_to_sample ( double  fs,
int  ns,
double  t,
int *  iS 
)

Converts a time to a sample number, given the sampling frequency

Parameters:
fs sampling frequency
ns number of samples
t the queried time sample
iS the returned sample number
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 18 of file time_to_sample.c.

Referenced by ddc_gaussfilter(), and ddc_sample_waveform().

EXTERN int sample_to_time ( double  fs,
int  ns,
int  iS,
double *  t 
)

Converts a sample number to a time given the sampling frequency

Parameters:
fs sampling frequency
ns number of samples
t the queried sample
iS the returned sample time
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 18 of file sample_to_time.c.

Referenced by ddc_gaussfilter(), ddc_gaussfilter_step(), fcnwf(), fcnwfjac(), and process_waveform().

EXTERN int sample_to_freq ( double  fs,
int  ns,
int  iS,
double *  f 
)

This routine returns the frequency corresponding to the sample number, note that this routine is not aware of the nyquist bands, and just keeps on counting from 0 -> fs.

Parameters:
fs sampling frequency
ns number of samples
iS the queried sample to get the frequency of
f the returned frequency
Returns:
BPM_SUCCESS upon success, BPM_FAILURE upon failure

Definition at line 20 of file sample_to_freq.c.


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