plan a window, I assume that X is time in 81ms steps, and Y is the actual data from your sensor...
say we begin with some stable data Y=y0 at x= 0, after 1 time step (81ms) it keeps with Y=y0 (x now is = 1[or 81 if you don't like time steps]) now, always save your previous data in y1... so:
Code:
Y=readSensor();//for the first time...
x=0;
for(;;){
y0=Y;
x0=X;
Y=readSensor();
X= X+1;
//maybe add a 81ms delay if readSensor doesn't do that...
}
after some steps, ( as in your picture) Y will be different enough from y0 to be marked as y2, how much different??? here comes the window!!!
Code:
Y=readSensor();//for the first time...
x=0;
for(;;){
y0=Y;
x1=X;
Y=readSensor();
X= X+1;
if(abs(Y-y0)>3){ //here my data window is 3!!!!
//if my sensor data varies further that 3 it's a change!
y1=y0; //the previous value before the drop...
x1=x0;
y2=Y; //the new data with the drop
x2=X; //see the value of X
}
//maybe add a 81ms delay if readSensor doesn't do that...
}
please make a better graph with more points and which event do you want to record/recognice (as a gradient will be the Y2-Y1 value, not only y2)...
for your other question:
now, you need to see the specs on the datasheet of your sensor, or if it's analogic, of your ADC, to see the repeatably and total error rate. say if your sensor reads from 0 to 1000 and it has a non-repeat error of 0.5% and you read a value of 100, it will ALWAYS vary from 95 to 105, and it will never get a clean 100 value reading... of course you can make some kind of data filter (FIR, IIR), or another data window (read like 12 times, add them, and divide by 12... ), to make your reading more stable...