EMG filter step by step
Dependencies: HIDScope MODSERIAL mbed-dsp mbed
MAF.h@0:e24c2f32e23e, 2014-10-20 (annotated)
- Committer:
- Tanja2211
- Date:
- Mon Oct 20 13:06:38 2014 +0000
- Revision:
- 0:e24c2f32e23e
d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Tanja2211 | 0:e24c2f32e23e | 1 | /* Copyright (c) <2012> MIT License |
Tanja2211 | 0:e24c2f32e23e | 2 | * |
Tanja2211 | 0:e24c2f32e23e | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
Tanja2211 | 0:e24c2f32e23e | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
Tanja2211 | 0:e24c2f32e23e | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
Tanja2211 | 0:e24c2f32e23e | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
Tanja2211 | 0:e24c2f32e23e | 7 | * furnished to do so, subject to the following conditions: |
Tanja2211 | 0:e24c2f32e23e | 8 | * |
Tanja2211 | 0:e24c2f32e23e | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
Tanja2211 | 0:e24c2f32e23e | 10 | * substantial portions of the Software. |
Tanja2211 | 0:e24c2f32e23e | 11 | * |
Tanja2211 | 0:e24c2f32e23e | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
Tanja2211 | 0:e24c2f32e23e | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
Tanja2211 | 0:e24c2f32e23e | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
Tanja2211 | 0:e24c2f32e23e | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
Tanja2211 | 0:e24c2f32e23e | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Tanja2211 | 0:e24c2f32e23e | 17 | * |
Tanja2211 | 0:e24c2f32e23e | 18 | * @section DESCRIPTION |
Tanja2211 | 0:e24c2f32e23e | 19 | * |
Tanja2211 | 0:e24c2f32e23e | 20 | * Moving Average Filter |
Tanja2211 | 0:e24c2f32e23e | 21 | * |
Tanja2211 | 0:e24c2f32e23e | 22 | * |
Tanja2211 | 0:e24c2f32e23e | 23 | */ |
Tanja2211 | 0:e24c2f32e23e | 24 | |
Tanja2211 | 0:e24c2f32e23e | 25 | #ifndef MAF_H |
Tanja2211 | 0:e24c2f32e23e | 26 | #define MAF_H |
Tanja2211 | 0:e24c2f32e23e | 27 | |
Tanja2211 | 0:e24c2f32e23e | 28 | #include "mbed.h" |
Tanja2211 | 0:e24c2f32e23e | 29 | |
Tanja2211 | 0:e24c2f32e23e | 30 | /** 10-Point Moving Average filter |
Tanja2211 | 0:e24c2f32e23e | 31 | * |
Tanja2211 | 0:e24c2f32e23e | 32 | * Example: |
Tanja2211 | 0:e24c2f32e23e | 33 | * @code |
Tanja2211 | 0:e24c2f32e23e | 34 | * // Update the filter with gyroscope readings |
Tanja2211 | 0:e24c2f32e23e | 35 | * #include "mbed.h" |
Tanja2211 | 0:e24c2f32e23e | 36 | * #include "ITG3200.h" |
Tanja2211 | 0:e24c2f32e23e | 37 | * #include "MAF.h" |
Tanja2211 | 0:e24c2f32e23e | 38 | * |
Tanja2211 | 0:e24c2f32e23e | 39 | * Serial pc(USBTX, USBRX); |
Tanja2211 | 0:e24c2f32e23e | 40 | * ITG3200 gyro(p9, p10); |
Tanja2211 | 0:e24c2f32e23e | 41 | * MAF Filter(); |
Tanja2211 | 0:e24c2f32e23e | 42 | * int Average; |
Tanja2211 | 0:e24c2f32e23e | 43 | * |
Tanja2211 | 0:e24c2f32e23e | 44 | * int main() { |
Tanja2211 | 0:e24c2f32e23e | 45 | * |
Tanja2211 | 0:e24c2f32e23e | 46 | * gyro.setLpBandwidth(LPFBW_42HZ); |
Tanja2211 | 0:e24c2f32e23e | 47 | * |
Tanja2211 | 0:e24c2f32e23e | 48 | * while(1){ |
Tanja2211 | 0:e24c2f32e23e | 49 | * |
Tanja2211 | 0:e24c2f32e23e | 50 | * Average = Filter.updateInt(gyro.getGyroX()); |
Tanja2211 | 0:e24c2f32e23e | 51 | * pc.printf("%i\n",Average); |
Tanja2211 | 0:e24c2f32e23e | 52 | * wait_ms(50); |
Tanja2211 | 0:e24c2f32e23e | 53 | * } |
Tanja2211 | 0:e24c2f32e23e | 54 | * } |
Tanja2211 | 0:e24c2f32e23e | 55 | * @endcode |
Tanja2211 | 0:e24c2f32e23e | 56 | */ |
Tanja2211 | 0:e24c2f32e23e | 57 | class MAF { |
Tanja2211 | 0:e24c2f32e23e | 58 | |
Tanja2211 | 0:e24c2f32e23e | 59 | public: |
Tanja2211 | 0:e24c2f32e23e | 60 | |
Tanja2211 | 0:e24c2f32e23e | 61 | /* Creates a 10-Point Moving Average Filter object |
Tanja2211 | 0:e24c2f32e23e | 62 | * |
Tanja2211 | 0:e24c2f32e23e | 63 | */ |
Tanja2211 | 0:e24c2f32e23e | 64 | MAF(void); |
Tanja2211 | 0:e24c2f32e23e | 65 | |
Tanja2211 | 0:e24c2f32e23e | 66 | /* Updates the filter |
Tanja2211 | 0:e24c2f32e23e | 67 | * @param data new data input for the filter,returns the float average |
Tanja2211 | 0:e24c2f32e23e | 68 | */ |
Tanja2211 | 0:e24c2f32e23e | 69 | float update(float data); |
Tanja2211 | 0:e24c2f32e23e | 70 | |
Tanja2211 | 0:e24c2f32e23e | 71 | /* Updates the filter |
Tanja2211 | 0:e24c2f32e23e | 72 | * @param data new data input for the filter, returns the integer average |
Tanja2211 | 0:e24c2f32e23e | 73 | */ |
Tanja2211 | 0:e24c2f32e23e | 74 | int updateInt(int data); |
Tanja2211 | 0:e24c2f32e23e | 75 | |
Tanja2211 | 0:e24c2f32e23e | 76 | private : |
Tanja2211 | 0:e24c2f32e23e | 77 | |
Tanja2211 | 0:e24c2f32e23e | 78 | float _k[10]; |
Tanja2211 | 0:e24c2f32e23e | 79 | int _a[10]; |
Tanja2211 | 0:e24c2f32e23e | 80 | |
Tanja2211 | 0:e24c2f32e23e | 81 | float _result; |
Tanja2211 | 0:e24c2f32e23e | 82 | int _resultInt; |
Tanja2211 | 0:e24c2f32e23e | 83 | }; |
Tanja2211 | 0:e24c2f32e23e | 84 | |
Tanja2211 | 0:e24c2f32e23e | 85 | #endif |