dScript Averaging

Hello

I need help to write an averaging function in dScript v4-15.
Devantech said to use bit-shifting in this format: average = average + ((new_value - average)>>2)

Anybody?
Thanks

Hi @martyk ,

I haven’t use dScript but did you try any of the AI tools to generate this code for you?

Olivia: Doesn’t matter as long as it works.
Thanks.

Yes Igor, tried them all. Github is the closest. Thanks.

Glad to see you’re diving into dScrip

Since you’re looking for an averaging method, are you thinking of a simple Moving Average or a Block Average? I’ve found that even a small ‘buffer’ array can handle this well in dScript. If you want to see a similar implementation logic, RobotShop has a great guide on understanding sensor data and noise that touches on how to handle these jumpy readings


Also, just a heads-up: if your sensor is particularly jumpy, sometimes adding a tiny delay between your ADC reads can give the hardware enough time to settle. I’m curious, what kind of sensor are you working with? I might have some specific logic I can share depending on what you’re trying to smooth out! :smile:

Oliver

Thanks for responding.

My sensors are not unstable or noisy. For now, they are connected directly to the board.
I have 4 sensors: 1 humidity, 1 barometric pressure, and 2 MCP9700 which are the worst.
It seems that the longer the algorithm, the more jumpy the result.

According to Devantech, “a successive approximation ADC is going to have some noise”. They suggested to take an average of several readings using an array, then each time change 1 value, then add all the values and divide by the array length.
Or by bit-shifting: “average = average + ((new_value - average)>>2)”

I wrote the function in the DSI file ok, but the execution in javascript section of index.htm does not execute.

Thanks for the help.

Somebody must have written a function for this problem.

There is almost no support for dScript, which is really disappointing. Devantech should have a website similar to Github.

After looking at this problem, I agree with your idea. But, I think the discussion here is also useful to ask the questions and get the solution.

Well I AM asking !
Where is everybody?

Maybe you could try asking Devantech again:
https://www.robot-electronics.co.uk/contact