Algorithm to filter spikes
hi guys...
i working maxbotix xl sonar sensor.
the output pulse of sensor (pin 2) varies in width when sees object in it's sights.
58 microsecs = 1 cm.
so 44.4 ms = 765 cm. (it's max reading distance)
i using pulsein read pulse width.
this works fine spikes no object around.
i testing in basement getting side clutter spikes.
is there algorithms out there (i'm sure there are) filter occassional spike or 2 in row ignored?
i reading sensor every 100 ms.
right let variable used counter run between 0 , 20.
it inc's on object , dec's on no object.
when variable > 9 says there object.
here code:
thanks or code!
i have gotten arduino uno , forum lot.
btw, why did convert inches centimeters?
i testing accuracy of sensor , printing output serial monitor.

i working maxbotix xl sonar sensor.
the output pulse of sensor (pin 2) varies in width when sees object in it's sights.
58 microsecs = 1 cm.
so 44.4 ms = 765 cm. (it's max reading distance)
i using pulsein read pulse width.
this works fine spikes no object around.
i testing in basement getting side clutter spikes.
is there algorithms out there (i'm sure there are) filter occassional spike or 2 in row ignored?
i reading sensor every 100 ms.
right let variable used counter run between 0 , 20.
it inc's on object , dec's on no object.
when variable > 9 says there object.
here code:
code: [select]
void loop()
{
duration = pulsein(sensor_pin,high,timeout);
inches = (duration/58)*0.3937008; // convert centimeters inches
if (inches < distance)
{
z++;
}
else
{
z--;
}
if (z > 20) z=20;
if (z < 0) z=0;
if (z > 9)
{
digitalwrite(12,high);
}
else
{
digitalwrite(12,low);
}
}
thanks or code!
i have gotten arduino uno , forum lot.
btw, why did convert inches centimeters?
i testing accuracy of sensor , printing output serial monitor.

there several ways of dealing spikes, depending on trying accomplish. call pulsein in loop, , read 5 values , add them up. after loop, divide sum 5, average distance.
you make copy of current reading @ end of loop, , compare new reading previous reading. if difference small, accept new reading. otherwise, ignore it.
a lot depends on how big spikes in comparison average reading, whether spike should influence average, or not, , how variation there in average reading, in particular how fast average reading changes.
whether did depends on data sheet told output of sensor, magic numbers mean, , types variables involved have. without seeing of code, can't tell.
as why, can tell that.
you make copy of current reading @ end of loop, , compare new reading previous reading. if difference small, accept new reading. otherwise, ignore it.
a lot depends on how big spikes in comparison average reading, whether spike should influence average, or not, , how variation there in average reading, in particular how fast average reading changes.
quote
btw, why did convert inches centimeters?
whether did depends on data sheet told output of sensor, magic numbers mean, , types variables involved have. without seeing of code, can't tell.
as why, can tell that.
Arduino Forum > Forum 2005-2010 (read only) > Software > Interfacing > Algorithm to filter spikes
arduino
Comments
Post a Comment