00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00366 #ifndef BPMDSP_H__
00367 #define BPMDSP_H__
00368
00369
00370
00371
00372 #include <stdio.h>
00373 #include <stdlib.h>
00374 #include <string.h>
00375 #include <math.h>
00376
00377 #include "bpm/bpm_defs.h"
00378 #include "bpm/bpm_messages.h"
00379 #include "bpm/bpm_alloc.h"
00380 #include "bpm/bpm_nr.h"
00381 #include "bpm/bpm_wf.h"
00382
00383
00384
00385
00386 #define BESSEL 0x0000001
00387 #define BUTTERWORTH 0x0000002
00388 #define CHEBYSHEV 0x0000004
00389 #define RAISEDCOSINE 0x0000008
00390 #define RESONATOR 0x0000010
00391 #define GAUSSIAN 0x0000020
00393 #define BILINEAR_Z_TRANSFORM 0x0000100
00394 #define MATCHED_Z_TRANSFORM 0x0000200
00395 #define NO_PREWARP 0x0000400
00396 #define CAUSAL 0x0000800
00397 #define ANTICAUSAL 0x0001000
00398 #define NONCAUSAL 0x0001800
00399 #define GAUSSIAN_SIGMA_BW 0x0002000
00401 #define LOWPASS 0x0010000
00402 #define HIGHPASS 0x0020000
00403 #define BANDPASS 0x0040000
00404 #define BANDSTOP 0x0080000
00405 #define NOTCH 0x0080000
00406 #define ALLPASS 0x0100000
00408 #define FIR 0x0200000
00409 #define IIR 0x0400000
00411 #define MAXORDER 10
00412 #define MAXPZ 50
00413 #define FILT_EPS 1.0e-10
00414 #define MAX_RESONATOR_ITER 50
00416 #define FFT_FORWARD 0
00417 #define FFT_BACKWARD 1
00419
00420
00421
00422 #ifdef __cplusplus
00423 extern "C" {
00424 #endif
00425
00429 typedef struct {
00430 int npoles;
00431 int nzeros;
00432 complex_t pole[MAXPZ];
00433 complex_t zero[MAXPZ];
00434 } filterrep_t;
00435
00439 typedef struct {
00440 char name[80];
00442 unsigned int options;
00443 int order;
00445 double fs;
00446 double f1;
00447 double f2;
00449 double alpha1;
00450 double alpha2;
00452 double w_alpha1;
00453 double w_alpha2;
00455 double cheb_ripple;
00456 double Q;
00457 double gauss_cutoff;
00459 complex_t dc_gain;
00460 complex_t fc_gain;
00461 complex_t hf_gain;
00462 double gain;
00464 filterrep_t *cplane;
00466 int nxc;
00467 double xc[MAXPZ+1];
00469 int nxc_ac;
00470 double xc_ac[MAXPZ+1];
00472 int nyc;
00473 double yc[MAXPZ+1];
00475 int nyc_ac;
00476 double yc_ac[MAXPZ+1];
00478 double xv[MAXPZ+1];
00479 double xv_ac[MAXPZ+1];
00481 double yv[MAXPZ+1];
00482 double yv_ac[MAXPZ+1];
00484 int ns;
00485 double *wfbuffer;
00487 } filter_t;
00488
00489
00490
00491
00492
00493
00510 EXTERN filter_t* create_filter( char name[], unsigned int options, int order,
00511 int ns, double fs, double f1, double f2, double par );
00512
00524 EXTERN int apply_filter( filter_t *f, double *wf );
00525
00526
00533 EXTERN void print_filter( FILE *of, filter_t *f );
00534
00540 EXTERN void delete_filter( filter_t *f );
00541
00542
00552 EXTERN int filter_step_response( filter_t *f, double *wf, int itrig );
00553
00563 EXTERN int filter_impulse_response( filter_t *f, double *wf, int itrig );
00564
00565
00566
00577 EXTERN filterrep_t* create_splane_representation( filter_t *f );
00578
00579
00589 EXTERN filterrep_t* create_resonator_representation( filter_t *f );
00590
00601 EXTERN filterrep_t* zplane_transform( filter_t *f, filterrep_t *s );
00602
00603
00610 EXTERN void print_filter_representation( FILE* of, filterrep_t *r );
00611
00612
00619 EXTERN int normalise_filter( filter_t *f, filterrep_t *s );
00620
00621
00634 EXTERN int calculate_filter_coefficients( filter_t *f );
00635
00636
00644 EXTERN int gaussian_filter_coeffs( filter_t *f );
00645
00646
00654 EXTERN int _expand_complex_polynomial( complex_t *w, int n, complex_t *a );
00655
00663 EXTERN complex_t _eval_complex_polynomial( complex_t *a, int n, complex_t z );
00664
00665
00666
00667
00674 EXTERN int ddc_initialise( int ns, double fs );
00675
00678 EXTERN void ddc_cleanup( void );
00679
00689 int ddc( doublewf_t *w, double f, filter_t *filter, complexwf_t *dcw );
00690
00691
00692
00693
00696 EXTERN int fft_gen_tables( void );
00697
00703 EXTERN int fft_initialise( int ns );
00704
00708 EXTERN void fft_cleanup( void );
00709
00717 EXTERN int complexfft( complexwf_t *z, int fft_mode );
00718
00726 EXTERN int realfft( doublewf_t *y, int fft_mode, complexwf_t *z );
00727
00728
00729 #ifdef __cplusplus
00730 }
00731 #endif
00732
00733 #endif
00734
00735
00736