#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 RESONATOR |
Bitmask for Resonator filter
Definition at line 36 of file bpm_dsp.h.
Referenced by create_filter().
#define BILINEAR_Z_TRANSFORM |
#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 ALLPASS |
Normalise filter as allpass ( resonator )
Definition at line 48 of file bpm_dsp.h.
Referenced by create_resonator_representation().
#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().
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.
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
|
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).
f | pointer to a filter that was created using create_filter | |
wf | an array containing the waveform to be filtered |
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.
of | the filepointer, use "stdout" to print to the terminal | |
f | the filter to be printed |
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.
f | a pointer to the filter |
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.
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 |
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.
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 |
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().
f | the initialised filter with the correct options in f->options |
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().
f | the initialised filter with the correct options in f->options |
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().
f | the filter, needs the options from it to check how to transform | |
s | filter s plane poles and zeros |
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.
of | the filepointer, use "stdout" to print to the terminal | |
r | the filter representation to be printed |
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
f | the filter | |
s | the filter's representation in the s plane |
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 ).
f | the filter, having it's f->cplane member set to the z plan representation |
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().
Helper routine to expand a complex polynomial from a set of zeros.
w | array of complex zeros for the polynomial | |
n | nunber of zeros | |
a | array of coeffiecients for the polynomial that is returned |
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().
Helper routine to evaluate a complex polynomial for value z
a | array of coeffiecients for the polynomial that is returned | |
n | number of zeros | |
z | the value for which to evalute the polynomial |
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().