Author Topic: Averaging of N-X ADC sample algorithm  (Read 1880 times)

0 Members and 1 Guest are viewing this topic.

Offline ggchabTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Averaging of N-X ADC sample algorithm
« on: May 12, 2017, 11:51:14 am »
I read in the application note AN4073 of STMicroelectronics that the averaging of N-X ADC sample algorithm is a better method than the classic average of N samples.
So, the samples are stored in a table. They are sorted and the X/2 first and last samples are discarded (the ones that are probably the most dispersed). The average is then calculated for the remaining samples.
Is it really better than the classic average and is it worth the additional memory needed ? (I am doing this on a little PIC18F)
Thank you
 

Offline Rerouter

  • Super Contributor
  • ***
  • Posts: 4694
  • Country: au
  • Question Everything... Except This Statement
Re: Averaging of N-X ADC sample algorithm
« Reply #1 on: May 12, 2017, 12:49:54 pm »
What your after is not really an average, but a statistical filter, like mode or median, in reality all 3 of these approaches are more computationally expensive because you need to sort them,

What you may want to try is a limited difference average, where outside of the window the values get scaled down to have less influence, such an approach is only slightly more expensive than an average, and only needs slightly more ram than a single value average.
 

Offline Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Averaging of N-X ADC sample algorithm
« Reply #2 on: May 12, 2017, 01:16:52 pm »
Its fairly simple to do N-X averaging for X=2 as long as you are decimating.  If you are trying to do a rolling average its a lot more computationally expensive. 

e.g. Take ten readings and sum them, while tracking the max and min value, then at the end of the the group of ten, subtract the max and min from the sum then divide by eight to get the result.

The only extra overhead is two compares per sample and the subtracts at the end.

For x>2 it gets fugly and is best avoided . . . .
 

Offline ggchabTopic starter

  • Frequent Contributor
  • **
  • Posts: 276
  • Country: be
Re: Averaging of N-X ADC sample algorithm
« Reply #3 on: May 12, 2017, 01:59:16 pm »
Thanks to both of you.
The min and max method seems very simple to implement :-) I will try it.

Envoyé de mon SM-G920F en utilisant Tapatalk

 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf