EMG filter step by step
Dependencies: HIDScope MODSERIAL mbed-dsp mbed
MAF.cpp@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 | * 10-Point Moving Average Filter |
Tanja2211 | 0:e24c2f32e23e | 21 | */ |
Tanja2211 | 0:e24c2f32e23e | 22 | |
Tanja2211 | 0:e24c2f32e23e | 23 | #include "MAF.h" |
Tanja2211 | 0:e24c2f32e23e | 24 | |
Tanja2211 | 0:e24c2f32e23e | 25 | MAF::MAF(){} |
Tanja2211 | 0:e24c2f32e23e | 26 | |
Tanja2211 | 0:e24c2f32e23e | 27 | float MAF::update(float data){ |
Tanja2211 | 0:e24c2f32e23e | 28 | |
Tanja2211 | 0:e24c2f32e23e | 29 | _k[0] = data; |
Tanja2211 | 0:e24c2f32e23e | 30 | _result = _k[0]*0.1 + _k[1]*0.1 + _k[2]*0.1 + _k[3]*0.1 + _k[4]*0.1 + _k[5]*0.1 + _k[6]*0.1 + _k[7]*0.1 + _k[8]*0.1 + _k[9]*0.1 ; |
Tanja2211 | 0:e24c2f32e23e | 31 | _k[9] = _k[8]; |
Tanja2211 | 0:e24c2f32e23e | 32 | _k[8] = _k[7]; |
Tanja2211 | 0:e24c2f32e23e | 33 | _k[7] = _k[6]; |
Tanja2211 | 0:e24c2f32e23e | 34 | _k[6] = _k[5]; |
Tanja2211 | 0:e24c2f32e23e | 35 | _k[5] = _k[4]; |
Tanja2211 | 0:e24c2f32e23e | 36 | _k[4] = _k[3]; |
Tanja2211 | 0:e24c2f32e23e | 37 | _k[3] = _k[2]; |
Tanja2211 | 0:e24c2f32e23e | 38 | _k[2] = _k[1]; |
Tanja2211 | 0:e24c2f32e23e | 39 | _k[1] = _k[0]; |
Tanja2211 | 0:e24c2f32e23e | 40 | |
Tanja2211 | 0:e24c2f32e23e | 41 | return _result; |
Tanja2211 | 0:e24c2f32e23e | 42 | } |
Tanja2211 | 0:e24c2f32e23e | 43 | |
Tanja2211 | 0:e24c2f32e23e | 44 | int MAF::updateInt(int data){ |
Tanja2211 | 0:e24c2f32e23e | 45 | |
Tanja2211 | 0:e24c2f32e23e | 46 | _a[0] = data; |
Tanja2211 | 0:e24c2f32e23e | 47 | _result = _a[0]*0.1 + _a[1]*0.1 + _a[2]*0.1 + _a[3]*0.1 + _a[4]*0.1 + _a[5]*0.1 + _a[6]*0.1 + _a[7]*0.1 + _a[8]*0.1 + _a[9]*0.1 ; |
Tanja2211 | 0:e24c2f32e23e | 48 | _a[9] = _a[8]; |
Tanja2211 | 0:e24c2f32e23e | 49 | _a[8] = _a[7]; |
Tanja2211 | 0:e24c2f32e23e | 50 | _a[7] = _a[6]; |
Tanja2211 | 0:e24c2f32e23e | 51 | _a[6] = _a[5]; |
Tanja2211 | 0:e24c2f32e23e | 52 | _a[5] = _a[4]; |
Tanja2211 | 0:e24c2f32e23e | 53 | _a[4] = _a[3]; |
Tanja2211 | 0:e24c2f32e23e | 54 | _a[3] = _a[2]; |
Tanja2211 | 0:e24c2f32e23e | 55 | _a[2] = _a[1]; |
Tanja2211 | 0:e24c2f32e23e | 56 | _a[1] = _a[0]; |
Tanja2211 | 0:e24c2f32e23e | 57 | |
Tanja2211 | 0:e24c2f32e23e | 58 | return _resultInt; |
Tanja2211 | 0:e24c2f32e23e | 59 | } |