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

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
01/08/03 21:37
Read: times


 
#35968 - RE: 12-bit adc
The filter example cited a couple of posts up is not a good averaging program! Dividing each sample like that by two before adding is next to worthless.

A better floating filter routine is to keep the filter as an even power of two bytes so that the averaging divide is easy to do. Next you need a circular index that points to the oldest entry in the table. This is the place to put the next newest sample at next averaging call. The index is then incremented to the next oldest location (with wrap at end of buffer).

Then if you want performance over simplicity you can keep a running sum of all the items in the filter. At next sample you subtract the oldest sample from this sum first...then put the new sample in the array over the oldest one, and add the newst one to the sum. This permits the new average to be obtained with one subtract, one add, and of course the divide to get the average from the sum which can simply be a shift if you used 2, 4, 8, or 16 entries in the filter table. I like to use filters with 16 samples because then the shifting can be done with the SWAP and some ORs.

Any time you use a filter it is necessary to get it initialized properly before using the results of it. One way is to let "N" sample periods elapse before using the filtered results, where N is the number of samples in the filter table. Another way is simply to call the filter update routine rapidly in quick succession N times after the index has been initialized. It is also necessary to zero all the filter table entries (and the runniung sum if you use that technique). With the running sum scheme, if you zero everything first there is no need to actually initialize a "sum" because the table all filled with zeros is == to the zeroed sum).

Michael Karas



List of 16 messages in thread
TopicAuthorDate
12-bit adc            01/01/70 00:00      
RE: 12-bit adc            01/01/70 00:00      
RE: 12-bit adc            01/01/70 00:00      
RE: 12-bit adc            01/01/70 00:00      
RE: 12-bit adc            01/01/70 00:00      
RE: 12-bit adc            01/01/70 00:00      
RE: 12-bit adc            01/01/70 00:00      
RE: 12-bit adc - Mike            01/01/70 00:00      
RE: 12-bit adc - Mike            01/01/70 00:00      
RE: 12-bit adc - Erik / Steve            01/01/70 00:00      
RE: 12-bit adc - Erik / Steve            01/01/70 00:00      
RE: 12-bit adc            01/01/70 00:00      
RE: 12-bit adc / Rob            01/01/70 00:00      
RE: 12-bit adc / Rob            01/01/70 00:00      
RE: 12-bit adc / Rob            01/01/70 00:00      
RE: 12-bit adc / Rob            01/01/70 00:00      

Back to Subject List