Digital signal processing routines


Files

file  bpm_dsp.h
 libbpm digital signal processing routines
file  calculate_filter_coefficients.c
file  create_filter.c
file  create_resonator_representation.c
file  create_splane_representation.c
file  delete_filter.c
file  filter_impulse_response.c
file  filter_step_response.c
file  normalise_filter.c
file  print_filter.c
file  print_filter_representation.c
file  zplane_transform.c

Data Structures

struct  filterrep_t
struct  filter_t

Defines

#define BESSEL
#define BUTTERWORTH
#define CHEBYSHEV
#define RAISEDCOSINE
#define RESONATOR
#define GAUSSIAN
#define BILINEAR_Z_TRANSFORM
#define MATCHED_Z_TRANSFORM
#define NO_PREWARP
#define LOWPASS
#define HIGHPASS
#define BANDPASS
#define BANDSTOP
#define NOTCH
#define ALLPASS
#define MAXORDER
#define MAXPZ
#define FILT_EPS
#define MAX_RESONATOR_ITER

Functions

EXTERN filter_tcreate_filter (char name[], unsigned int options, int order, int ns, double fs, double f1, double f2, double par)
EXTERN int apply_filter (filter_t *f, double *wf)
EXTERN void print_filter (FILE *of, filter_t *f)
EXTERN void delete_filter (filter_t *f)
EXTERN int filter_step_response (filter_t *f, double *wf, int itrig)
EXTERN int filter_impulse_response (filter_t *f, double *wf, int itrig)
EXTERN filterrep_tcreate_splane_representation (filter_t *f)
EXTERN filterrep_tcreate_resonator_representation (filter_t *f)
EXTERN filterrep_tzplane_transform (filter_t *f, filterrep_t *s)
EXTERN void print_filter_representation (FILE *of, filterrep_t *r)
EXTERN int normalise_filter (filter_t *f, filterrep_t *s)
EXTERN int calculate_filter_coefficients (filter_t *f)
EXTERN int _expand_complex_polynomial (complex_t *w, int n, complex_t *a)
EXTERN complex_t _eval_complex_polynomial (complex_t *a, int n, complex_t z)


Define Documentation

#define BESSEL

Bitmask for Bessel filter

Definition at line 32 of file bpm_dsp.h.

Referenced by create_filter(), and create_splane_representation().

#define BUTTERWORTH

Bitmask for Butterworth filter

Definition at line 33 of file bpm_dsp.h.

Referenced by create_filter(), and create_splane_representation().

#define CHEBYSHEV

Bitmask for Chebyshev filter

Definition at line 34 of file bpm_dsp.h.

Referenced by create_filter(), and create_splane_representation().

#define RAISEDCOSINE

Bitmask for Raised Cosine filter

Definition at line 35 of file bpm_dsp.h.

#define RESONATOR

Bitmask for Resonator filter

Definition at line 36 of file bpm_dsp.h.

Referenced by create_filter().

#define GAUSSIAN

Bitmask for Gaussian filter

Definition at line 37 of file bpm_dsp.h.

#define BILINEAR_Z_TRANSFORM

Get z poles via bilinear z transform from s plane

Definition at line 39 of file bpm_dsp.h.

#define MATCHED_Z_TRANSFORM

Get z poles via matches z transform from s plane

Definition at line 40 of file bpm_dsp.h.

Referenced by zplane_transform().

#define NO_PREWARP

Don't do the prewarp correction

Definition at line 41 of file bpm_dsp.h.

Referenced by create_filter().

#define LOWPASS

Normalise filter as lowpass

Definition at line 43 of file bpm_dsp.h.

Referenced by calculate_filter_coefficients(), and normalise_filter().

#define HIGHPASS

Normalise filter as highpass

Definition at line 44 of file bpm_dsp.h.

Referenced by calculate_filter_coefficients(), and normalise_filter().

#define BANDPASS

Normalise filter as bandpass

Definition at line 45 of file bpm_dsp.h.

Referenced by calculate_filter_coefficients().

#define BANDSTOP

Normalise filter as bandstop

