Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: HIDScope biquadFilter circular_buffer mbed
Fork of EMG by
Revision 26:97a8adc9b895, committed 2017-10-24
- Comitter:
- Roytsg
- Date:
- Tue Oct 24 10:48:48 2017 +0000
- Parent:
- 25:9c2fc98da6b3
- Child:
- 27:674193a62e06
- Commit message:
- array wise moving average 10 samples
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 24 10:11:31 2017 +0000
+++ b/main.cpp Tue Oct 24 10:48:48 2017 +0000
@@ -16,18 +16,8 @@
* this function samples the emg and sends it to HIDScope
**/
- double a1 = 0;
- double a2 = 0;
- double a3 = 0;
- double a4 = 0;
- double a5 = 0;
- double a6 = 0;
- double a7 = 0;
- double a8 = 0;
- double a9 = 0;
- double a10 = 0;
- double a11 = 0;
- double a12 = 0;
+ double A[10];
+
void sample()
{
@@ -57,22 +47,22 @@
scope.set(0, emgFiltered );
scope.set(1, emgabs );
- a12 = a11;
- a11 = a10;
- a9 = a8;
- a8 = a7;
- a7 = a6;
- a6 = a5;
- a5 = a4;
- a4 = a3;
- a3 = a2;
- a2 = a1;
- a1 = emgabs;
+ for(int i = 9; i >= 0; i--){
+ if (i == 0) {
+ A[i] = emgabs;
+ }
+ else {
+ A[i] = A[i-1];
+ }
+ }
+ double sum = 0;
+ for (int n = 0; n < 9; n++) {
+ sum = sum + A[n];
+ }
- double moving = a1 + a2 + a3 + a4 + a5;
- double movmean = moving/5;
- scope.set(2, movmean );
+ double movmean = sum/10;
+ scope.set(2, movmean);
scope.send();
}
