File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,6 +66,39 @@ int Devlpr::lastValueCentered()
6666 return lastVal - wAvg;
6767}
6868
69+ unsigned int Devlpr::windowPeakAmplitude ()
70+ {
71+ // use the window average as the reference point (should be close to DC offset)
72+ int wAvg = windowAvg ();
73+ // and need to find the max absolute value from ref
74+ unsigned int peak = 0 ;
75+ for (int i = 0 ; i < BUFSIZE; i++) { // no need to start from bufInd
76+ int currDiff = (int )buf[i] - wAvg;
77+ int currAbs = abs (currDiff);
78+ if (currAbs > peak) {
79+ peak = currAbs;
80+ }
81+ }
82+ return peak;
83+ }
84+
85+ unsigned int Devlpr::windowPeakToPeakAmplitude ()
86+ {
87+ // and need to find the max absolute value from ref
88+ unsigned int peak = 0 ;
89+ unsigned int trough = 1023 ;
90+ for (int i = 0 ; i < BUFSIZE; i++) { // no need to start from bufInd
91+ unsigned int currVal = buf[i];
92+ if (currVal > peak) {
93+ peak = currVal;
94+ }
95+ if (currVal < trough) {
96+ trough = currVal;
97+ }
98+ }
99+ return peak - trough;
100+ }
101+
69102int Devlpr::scheduleFunction (void (*f)(Devlpr *d), unsigned int millisPer)
70103{
71104 // check first if we are out of space to attach more functions
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ class Devlpr
1111 unsigned int lastValue ();
1212 int lastValueCentered ();
1313 unsigned int windowAvg ();
14+ unsigned int windowPeakAmplitude ();
15+ unsigned int windowPeakToPeakAmplitude ();
1416 int scheduleFunction (void (*f)(Devlpr *d), unsigned int millisPer);
1517 private:
1618 // emg buffer bookkeeping
Original file line number Diff line number Diff line change 33Devlpr devlpr;
44
55void printEMG (Devlpr *d) {
6- int result = d->lastValueCentered ();
6+ int result = d->windowPeakToPeakAmplitude ();
77 Serial.println (result);
88}
99
You can’t perform that action at this time.
0 commit comments