script zover
Dependencies: HIDScope MODSERIAL mbed
Diff: main.cpp
- Revision:
- 8:37563d2ec529
- Parent:
- 7:5f1c0bcd3f69
- Child:
- 9:cc60d28643cb
--- a/main.cpp Mon Oct 20 09:54:15 2014 +0000 +++ b/main.cpp Mon Oct 20 10:12:00 2014 +0000 @@ -37,11 +37,24 @@ return emg_value; } -float hpfilter1(float emg_value) +float notchfilter(float ylp1) +{ + static float yn,x1=0,x2=0,y1=0,y2=0,x; + x = ylp1; + yn = A0N*x + A1N*x1+A2N*x2+B1N*y1+B2N*y2; + x2 = x1; + x1 = x; + y2 = y1; + y1 = yn; + return yn; +} + + +float hpfilter1(float yn) { static float x1=0,y1=0,x2=0, y2=0,x; - x = emg_value; - yhp1 = x + A1HP1*x1 + A0HP1*x2 - B1HP1*y1 + B0HP1*y2; + x = yn; + yhp1 = x + A1HP1*x1 + A0HP1*x2 - B1HP1*y1 - B0HP1*y2; x2 = x1; x1 = x; y2 = y1; @@ -49,10 +62,10 @@ return yhp1; } -float lpfilter1(float emg_value) +float lpfilter1(float yhp1) { static float x1=0,y1=0,x2=0, y2=0,x; - x = emg_value; + x = yhp1; ylp1 = A1LP1*x1-B1LP1*y1+A0LP1*x2-B0LP1*y2; x2 = x1; x1 = x; @@ -61,17 +74,6 @@ return ylp1; } -float notchfilter(float emg_value) -{ - static float yn,x1=0,x2=0,y1=0,y2=0,x; - x = emg_value; - yn = A0N*x + A1N*x1+A2N*x2+B1N*y1+B2N*y2; - x2 = x1; - x1 = x; - y2 = y1; - y1 = yn; - return yn; -} void viewer() { @@ -99,9 +101,10 @@ while(!looptimerflag) /* do nothing */; looptimerflag = false; emg_value = readEMG(); - yhp1 = hpfilter1(emg_value); //function hpfilter - ylp1 = lpfilter1(emg_value); //function filter yn = notchfilter(emg_value); + yhp1 = hpfilter1(yn); //function hpfilter + ylp1 = lpfilter1(yhp1); //function filter + ysum = ysum+yn; n++;