So I'm working on a project using HC-SR04 Ultrasonic Proximity sensors. I'd like to use these sensors to detect the proximity of a person within its operational range/angle. I think the best way for me to do this is to have the arduino read the values from the sensors, and spit out the average of everything every half second.
I'd also like to filter false values or outliers when calculating this average.
Is there a way to do this? Also, is there a way to do this for 5 sensors simultaneously (ex. A125 B400 C400 D400 E400 if there's only someone occupying the space in sensor A, 125cm away, with 400cm being the max operational range
Since the sensors don't always operate at a consistent rate, I don't want to have to specify a number of values to average. I want the code to read for 500ms, and give me the mean value (excluding outliers) of all the readings that were taken during that time.
Using an Arduino Uno Rev3
Bonus: How can I set a range of values (1-400) and have Arduino place those values on a scale of 1-100? I'll be doing more research on that later, but I might as well ask while I'm here.
I am using an Uno (should have stated that above). It looks like movingAvg takes the average of a specific number of readings? I'd like to collect a flexible number of readings within a certain timeframe (500ms) and take the average of those.
That's the part I'm stuck on. I'm not even sure what to add/remove from the code to make it do what I need it to do, which is why I asked here. I've looked on a few other threads, but none of them specifically do what I need, and I'm not sure where to begin on it.
The movingAvg is helpful as a baseline, but it presents the same issue as the 200 other threads that tell me how to average a set number of data points.
we used dual rate averages for speech and background noise for speech detection in speakerphones. dual rate means K is different for attack, samp > avg and decay. for speech, the attack rate is higher than the decay rate. for noise the attack rate was very low but the decay rate very fast.
With many/most sensors, I often find it very useful to first apply a median filter to the raw sensor readings, to discard spurious readings. There is an Arduino median filter library that works just fine, you just have to figure out how long the buffer needs to be to make it maximally effective for the particular system. After the median filter, use a simple digital low-pass filter to "smooth" the output.
For most sensors, at rational sample rates, with a reasonable buffer length, the computational load is pretty minimal. As with most thing, more is rarely better.
Do they seem to update at a faster rate when there is an object in front of the sensor, and the closer the object, the faster the rate? If so, that's just the speed of sound, I think! The closer the object, the quicker the echo is received and the more readings your code will make over a given period. At 4m distance, the echo would be received around 23ms after the sensor is triggered. At 1.25m distance, the echo would be received around 7ms after. (I'm assuming speed of sound is ~350m/s)
Why do you want the output to be at this "perfect" rate? Why is that important?
If you want an average output from all 5 sensors every half second, you can spend only around 100ms reading each sensor. So you may only have time to take 4 readings per sensor, if your code reads the sensors in the "normal" way. That's not a very large sample size to be worthwhile doing any complex statistics on.
If you can find a way to take measurements on all 5 sensors simultaneously, maybe you can get at least 20 readings from each sensor in half a second. But that's difficult to code, beyond beginner level, and would only work if you can be certain that the 5 sensors can't possibly pick up signals from each other.