| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| lala Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				| What is averaging algorithm? |  
				|  Posted: Thu Jun 03, 2004 3:08 am |   |  
				| 
 |  
				|   
 hello;
 
 What is averaging algorithm? i just study on resistive touchscreen technology and want to know how the averaging algorithm apply to this technology?
 
 thank you
 |  | 
	
		|  | 
	
		| SteveS 
 
 
 Joined: 27 Oct 2003
 Posts: 126
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Jun 03, 2004 8:33 am |   |  
				| 
 |  
				| Since filtering comes up a lot I wrote up a real short and simple introduction to filters in the code section. Hope that helps. 
 - SteveS
 |  | 
	
		|  | 
	
		| bdring Guest
 
 
 
 
 
 
 
			
			
			
			
			
			
			
			
			
 
 | 
			
				|  |  
				|  Posted: Fri Jun 11, 2004 2:01 pm |   |  
				| 
 |  
				| I often use a rolling average.  You can call this hundreds or times without the need to store a bunch of values in RAM.  Adjust the variable type to fit your application.  It is not very fast, but it works for me. 
 
 
  	  | Code: |  	  | int16 avg(int16 oldVal, int16 newVal, int8 sampleNo) {
 return = oldVal + (newVal-oldVal)/sampleNo;
 }
 
 | 
 
 
 Initialize the value to zero and call it as shown below.
 
 
  	  | Code: |  	  | oldVal = 0; oldVal = avg(oldVal, 100, 1);
 oldVal = avg(oldVal, 120, 2);
 oldVal = avg(oldVal, 140, 3);
 | 
 oldVal will hold the average at every stage and end up with 130 in this case.
 |  | 
	
		|  | 
	
		|  |