I've made an aneometer, that measures windspeed by counting the rotations of a propeller blade spinning in the air, the airspeed is then displayed on a screen.
So far so good. But with the first version there was a small problem, the windspeed was fluctuating so rapidly that the display was changing so fast it was almost unreadable.
My first attempt to steady and smooth the windspeed simply involved loading the the last 20 values into an array, and averaging them. This made a slight improvement, but the displayed value was still changing too much to be very good.
The 2nd idea was to limit the rate-of-change of the displayed value to within specified parameters. Again this was an improvement, sudden large fluctuations were removed, but still not perfect.
The 3rd step was simply to limit the number of times per second that the screen would be updated. This was another slight improvement, but still not ideal.
At this point it occurred to me that smoothing out continuously varying values for display must be a pretty 'standard' problem, and therefore there's a probably a 'standard' solution - a standard mathematical function that I can plug my input values into and get a nice smooth and stabilized output from.
Is there? if so what? - Or do I just have to continue tweaking the input values until I get some display values that I like?
Fulliautomatix:
My first attempt to steady and smooth the windspeed simply involved loading the the last 20 values into an array, and averaging them. This made a slight improvement, but the displayed value was still changing too much to be very good.
Looks like either a big mistake in the hardware or in the software.
What is it all? Reed contact anemometer? Pull resistors? Circuit schematics? Code?
You don't want us to make wild guesses about all the mistakes you are making to read bad wind speed results, don't you?
I believe the solution I've found is actually working - i.e. it's correctly reporting what the anemometer is doing. The things is that because I'm display airspeed in meters/second to two decimal places, the 2nd decimal place is changing at a blur, and the 1st decimal place is changing very rapidly to.
I'd like to update the screen let's say two or three times a second - once every 300 - 500 milliseconds.
I'm not really asking for a fix to programming problem, what I've done does actually work ok. What I'm saying is that this must be a pretty routine issue - stabilizing a set of fluctuating values, and I can't help feeling there must be a pretty routine solution?
Noisy sensor readings are a fact of life. Most often, the simplest, and most effective, approach to getting stable readings is to apply a simple digital low-pass filter to the readings. This will mitigate the impact of "outlier" readings, and give a smoothly changing output. And, for wind speed, you don't need to see the reading with 1 mSec resolution. What you care about is more the average reading over the last second, or several seconds.
Averaging - adding a range of samples then dividing by their total
Checking for variance and setting a tolerance - is it so different from the last result?
Cross fading - blend between the two
These functions eat up processing time but should be sufficient to get you three refreshes per second.
FYI - I would be reluctant to post code on this forum unless you want the moderators to pick it apart. I've recently posted my own issue, my first and probably my last. Not a friendly forum and definately not one for the home enthusiast - more a hardcore user forum.
At this point it occurred to me that smoothing out continuously varying values for display must be a pretty 'standard' problem, and therefore there's a probably a 'standard' solution - a standard mathematical function that I can plug my input values into and get a nice smooth and stabilized output from.
Why are you trying to falsify the data?
There are two good answers
More pulses per second - Say 10 pulse per revevolution and not just one
Take the reading over a longer period.
In addition to every thing else drop every thing after the decimal point, it's useless over accuracy.
I'd like to update the screen let's say two or three times a second
Why is it important to update the display this frequently ?
If you want to introduce the idea of knowing how much the speed is changing then you could have more data displayed. You could, for instance, display the current wind speed every 5 seconds and the max and min wind speeds recorded during the previous 5 seconds.
It certainly seems true that the price for help is often a little bit of abuse and sarcasm. - I often find myself thinking I'm eight years old and back at school! You must remember that the gurus have often heard a question a thousand time before and think the answer is blindingly obvious!
I would be reluctant to post code on this forum unless you want the moderators to pick it apart
But thats kinda what you wanted isn't it? It can be very hard to help without seeing what they've already done, but you're right if you're a beginner they'll rip you shreds! What I find amusing is that sometime I get pestered to post my code even when I'm not actually asking for a code-fix!
On this forum I'm a novice, but on others I walk on water. When I'm the one giving advice I always try to temper my answer with a bit of patience.
Why are you trying to falsify the data?
I'm not. The Windspeed probe I'm using is designed to be plugged into a smartphone, it comes with an app that always displays the data very smoothly, so rather than jumping from 1.5 m/s to 2.0 m/s in one change it scrolls from 1.5 to 1.6, to 1.7 and 1.8 without missing any values. I'm trying to do something similar (and have mostly succeeded)
apply a simple digital low-pass filter to the readings.
I think this is the key phrase I've been looking for. Are there any 'standard' algorithms for doing this? Or do all low pass filters need to be designed individually from scratch for each specific application? Or best of all, can someone direct me to an 'idiots guide' to low pass filters for arduinos?
Fulliautomatix:
Are there any 'standard' algorithms for doing this? Or do all low pass filters need to be designed individually from scratch for each specific application? Or best of all, can someone direct me to an 'idiots guide' to low pass filters for arduinos?
You mean like the actual code I already posted that you apparently didn't bother to read??
Fulliautomatix:
Sorry I didn't acknowledge your contribution Ray! I read your code, understood it and used it, thank you!
I was just wondering if there were better, more sophisticated filters available that possibly use more than 3 lines of code.
Regards
Of course there are. Digital filters come in all levels of complexity, up to ones that only a handful of people in the world truly understand. But for what you're doing, they would add complexity, with little benefit. Getting the best possible result requires understanding the nature of the noise, and custom-designing a digital filter to suit. NOT a beginners project.