ver.beta0

Committer:
macht
Date:
Wed Sep 10 04:28:53 2014 +0000
Revision:
0:b7a168dd2734
Child:
1:2d33daf35ed1
Digital Filter Libraries beta ver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
macht 0:b7a168dd2734 1 #ifndef DIGITALFILTER_H
macht 0:b7a168dd2734 2 #define DIGITALFILTER_H
macht 0:b7a168dd2734 3 #include "mbed.h"
macht 0:b7a168dd2734 4 #include "math.h"
macht 0:b7a168dd2734 5 #include<vector>
macht 0:b7a168dd2734 6
macht 0:b7a168dd2734 7 //enumrator to choose filter type
macht 0:b7a168dd2734 8 typedef enum FilterType{
macht 0:b7a168dd2734 9 LPF1,
macht 0:b7a168dd2734 10 LPF2,
macht 0:b7a168dd2734 11 HPF1,
macht 0:b7a168dd2734 12 HPF2,
macht 0:b7a168dd2734 13 RESONANCE,
macht 0:b7a168dd2734 14 NOTCH,
macht 0:b7a168dd2734 15 HILBERT,
macht 0:b7a168dd2734 16 }FilterType;
macht 0:b7a168dd2734 17
macht 0:b7a168dd2734 18 class DigitalFilter
macht 0:b7a168dd2734 19 {
macht 0:b7a168dd2734 20 public:
macht 0:b7a168dd2734 21 /**
macht 0:b7a168dd2734 22 * Create a DigitalFilter instance
macht 0:b7a168dd2734 23 *@param filter_type desired filter type
macht 0:b7a168dd2734 24 *@param fs sampling frequency
macht 0:b7a168dd2734 25 */
macht 0:b7a168dd2734 26 DigitalFilter(FilterType filter_type,float fs); //constructor, choose filter type and set sampling frequency
macht 0:b7a168dd2734 27 /**
macht 0:b7a168dd2734 28 /**
macht 0:b7a168dd2734 29 * initialize DigitalFilter.Need to set several parameters before calling this method.
macht 0:b7a168dd2734 30 */
macht 0:b7a168dd2734 31 int init(); //calcurate and set filter coefficients.Return value is the delay step of designed filter.
macht 0:b7a168dd2734 32 /**
macht 0:b7a168dd2734 33 *Update filter outputs.
macht 0:b7a168dd2734 34 *@param input latest input of filter
macht 0:b7a168dd2734 35 */
macht 0:b7a168dd2734 36 float update(float input); //update filter outputs.
macht 0:b7a168dd2734 37 /**
macht 0:b7a168dd2734 38 /*Reset buffer of filter
macht 0:b7a168dd2734 39 */
macht 0:b7a168dd2734 40 void reset(); //reset filter inputs and past inputs(all past inputs set to 0)
macht 0:b7a168dd2734 41 /**
macht 0:b7a168dd2734 42 *accesor of fc(center frequency)
macht 0:b7a168dd2734 43 *@param fc center frequency
macht 0:b7a168dd2734 44 */
macht 0:b7a168dd2734 45 void set_fc(float fc); //accesor of fc(center frequency)
macht 0:b7a168dd2734 46 /**
macht 0:b7a168dd2734 47 *accesor of zeta(decrement)
macht 0:b7a168dd2734 48 *@param zeta decrement of filter
macht 0:b7a168dd2734 49 */
macht 0:b7a168dd2734 50 void set_zeta(float zeta); //accesor of zeta(decrement)
macht 0:b7a168dd2734 51 /**
macht 0:b7a168dd2734 52 *accesor of q(quality factor)
macht 0:b7a168dd2734 53 *@param q quality factor
macht 0:b7a168dd2734 54 */
macht 0:b7a168dd2734 55 void set_Q(float q); //accesor of quality factor
macht 0:b7a168dd2734 56 /**
macht 0:b7a168dd2734 57 *accesor of tap(hilbert filter's tap number)
macht 0:b7a168dd2734 58 *@param tap hilbert filter's tap number
macht 0:b7a168dd2734 59 */
macht 0:b7a168dd2734 60 void set_tap(int tap); //accesor of hilbert filter's tap number
macht 0:b7a168dd2734 61 /**
macht 0:b7a168dd2734 62 *accesor of filter time constant
macht 0:b7a168dd2734 63 */
macht 0:b7a168dd2734 64 float get_tau(); //accesor of filter time constant
macht 0:b7a168dd2734 65 /**
macht 0:b7a168dd2734 66 *accesor of delay_step
macht 0:b7a168dd2734 67 */
macht 0:b7a168dd2734 68 int get_delay_step(); //get delay step of designed filter
macht 0:b7a168dd2734 69
macht 0:b7a168dd2734 70 private:
macht 0:b7a168dd2734 71 void vectorRightShift(vector<float> &array); //right shift elements of vector
macht 0:b7a168dd2734 72 void vectorSetAllToZero(vector<float> &array); //set all elements of vector to 0
macht 0:b7a168dd2734 73 vector<float> a_; //filter coefficients of denominator a
macht 0:b7a168dd2734 74 vector<float> b_; //filter coefficients of numerator b
macht 0:b7a168dd2734 75 vector<float> u_; //intermediate outputs of filter
macht 0:b7a168dd2734 76 vector<float> y_; //intermediate outputs of filter
macht 0:b7a168dd2734 77 int delay_step_; //delay step
macht 0:b7a168dd2734 78 float gain_; //filter gain
macht 0:b7a168dd2734 79 float fs_; //sampling frequency
macht 0:b7a168dd2734 80 float ts_; //sampling time
macht 0:b7a168dd2734 81 float fc_; //center frequency
macht 0:b7a168dd2734 82 float zeta_; //decrement
macht 0:b7a168dd2734 83 float Q_; //quality factor
macht 0:b7a168dd2734 84 float tau_;
macht 0:b7a168dd2734 85 int tap_; //tap number of hilbert filter
macht 0:b7a168dd2734 86 static const float pi_ = 3.141592; //circular constant
macht 0:b7a168dd2734 87 FilterType filter_type_ ;
macht 0:b7a168dd2734 88 };
macht 0:b7a168dd2734 89 #endif