jecottrell
Joined: 16 Jan 2005 Posts: 559 Location: Tucson, AZ
|
|
Posted: Sun Mar 13, 2005 6:20 pm |
|
|
I did some reading on "median filtering" and it looks like that's what I need. It also happens to be what I tried with the 3 reading high/low discard approach. So I'll do some more testing.
Here was the gist of what I used: ( I don't have the original code available at the moment so I re-wrote it.)
Code: |
signed int16 median_filter(signed int16 value_in) {
static signed int16 holding_array[3];
int i = 0;
static int counter;
signed int16 low_val = 32767;
signed int16 high_val = -32768;
int high_loc = 0; //location in array of high value
int low_loc = 0; //location in array of low value
signed int16 median_val;
holding_array[counter] = value_in; //put incoming val in array
if(counter < 2) { //increment array
counter++;
} else {
counter = 0;
}
for(i = 0; i < 3; i++) { //find and mark highs and lows
if(holding_array[i] > high_val) {
high_val = holding_array[i];
high_loc = i;
}
if(holding_array[i] < low_val) {
low_val = holding_array[i];
low_loc = i;
}
}
median_val = holding_array[3 - (high_loc + low_loc)];
return(median_val);
}
|
Better way to do it? |
|