00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00365 #ifndef BPMDSP_H__
00366 #define BPMDSP_H__
00367
00368
00369
00370
00371 #include <stdio.h>
00372 #include <stdlib.h>
00373 #include <string.h>
00374 #include <math.h>
00375
00376 #include "bpm/bpm_defs.h"
00377 #include "bpm/bpm_messages.h"
00378 #include "bpm/bpm_nr.h"
00379 #include "bpm/bpm_wf.h"
00380
00381
00382
00383
00384 #define BESSEL 0x0000001
00385 #define BUTTERWORTH 0x0000002
00386 #define CHEBYSHEV 0x0000004
00387 #define RAISEDCOSINE 0x0000008
00388 #define RESONATOR 0x0000010
00389 #define GAUSSIAN 0x0000020
00391 #define BILINEAR_Z_TRANSFORM 0x0000100
00392 #define MATCHED_Z_TRANSFORM 0x0000200
00393 #define NO_PREWARP 0x0000400
00394 #define CAUSAL 0x0000800
00395 #define ANTICAUSAL 0x0001000
00396 #define NONCAUSAL 0x0001800
00397 #define GAUSSIAN_SIGMA_BW 0x0002000
00399 #define LOWPASS 0x0010000
00400 #define HIGHPASS 0x0020000
00401 #define BANDPASS 0x0040000
00402 #define BANDSTOP 0x0080000
00403 #define NOTCH 0x0080000
00404 #define ALLPASS 0x0100000
00406 #define FIR 0x0200000
00407 #define IIR 0x0400000
00409 #define MAXORDER 10
00410 #define MAXPZ 50
00411 #define FILT_EPS 1.0e-10
00412 #define MAX_RESONATOR_ITER 50
00414 #define FFT_FORWARD 0
00415 #define FFT_BACKWARD 1
00417
00418
00419
00420 #ifdef __cplusplus
00421 extern "C" {
00422 #endif
00423
00427 typedef struct {
00428 int npoles;
00429 int nzeros;
00430 complex_t pole[MAXPZ];
00431 complex_t zero[MAXPZ];
00432 } filterrep_t;
00433
00437 typedef struct {
00438 char name[80];
00440 unsigned int options;
00441 int order;
00443 double fs;
00444 double f1;
00445 double f2;
00447 double alpha1;
00448 double alpha2;
00450 double w_alpha1;
00451 double w_alpha2;
00453 double cheb_ripple;
00454 double Q;
00455 double gauss_cutoff;
00457 complex_t dc_gain;
00458 complex_t fc_gain;
00459 complex_t hf_gain;
00460 double gain;
00462 filterrep_t *cplane;
00464 int nxc;
00465 double xc[MAXPZ+1];
00467 int nxc_ac;
00468 double xc_ac[MAXPZ+1];
00470 int nyc;
00471 double yc[MAXPZ+1];
00473 int nyc_ac;
00474 double yc_ac[MAXPZ+1];
00476 double xv[MAXPZ+1];
00477 double xv_ac[MAXPZ+1];
00479 double yv[MAXPZ+1];
00480 double yv_ac[MAXPZ+1];
00482 int ns;
00483 double *wfbuffer;
00485 } filter_t;
00486
00487
00488
00489
00490
00491
00508 EXTERN filter_t* create_filter( char name[], unsigned int options, int order,
00509 int ns, double fs, double f1, double f2, double par );
00510
00522 EXTERN int apply_filter( filter_t *f, doublewf_t *w );
00523
00524
00531 EXTERN void print_filter( FILE *of, filter_t *f );
00532
00538 EXTERN void delete_filter( filter_t *f );
00539
00540
00550 EXTERN int filter_step_response( filter_t *f, doublewf_t *w, int itrig );
00551
00561 EXTERN int filter_impulse_response( filter_t *f, doublewf_t *w, int itrig );
00562
00563
00564
00575 EXTERN filterrep_t* create_splane_representation( filter_t *f );
00576
00577
00587 EXTERN filterrep_t* create_resonator_representation( filter_t *f );
00588
00599 EXTERN filterrep_t* zplane_transform( filter_t *f, filterrep_t *s );
00600
00601
00608 EXTERN void print_filter_representation( FILE* of, filterrep_t *r );
00609
00610
00617 EXTERN int normalise_filter( filter_t *f, filterrep_t *s );
00618
00619
00632 EXTERN int calculate_filter_coefficients( filter_t *f );
00633
00634
00642 EXTERN int gaussian_filter_coeffs( filter_t *f );
00643
00644
00652 EXTERN int _expand_complex_polynomial( complex_t *w, int n, complex_t *a );
00653
00661 EXTERN complex_t _eval_complex_polynomial( complex_t *a, int n, complex_t z );
00662
00663
00664
00665
00672 EXTERN int ddc_initialise( int ns, double fs );
00673
00676 EXTERN void ddc_cleanup( void );
00677
00692 int ddc( doublewf_t *w, double f, filter_t *filter, complexwf_t *dcw,
00693 doublewf_t *bufre, doublewf_t *bufim );
00694
00695
00696
00697
00700 EXTERN int fft_gen_tables( void );
00701
00707 EXTERN int fft_initialise( int ns );
00708
00712 EXTERN void fft_cleanup( void );
00713
00721 EXTERN int complexfft( complexwf_t *z, int fft_mode );
00722
00730 EXTERN int realfft( doublewf_t *y, int fft_mode, complexwf_t *z );
00731
00736 EXTERN void norm_phase( double *phase );
00737
00738 #ifdef __cplusplus
00739 }
00740 #endif
00741
00742 #endif
00743
00744
00745