CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Running Average Computation
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sun Mar 13, 2005 6:20 pm     Reply with quote

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?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group