|
发表于 2014-9-19 17:12:36
|
显示全部楼层
本帖最后由 yigang 于 2014-9-19 17:13 编辑
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
uInt4 MEAN_FILTER(uChar LEV_OR_SURF)
{ // [1][2][3][4][5],
// 5 POINT MEAN FILTER: ^
// |--------------> OUTPUT.
static uInt4 LEV_CAL_BUFF[5] = { // Buffer of level value calculate.
0,0,0,0,0 };
static uInt4 SUR_CAL_BUFF[5] = { // Buffer of INTERFACE value calculate.
0,0,0,0,0 };
uInt4 NEW_VALUE, *pt, v_temp;
uInt2 i, j;
if (LEV_OR_SURF == LEVEL) {
pt = (uInt4 *) &LEV_CAL_BUFF[0];
*(pt+4) = NEW_VALUE = lev_value_pulse; // Append data to buffer.
}
else {
pt = (uInt4 *) &SUR_CAL_BUFF[0];
*(pt+4) = NEW_VALUE = sur_value_pulse; // Append data to buffer.
}
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
if (*(pt+j) > *(pt+j+1)) {
v_temp = *(pt+j);
*(pt+j) = *(pt+j+1);
*(pt+j+1) = v_temp;
}
}
}
v_temp = *(pt+2); // New mean value.
for (i = 0; i < 3; i++)
*(pt+i) = *(pt+i+1); //shift data to new order
*(pt+3) = NEW_VALUE;
return v_temp;
} |
|