Simple biquad filter
Dependents: EMG_Filter frdm_Motor_V2_2 frdm_Motor_V2_2 frdm_Motor_V2_3 ... more
biquadFilter.h@1:b9512f750fb6, 2015-08-30 (annotated)
- Committer:
- tomlankhorst
- Date:
- Sun Aug 30 12:44:11 2015 +0000
- Revision:
- 1:b9512f750fb6
- Parent:
- 0:dca6a1d16911
- Child:
- 2:1066501736e9
Updated documentation, fixed wrong type
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomlankhorst | 0:dca6a1d16911 | 1 | #ifndef _BIQUADFILTER_H_ |
tomlankhorst | 0:dca6a1d16911 | 2 | #define _BIQUADFILTER_H_ |
tomlankhorst | 0:dca6a1d16911 | 3 | |
tomlankhorst | 1:b9512f750fb6 | 4 | |
tomlankhorst | 1:b9512f750fb6 | 5 | /** A simple Biquad-filter |
tomlankhorst | 1:b9512f750fb6 | 6 | * |
tomlankhorst | 1:b9512f750fb6 | 7 | * Example: |
tomlankhorst | 1:b9512f750fb6 | 8 | * @code |
tomlankhorst | 1:b9512f750fb6 | 9 | * #include "mbed.h" |
tomlankhorst | 1:b9512f750fb6 | 10 | * #include "biquadFilter.h" // Require the HIDScope library |
tomlankhorst | 1:b9512f750fb6 | 11 | * |
tomlankhorst | 1:b9512f750fb6 | 12 | * biquadFilter myFilter( 0.0009446914586925257 , 0.0018893829173850514 , 0.0009446914586925257 , -1.911196288237583 , 0.914975054072353 ); |
tomlankhorst | 1:b9512f750fb6 | 13 | * DigitalIn btn( PTC6 ); |
tomlankhorst | 1:b9512f750fb6 | 14 | |
tomlankhorst | 1:b9512f750fb6 | 15 | * double sampleAndFilter() |
tomlankhorst | 1:b9512f750fb6 | 16 | * { |
tomlankhorst | 1:b9512f750fb6 | 17 | * // Read digital in from button |
tomlankhorst | 1:b9512f750fb6 | 18 | * return myFilter( btn.read() ? 1 : 0 ); |
tomlankhorst | 1:b9512f750fb6 | 19 | * } |
tomlankhorst | 1:b9512f750fb6 | 20 | * @endcode |
tomlankhorst | 1:b9512f750fb6 | 21 | */ |
tomlankhorst | 1:b9512f750fb6 | 22 | |
tomlankhorst | 0:dca6a1d16911 | 23 | class biquadFilter { |
tomlankhorst | 1:b9512f750fb6 | 24 | // Constant parameters of the filter |
tomlankhorst | 0:dca6a1d16911 | 25 | const float a0, a1, a2, b1, b2; |
tomlankhorst | 1:b9512f750fb6 | 26 | // Memory |
tomlankhorst | 1:b9512f750fb6 | 27 | double z1, z2; |
tomlankhorst | 0:dca6a1d16911 | 28 | public: |
tomlankhorst | 1:b9512f750fb6 | 29 | /** |
tomlankhorst | 1:b9512f750fb6 | 30 | * Initialize the filter |
tomlankhorst | 1:b9512f750fb6 | 31 | * @param a0 |
tomlankhorst | 1:b9512f750fb6 | 32 | * @param a1 |
tomlankhorst | 1:b9512f750fb6 | 33 | * @param a2 |
tomlankhorst | 1:b9512f750fb6 | 34 | * @param b1 |
tomlankhorst | 1:b9512f750fb6 | 35 | * @param b2 |
tomlankhorst | 1:b9512f750fb6 | 36 | */ |
tomlankhorst | 0:dca6a1d16911 | 37 | biquadFilter( double, double, double, double, double ); |
tomlankhorst | 1:b9512f750fb6 | 38 | |
tomlankhorst | 1:b9512f750fb6 | 39 | /** |
tomlankhorst | 1:b9512f750fb6 | 40 | * Execute one computational step and return the output |
tomlankhorst | 1:b9512f750fb6 | 41 | * @param x : double representing the input |
tomlankhorst | 1:b9512f750fb6 | 42 | * @return y : double representing the output |
tomlankhorst | 1:b9512f750fb6 | 43 | */ |
tomlankhorst | 0:dca6a1d16911 | 44 | double step( double ); |
tomlankhorst | 0:dca6a1d16911 | 45 | }; |
tomlankhorst | 0:dca6a1d16911 | 46 | |
tomlankhorst | 0:dca6a1d16911 | 47 | #endif |