Thomas Plaisier / Mbed 2 deprecated G3_Barry_Plotter.

Dependencies:   MODSERIAL mbed Encoder

main.cpp

Committer:
Socrates
Date:
2013-10-16
Revision:
4:513c33bba011
Parent:
3:935347ab4e12
Child:
5:1a1ce2f5cb66

File content as of revision 4:513c33bba011:

#include "mbed.h"
#include "MODSERIAL.h"

AnalogIn emg(PTB0);
MODSERIAL pc(USBTX,USBRX);

volatile bool looptimerflag;

void setlooptimerflag(void)
{
    looptimerflag = true;
}


int main()
{
    Ticker looptimer;
    const float ts=0.001;
    looptimer.attach(setlooptimerflag,ts);
    float x,y,y1,y2,x1,z,z1,z2,yabs,yabs1,yabs2,k,numh1,numh2,denh1,denh2,numl1,numl2,numl3,denl1,denl2,denl3;
    x1=0;
    y1=0;
    y2=0;
    z1=0;
    z2=0;
    yabs1=0;
    yabs2=0;

    numh1=0.996868235770807;
    numh2=-0.996868235770807;
    //denh1=1;
    denh2=-0.993736471541615;
    numl1=0.391302053991682*pow(10.0,-4.0);
    numl2=0.782604107983365*pow(10.0,-4.0);
    numl3=0.391302053991682*pow(10.0,-4.0);
    //denl1=1;
    denl2=-1.982228929792529;
    denl3=0.982385450614126;
    pc.baud(115200);

    while(1) {
        while(looptimerflag != true);
        looptimerflag = false;
        k=emg.read();
        x=(k-0.5)*2.0;

        //High pass, 1 Hz
        //1e orde
        y=x*numh1+x1*numh2-y1*denh2;
        
        //Rectify
        yabs=abs(y);

        //Low pass, 2 Hz
        //2e orde
        z=yabs*numl1+yabs1*numl2+yabs2*numl3-z1*denl2-z2*denl3;
        
        pc.printf("%f\n\r",z);
        x1=x;
        y2=y1;
        y1=y;
        z2=z1;
        z1=z;
        yabs2=yabs;
        yabs1=yabs;
    }
}