Measure the change of data points from the line; Catch Dip

How to measure this area in C ++?

(update: I sent the solution and code as an answer, rather than editing the question again)

How to quantify the blue area between ideal curve and measured curve
The ideal line (dashed red) is a graph from the starting point, with the average growth increasing with each angle of measurement; I get it on average. I measured the test data in black. How can I quantify the area of ​​incidence in blue? The X axis is unified, so slopes and math are simplified.

I could determine the cutoff for such areas, and then mark this part for re-inspection or rejection. Rarely, there is another failure that appears closer to the right, but setting the cut-off value for the standard deviation usually leads to errors in these parts.

Update

. , , , " ".:)
Better visualization of the problem


?

X - . , 0,75 ° 10- , Y. - data[idx] idx,value, (x,y). , .

TPS .

() ; , .. 15 °, "" . , .

, , 10 , 120 , . , uC32 PIC32 microcontroller, , .


: X, , . , " : 0 : 14". deltas.

deltas, , Std Dev . dip , , Std Dev ( 2.3), , . 2.6, . , , , Std Dev .

, , . Kurtosis , . , , , . , , , , AVG deltas . R ^ 2 - .

AVG Std Dev , deltas. . , 2x Std Dev Average. , AVG, , AVG+Std Dev AVG. , , . 15 ° .

deltas deltas , , . 5 deltas , . , , AVG , 2,9 3 . 6 15 . AVG -35.

AVG , deltas, AVG, . , AVG. , - , . , AVG 2x AVG, . 8 , sumOfDiffs AVG.

float sumOfDiffs=0.0;
for( int idx=0; idx<stop; idx++ ){
    float spread = deltas[idx] - line->AdcAvgRise;
    sumOfDiffs = sumOfDiffs + spread;
    ...
    testVal = 2*line->AdcAvgRise;
    if( sumOfDiffs > testVal || sumOfDiffs < -testVal ){
        flag = 'S';
    }
    ...
}

58 , sumOfDiffs AVG! , 120 sumOfDiffs -0.000057.

sumOfDiffs 0,000000, .000100. , : " " .

sumOfDiffs , . , sumOfDiffs , 2x AVG, AVG . deltas idx 23 49; 17,25 ° 19,5 °.

Avg rise: 6.75    Std dev: 2.577
idx: delta  diff from avg   sumOfDiffs  Flag
 23:   5    -1.75           -14.05      S
 24:   6    -0.75           -14.80      S
 25:   7     0.25           -14.55      S
 26:   5    -1.75           -16.30      S
 27:   3    -3.75           -20.06      S
 28:   3    -3.75           -23.81      S
 29:   7     0.25           -23.56      S
 30:   4    -2.75           -26.31      S
 31:   2    -4.75           -31.06      S
 32:   8     1.25           -29.82      S
 33:   6    -0.75           -30.57      S
 34:   9     2.25           -28.32      S
 35:   8     1.25           -27.07      S
 36:   5    -1.75           -28.82      S
 37:  15     8.25           -20.58      S
 38:   7     0.25           -20.33      S
 39:   5    -1.75           -22.08      S
 40:   9     2.25           -19.83      S
 41:  10     3.25           -16.58      S
 42:   9     2.25           -14.34      S
 43:   3    -3.75           -18.09      S
 44:   6    -0.75           -18.84      S
 45:  11     4.25           -14.59      S
 47:   3    -3.75           -16.10      S
 48:   8     1.25           -14.85      S
 49:   8     1.25           -13.60      S
Final Sum of diffs: 0.000030
RunningStats analysis:
NumDataValues= 125
Mean= 6.752
StandardDeviation= 2.577
Skewness= 0.251
Kurtosis= -0.277

:, , , OEM- , 4- . Arduino 8k , TFT- 3 °! deltas , . 120- 30- , .

+4
2

  • , 0.
    • , 0.
    • , , , , diff , , .
  • , , , - : AREA, :
    • , .
    • ( ) , .
    • ( , , ) , .
    • , " ", , , .
  • , :
    • , , , .
      • , , - , .
      • , , ( ), , ,
      • , . , , " " . , , , .

  • , , , - " ". :
    • RANSAC ( IMHO)
      • .
      • , , (IMHO)
    • ,
      • , , , .
      • , , , .
    • 10 10
      • - , , , , - , -
      • , -
  • Y, X
  • ( Y_dev = Y_data - Y_straight, ) :
    • PositiveMax = 0; NegativeMax = 0;
    • ( ) tmp_Area
      • ,
        • , , PositiveMax NegativeMax, PositiveMax NegativeMax
        • reset tmp_Area = Y_dev; ,
    • , , , , .
    • , NegativeMax .
    • , , Y_dev , .
    • , , ,
      • .
    • , .
      • : , , , . , , , , .... , , , ..... .
+1

, - . , Math.SE, , "Cross Validated" , Stats.SE.

Math.SE. , .: P :

Plot of data gathered, highlighting the dip

"": , deltas, 0,75 ° . "Rise" "slope" - : dy/dx.

"" deltas , , . deltas, , .

Average of the Numerical Integral of the derivative

2.6. " ", , , .

, - , , . , . , dipCountLimit 5. dip-/ (, Numerical Integrator) , , + . AVG + STD DEV , .

int dipdx=0;
//  inDipFlag also counts the length of this dip
int inDipFlag=0;
float dips[140] = { 0.0 };
for( int idx=0; idx<stop; idx++ ){
    const float diffFromAvg = deltas[idx] - line->AdcAvgRise;
    //  state machine to monitor dips
    const int _stop = stop-1;
    if( diffFromAvg < 0 && idx < _stop ) {
        //  check NEXT data point for negative diff & set dipFlag to put state in dip
        const float nextDiff = deltas[idx+1] - line->AdcAvgRise;
        if( nextDiff < 0 && inDipFlag == 0 )
            inDipFlag = 1;
        //  already IN a dip, and next diff is negative
        if( nextDiff < 0 && inDipFlag > 0 ) {
            inDipFlag++;
        }

        //  accumulate this dip
        dips[dipdx]+= diffFromAvg;

        //  next data point ends this dip and we advance dipdx to next dip
        if( inDipFlag > 0 && nextDiff > 0 ) {
            if( inDipFlag < dipCountLimit ){
                //  reset the accumulator, do not advance dipdx to next entry
                dips[dipdx]=0.0;
            } else {
                //  change this entry value from dip sum to its ratio
                dips[dipdx] = -dips[dipdx]/inDipFlag;
                //  advance dipdx to next entry
                dipdx++;
            }
            //  Next diff isn't negative, so the dip is done
            inDipFlag = 0;
        }
    }
}
+1
source

All Articles