Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Extract Gradient ( in real time)

Status
Not open for further replies.

Neyolight

Full Member level 5
Joined
Aug 29, 2011
Messages
306
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
World
Activity points
3,624
Hi all

I am looking to extract the gradient of my sensor data I capture (real time). Im not sure how to do that.

Lets say the sensor plots a "V" shaped graph in response of an external stimulus ( Please see the image). All I need to do is capture X1, Y1 and X2 and Y2 (please see the image) . But im unsure how to do that.

To add to my problem, the sensor reading vary within 10 points (bug in code maybe or something). So if the sensor is suppose to give an output of 100, the actual output (on UART) will vary between 95-105. So im not sure how to go about capturing the gradient.

Im coding in C, over MPLAB and using PIC18 micro.

Thanks


---------- Post added at 17:13 ---------- Previous post was at 17:11 ----------

Also Im capturing my sensor output every 81 ms .
 

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...
 
Hi, how to identify the minima( Y2). We would need another check in the if loop to see if the current value is greater than the previous value, keeping in mind values vary randomly up to 10 points. :|
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top