|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#16
|
|||||
|
|||||
|
Re: Sensor "de-noising"
Quote:
|
|
#17
|
|||||
|
|||||
|
Re: Sensor "de-noising"
While Kevin's approach is far more elegant, this might work for you in a pinch:
Code:
/* some set-up */
#include <stdio.h>
#define true 1
#define false !true
typedef char boolean;
/* a program to run the stuff */
int main (void)
{
static int array[5] = {0,0,0,0,0};
static int counter = 0;
boolean persistence;
boolean digitalInput;
int i;
/* run the persistance checker in a loop */
for (i=0; i<10; i++)
{
/* put in some false then put in some true */
if(i>4)
digitalInput = true;
else
digitalInput = false;
/* check on the input and fill the
* persistence array with the result
*/
if( digitalInput)
array[counter] = 1;
else
array[counter] = 0;
/* keep tabs on the array index */
counter++;
if(counter > 4)
counter = 0;
/* now AND the entire array and show the result */
persistence = array[0] && array[1] && array[2] && array[3] && array[4];
printf(" perist = %d \n",persistence);
}
}
...ugly but it could work Eric Last edited by EricS-Team180 : 05-03-2013 at 13:34. |
|
#18
|
||||
|
||||
|
Re: Sensor "de-noising"
Here's a simple IIR filter which does essentially the same thing with 2 lines of code, no loops, and no conditional logic: Code:
ave = 0.5*(input+ave); output = truncate(ave+0.03); input and output are 0 or 1. |
|
#19
|
||||
|
||||
|
Re: Sensor "de-noising"
Last year we created a class to handle averaging out our noise. we were using this for sensors that gave us analog data, but you could send in 1.0 and 0.0 on the output side for a digital signal.
What ended up being nice about this class last year was that we could very easily change how many samples were being included in the average. As we started to speed things up throughout the season, we needed the average to be more responsive (fewer samples) Here's the Java code: https://gist.github.com/jcorcoran/5097376 |
|
#20
|
||||
|
||||
|
Re: Sensor "de-noising"
Quote:
|
|
#21
|
|||||
|
|||||
|
Re: Sensor "de-noising"
Quote:
Mind you, it's probably a perfectly cromulent and simple solution to the OP's actual problem, it just seems different than actual debouncing. |
|
#22
|
||||
|
||||
|
Re: Sensor "de-noising"
Quote:
If you want to debounce in both directions, change the second line to Code:
if(output==0) output=truncate(ave+0.03); else output=truncate(ave+1-0.03); Last edited by Ether : 06-03-2013 at 09:42. |
|
#23
|
|||
|
|||
|
Re: Sensor "de-noising"
Quote:
|
|
#24
|
||||
|
||||
|
Re: Sensor "de-noising"
Quote:
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|