Definition at line 46 of file bpm_dsp.h.

Referenced by calculate_filter_coefficients(), and create_resonator_representation().

#define NOTCH

Normalise filter as notch filter (=bandstop)

Definition at line 47 of file bpm_dsp.h.

#define ALLPASS

Normalise filter as allpass ( resonator )

Definition at line 48 of file bpm_dsp.h.

Referenced by create_resonator_representation().

#define MAXORDER

Maximum filter order

Definition at line 50 of file bpm_dsp.h.

#define MAXPZ

Maximum number of poles and zeros

Definition at line 51 of file bpm_dsp.h.

Referenced by calculate_filter_coefficients(), and create_resonator_representation().

#define FILT_EPS

A small number used in bpmdsp

Definition at line 52 of file bpm_dsp.h.

Referenced by _expand_complex_polynomial(), create_resonator_representation(), and print_filter().

#define MAX_RESONATOR_ITER

Maximum iterations in resonator poles calculation

Definition at line 53 of file bpm_dsp.h.

Referenced by create_resonator_representation().


Function Documentation

EXTERN filter_t* create_filter ( char  name[],
unsigned int  options,
int  order,
int  ns,
double  fs,
double  f1,
double  f2,
double  par 
)

Creates the filter.

Parameters:
name a name for the filter
options filter specification and options bitword
order filter order
ns number of samples of the waveforms
fs sampling frequency
f1 first frequency
f2 optional second frequency ( bandpass/bandstop )
par optional parameter
  • for chebyshev : ripple in dB
  • for resonator : Q factor
Returns:
A pointer to the created filter structure, memory is allocated on the heap inside this routine, the user has to take of deleting it using delete_filter().

Definition at line 10 of file create_filter.c.

References alloc_simple_wave_double(), filter_t::alpha1, filter_t::alpha2, BESSEL, bpm_error(), bpm_warning(), BUTTERWORTH, calculate_filter_coefficients(), filter_t::cheb_ripple, CHEBYSHEV, filter_t::cplane, create_resonator_representation(), create_splane_representation(), filter_t::f1, filter_t::f2, filter_t::fs, filter_t::IsFIR, filter_t::name, NO_PREWARP, normalise_filter(), filterrep_t::npoles, filter_t::ns, filter_t::options, filter_t::order, filter_t::Q, RESONATOR, filter_t::w_alpha1, filter_t::w_alpha2, filter_t::wfbuffer, filter_t::yc, and zplane_transform().

EXTERN int apply_filter ( filter_t f,
double *  wf 
)

Apply the filter to the given waveform. Note that the filter is applied in place, the user has to make a copy of the waveform if he/she wants to keep the original before applying the filter. The number of samples in the waveform has to be set in advance when creating the filter, it is stored in the filter structure (f->ns).

Parameters:
f pointer to a filter that was created using create_filter
wf an array containing the waveform to be filtered
Returns:
BPM_SUCCESS upon success and BPM_FAILURE upon failure

Definition at line 19 of file apply_filter.c.

References bpm_error(), filter_t::gain, filter_t::IsFIR, filter_t::ns, filter_t::nxc, filter_t::nyc, filter_t::wfbuffer, filter_t::xc, filter_t::xv, filter_t::yc, and filter_t::yv.

Referenced by filter_impulse_response(), and filter_step_response().

EXTERN void print_filter ( FILE *  of,
filter_t f 
)

Prints the filter to the given file pointer.

Parameters:
of the filepointer, use "stdout" to print to the terminal
f the filter to be printed
Returns:
void

Definition at line 8 of file print_filter.c.

References bpm_error(), c_abs(), c_arg(), filter_t::cplane, filter_t::dc_gain, filter_t::fc_gain, FILT_EPS, filter_t::hf_gain, filter_t::name, filter_t::nxc, print_filter_representation(), and filter_t::xc.

EXTERN void delete_filter ( filter_t f  ) 

Clears the memory that was allocated on the heap for the filter f.

Parameters:
f a pointer to the filter
Returns:
void

Definition at line 8 of file delete_filter.c.

