ver.beta0

Committer:
macht
Date:
Thu Sep 18 13:07:09 2014 +0000
Revision:
2:4e7d58236762
Parent:
1:2d33daf35ed1
add API documentation

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