Skip to content

Commit

Permalink
bilinear interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
d00616 committed Nov 10, 2013
1 parent ae5d30e commit 791e485
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
22 changes: 21 additions & 1 deletion P300/gasSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,21 @@ uint16_t GasSensor::loopAction(char temp, char humidity)
// hpos+1,tpos-1 must be less
if (htmap_avg[hpos+1][tpos-1]>maxval) htmap_avg[hpos+1][tpos-1]=maxval;
}

// maxval: bilinear interpolation
// avoid quality jumping when temp/hum
if ( (htmap_avg[hpos][tpos+1]<65535) && (htmap_avg[hpos+1][tpos]<65535) && (htmap_avg[hpos+1][tpos+1]<65535) && (hpos<HT_MAP_COUNT_HUM-2) && (tpos<HT_MAP_COUNT_TEMP-2))
{
char modulo_temp = (temp-HT_MAP_MIN_TEMP)%HT_MAP_DIV_TEMP;
char modulo_hum = (humidity-HT_MAP_MIN_HUM)%HT_MAP_DIV_HUM;

uint16_t temp1 = interpolation(htmap_avg[hpos][tpos],htmap_avg[hpos][tpos+1], modulo_temp, HT_MAP_DIV_TEMP);
uint16_t temp2 = interpolation(htmap_avg[hpos+1][tpos],htmap_avg[hpos+1][tpos+1], modulo_temp, HT_MAP_DIV_TEMP);

maxval = interpolation(temp1,temp2, modulo_hum, HT_MAP_DIV_HUM);
}

// quality = ( (float)maxval/(float)lval)*100;
// quality = ( (float)maxval/(float)lval)*100;
float f1 = lval-maxval;
if (f1<0) f1=0;
float f2 = (maxval*SENSOR_VARIANCE)-maxval;
Expand All @@ -197,3 +210,10 @@ uint16_t GasSensor::loopAction(char temp, char humidity)

return lval;
}

uint16_t GasSensor::interpolation(uint16_t val1, uint16_t val2, char modulo, char steps)
{
if (val1<val2) return val1+((((float)val2-(float)val1)/(float)steps) * (float)modulo);
else return val2+((((float)val1-(float)val2)/(float)steps) * (float)modulo);
}

1 change: 1 addition & 0 deletions P300/gasSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class GasSensor

private:
void sethtmap(char,char, uint16_t);
uint16_t interpolation(uint16_t, uint16_t, char, char);


};
Expand Down
4 changes: 2 additions & 2 deletions P300/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ int main()
{
lq=gas.getQuality();
// if ( (gas.millis_val>1743459) && (gas.millis_val<1743714))
/*

{
cout << gas.millis_val << " " << temp1 << " " << hum1 << " " << gas.analog_val << " " << (int)gas.getQuality();
if (lq<80) cout << " STOP" << endl;
else cout << " OK" << endl;
}
*/

}
}
printhtmap();
Expand Down

0 comments on commit 791e485

Please sign in to comment.