References filter_t::cplane, free_simple_wave_double(), and filter_t::wfbuffer.

EXTERN int filter_step_response ( filter_t f,
double *  wf,
int  itrig 
)

This routine fills the given wf with the step response of the filter. The step response is defined as wf[i] = 0. for i < itrig and wf[i] = 1. for i >= itrig.

Parameters:
f a pointer to the filter to use
wf pointer to a waveform which will be overwritten with the step response
itrig the sample number in the waveform which will have the step
Returns:
BPM_SUCCESS upon succes and BPM_FAILURE upon failure

Produces a stepresponse for the filter, step is defined by the trigger sample number the starting level and the endlevel

Definition at line 8 of file filter_step_response.c.

References apply_filter(), bpm_error(), and filter_t::ns.

EXTERN int filter_impulse_response ( filter_t f,
double *  wf,
int  itrig 
)

This routine fills the given wf with the impulse response of the filter. The impulse response is defined as wf[i] = 1. for i == itrig and wf[i] = 0. elsewhere.

Parameters:
f a pointer to the filter to use
wf pointer to a waveform which will be overwritten with the impulse response
itrig the sample number in the waveform which will have the impulse
Returns:
BPM_SUCCESS upon succes and BPM_FAILURE upon failure

Produces an impulse response for the filter, step is defined by the trigger sample number the starting level and the endlevel

Definition at line 7 of file filter_impulse_response.c.

References apply_filter(), bpm_error(), and filter_t::ns.

EXTERN filterrep_t* create_splane_representation ( filter_t f  ) 

This routine returns a pointer to a filter representation filterrep_t in the s plane for Butterworth, Chebyshev and Bessel filters. It need an initialised filter structure which has the filter type and the order set. Memory is allocated for this routine on the heap, so the user is responsible to delete this memory using free().

Parameters:
f the initialised filter with the correct options in f->options
Returns:
the filter representation in the s plane

Definition at line 32 of file create_splane_representation.c.

References _add_splane_pole(), BESSEL, bpm_error(), BUTTERWORTH, c_conj(), c_exp(), filter_t::cheb_ripple, CHEBYSHEV, complex(), filterrep_t::npoles, filter_t::options, and filter_t::order.

Referenced by create_filter().

EXTERN filterrep_t* create_resonator_representation ( filter_t f  ) 

This routine returns a pointer to a filter representation filterrep_t in the z plane for resonance filters. It needs an initialised filter structure which has the filter type and the Q factor set. Memory is allocated for this routine on the heap, so the user is responsible to delete this memory using free().

Parameters:
f the initialised filter with the correct options in f->options
Returns:
the filter representation in the z plane

Definition at line 15 of file create_resonator_representation.c.

References _eval_complex_polynomial(), _expand_complex_polynomial(), _reflect(), ALLPASS, filter_t::alpha1, BANDSTOP, bpm_error(), c_conj(), c_div(), c_exp(), complex(), FILT_EPS, complex_t::im, MAX_RESONATOR_ITER, MAXPZ, filterrep_t::npoles, filterrep_t::nzeros, filter_t::options, filterrep_t::pole, filter_t::Q, complex_t::re, and filterrep_t::zero.

Referenced by create_filter().

EXTERN filterrep_t* zplane_transform ( filter_t f,
filterrep_t s 
)

This routine transforms the poles and zeros for Bessel, Chebyshev and Butterworth filters to the z plane either via matched z transform or bilinear z transform. This is set in f->options. Memory is allocated for this routine on the heap, so the user is responsible to delete this memory using free().

Parameters:
f the filter, needs the options from it to check how to transform
s filter s plane poles and zeros
Returns:
a pointer to the z plane representation

Definition at line 8 of file zplane_transform.c.

References bpm_error(), c_div(), c_exp(), c_scale(), c_sum(), complex(), MATCHED_Z_TRANSFORM, filterrep_t::npoles, filterrep_t::nzeros, filter_t::options, filterrep_t::pole, and filterrep_t::zero.

Referenced by create_filter().

EXTERN void print_filter_representation ( FILE *  of,
filterrep_t r 
)

