ver.beta0

Committer:
macht
Date:
Wed Sep 10 05:05:17 2014 +0000
Revision:
1:2d33daf35ed1
Parent:
0:b7a168dd2734
Child:
2:4e7d58236762
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 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 1:2d33daf35ed1 21
macht 1:2d33daf35ed1 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 1:2d33daf35ed1 27
macht 1:2d33daf35ed1 28 /** initialize DigitalFilter.Need to set several parameters before calling this method.
macht 0:b7a168dd2734 29 */
macht 0:b7a168dd2734 30 int init(); //calcurate and set filter coefficients.Return value is the delay step of designed filter.
macht 1:2d33daf35ed1 31
macht 1:2d33daf35ed1 32 /**Update filter outputs.
macht 0:b7a168dd2734 33 *@param input latest input of filter
macht 0:b7a168dd2734 34 */
macht 0:b7a168dd2734 35 float update(float input); //update filter outputs.
macht 1:2d33daf35ed1 36
macht 1:2d33daf35ed1 37 /** Reset buffer of filter
macht 0:b7a168dd2734 38 */
macht 0:b7a168dd2734 39 void reset(); //reset filter inputs and past inputs(all past inputs set to 0)
macht 1:2d33daf35ed1 40
macht 1:2d33daf35ed1 41
macht 1:2d33daf35ed1 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 1:2d33daf35ed1 46
macht 1:2d33daf35ed1 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 1:2d33daf35ed1 51
macht 1:2d33daf35ed1 52
macht 1:2d33daf35ed1 53 /**accesor of q(quality factor)
macht 0:b7a168dd2734 54 *@param q quality factor
macht 0:b7a168dd2734 55 */
macht 0:b7a168dd2734 56 void set_Q(float q); //accesor of quality factor
macht 1:2d33daf35ed1 57
macht 1:2d33daf35ed1 58 /**accesor of tap(hilbert filter's tap number)
macht 0:b7a168dd2734 59 *@param tap hilbert filter's tap number
macht 0:b7a168dd2734 60 */
macht 0:b7a168dd2734 61 void set_tap(int tap); //accesor of hilbert filter's tap number
macht 1:2d33daf35ed1 62
macht 1:2d33daf35ed1 63 /**accesor of filter time constant
macht 0:b7a168dd2734 64 */
macht 0:b7a168dd2734 65 float get_tau(); //accesor of filter time constant
macht 1:2d33daf35ed1 66
macht 1:2d33daf35ed1 67 /**accesor of delay_step
macht 0:b7a168dd2734 68 */
macht 0:b7a168dd2734 69 int get_delay_step(); //get delay step of designed filter
macht 0:b7a168dd2734 70
macht 0:b7a168dd2734 71 private:
macht 0:b7a168dd2734 72 void vectorRightShift(vector<float> &array); //right shift elements of vector
macht 0:b7a168dd2734 73 void vectorSetAllToZero(vector<float> &array); //set all elements of vector to 0
macht 0:b7a168dd2734 74 vector<float> a_; //filter coefficients of denominator a
macht 0:b7a168dd2734 75 vector<float> b_; //filter coefficients of numerator b
macht 0:b7a168dd2734 76 vector<float> u_; //intermediate outputs of filter
macht 0:b7a168dd2734 77 vector<float> y_; //intermediate outputs of filter
macht 0:b7a168dd2734 78 int delay_step_; //delay step
macht 0:b7a168dd2734 79 float gain_; //filter gain
macht 0:b7a168dd2734 80 float fs_; //sampling frequency
macht 0:b7a168dd2734 81 float ts_; //sampling time
macht 0:b7a168dd2734 82 float fc_; //center frequency
macht 0:b7a168dd2734 83 float zeta_; //decrement
macht 0:b7a168dd2734 84 float Q_; //quality factor
macht 0:b7a168dd2734 85 float tau_;
macht 0:b7a168dd2734 86 int tap_; //tap number of hilbert filter
macht 0:b7a168dd2734 87 static const float pi_ = 3.141592; //circular constant
macht 0:b7a168dd2734 88 FilterType filter_type_ ;
macht 0:b7a168dd2734 89 };
macht 0:b7a168dd2734 90 #endif