Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
08/14/02 13:44
Read: times


 
#27227 - moving average
Kunal wrote:
--------------------------------------------
"Hey can anybody tell me a bit more about my moving average code? Is it right, is it as innovative as I thought, or is it the normal way to go about it?"


Hi Kunal,

I started a new thread, to make it easier to search for this topic later.

Following an example written completely in C, maybe it was similiar to this, what you mean:


#define SAMPLE_COUNT    16

#define div_rnd(x,y)    ((x + (x >> 1)) / y)


int moving_average( int val )
{
  static int samples[SAMPLE_COUNT] = { 0 };
  static char sample_no = 1;

  int aver = 0;
  char i;

  if( --sample_no == 0 )
    sample_no = SAMPLE_COUNT;

  for( i = SAMPLE_COUNT; i; i-- ){
    if( i == sample_no )
      samples[i-1] = val;
    aver += samples[i-1];
  }
  return div_rnd( aver, SAMPLE_COUNT );
}



Now my previous example again, but it has a different characteristic. I know not if it was also named "moving average":

adc_input[channel] -= adc_input[channel] / SAMPLE_COUNT
                   - (((uint)ADDH << 2) | (ADDL & 0x03));



Peter


List of 12 messages in thread
TopicAuthorDate
moving average            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: Steve            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: Peter.            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: moving average            01/01/70 00:00      
RE: moving average            01/01/70 00:00      

Back to Subject List