Prints the filter representation in terms of poles and zeros to the filepointer.

Parameters:
of the filepointer, use "stdout" to print to the terminal
r the filter representation to be printed
Returns:
void

Display filter representation

Definition at line 8 of file print_filter_representation.c.

References c_imag(), c_real(), filterrep_t::npoles, filterrep_t::nzeros, filterrep_t::pole, and filterrep_t::zero.

Referenced by print_filter().

EXTERN int normalise_filter ( filter_t f,
filterrep_t s 
)

Normalises the Butterworth, Chebyshev or Bessel filters to be Bandpass/stop or Low/Highpass

Parameters:
f the filter
s the filter's representation in the s plane
Returns:
BPM_SUCCESS upon success or BPM_FAILURE upon failure.

Definition at line 7 of file normalise_filter.c.

References bpm_error(), c_div(), c_scale(), complex(), HIGHPASS, LOWPASS, filterrep_t::npoles, filterrep_t::nzeros, filter_t::options, filterrep_t::pole, filter_t::w_alpha1, filter_t::w_alpha2, and filterrep_t::zero.

Referenced by create_filter().

EXTERN int calculate_filter_coefficients ( filter_t f  ) 

Calculates the filter coefficients from the z plane representation. Before this routine is called, one has to make sure that the member cplane, which holds a pointer to the filter's representation in the complex plane is set. This routine than calculates the filter coefficients and stores them in f->xc ( coefficients of x[n], x[n-1], x[n-2]...) and f->yc ( coefficients of y[n-1], y[n-2], y[n-3], ... in case of IIR filters ).

Parameters:
f the filter, having it's f->cplane member set to the z plan representation
Returns:
BPM_SUCCESS upon success or BPM_FAILURE upon failure.

Calculates the filter coefficients from the poles and zeros in the cplane representation... Also calculates the filter gains...

Definition at line 56 of file calculate_filter_coefficients.c.

References _eval_complex_polynomial(), _expand_complex_polynomial(), filter_t::alpha1, filter_t::alpha2, BANDPASS, BANDSTOP, c_abs(), c_div(), c_mult(), c_real(), c_sqrt(), complex(), filter_t::cplane, filter_t::dc_gain, filter_t::fc_gain, filter_t::gain, filter_t::hf_gain, HIGHPASS, LOWPASS, MAXPZ, filterrep_t::npoles, filter_t::nxc, filter_t::nyc, filterrep_t::nzeros, filter_t::options, filterrep_t::pole, filter_t::xc, filter_t::yc, and filterrep_t::zero.

Referenced by create_filter().

EXTERN int _expand_complex_polynomial ( complex_t w,
int  n,
complex_t a 
)

Helper routine to expand a complex polynomial from a set of zeros.

Parameters:
w array of complex zeros for the polynomial
n nunber of zeros
a array of coeffiecients for the polynomial that is returned
Returns:
BPM_SUCCESS upon success or BPM_FAILURE upon failure.

Calculate the polynomial coefficients in a0 + a1 * z + a2 * z^2 + a3 * z^3 + ... = (z-w1)(z-w2)(z-w3)... from the n polynomial's zero's "w" returns the results in a, the array of coefficients...

Definition at line 8 of file calculate_filter_coefficients.c.

References bpm_error(), c_imag(), c_mult(), c_neg(), c_sum(), complex(), and FILT_EPS.

Referenced by calculate_filter_coefficients(), and create_resonator_representation().

EXTERN complex_t _eval_complex_polynomial ( complex_t a,
int  n,
complex_t  z 
)

Helper routine to evaluate a complex polynomial for value z

Parameters:
a array of coeffiecients for the polynomial that is returned
n number of zeros
z the value for which to evalute the polynomial
Returns:
the value of the polynomial for z ( complex_t )

Definition at line 44 of file calculate_filter_coefficients.c.

References c_mult(), c_sum(), and complex().

Referenced by calculate_filter_coefficients(), and create_resonator_representation().


Generated on Fri Nov 9 21:17:23 2007 for libbpm by  doxygen 1.5.1