Hi Team
I wanted to ask you if anyone has ever done a FIFO floating point average, I would need to do this type of average on a sample of 50 results after they have been converted by a sensor with SPI interface, looking in the forum it does not seem like anyone has already done so, what is the correct approach for you?
Thank you
AVERAGE FLOATING POINT
Moderator: Benj
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: AVERAGE FLOATING POINT
Hi.
I'm using a BME280 Temperature/Humidity/Pressure Sensor.
So I could calculate altitude, It was vital the pressure float results were ultra-stable.
To do that I used The altitude was so stable it could measure the height of me lol.
Note: I used ground to keep floats rounded up to 2dp.
I'm using a BME280 Temperature/Humidity/Pressure Sensor.
So I could calculate altitude, It was vital the pressure float results were ultra-stable.
To do that I used The altitude was so stable it could measure the height of me lol.
Note: I used ground to keep floats rounded up to 2dp.
Martin
Re: AVERAGE FLOATING POINT
Hello Medelec35
thanks for your submission but I think it is not good for my work, I had already done such a thing, if I understand correctly yours is a mathematical average made on 150 samples, and having a loop of 1 mS it can be said that the result that you could theoretically see on a display would be every 150mS, unfortunately my times are much longer as I receive new data only every 200mS so with an average set to 50 I have a new value to send to the display every 10Sec, I would need it a FIFO type average, that when I filled the buffer, I update the oldest data with the new one and recalculate the result, and I would have an update every 200mS
I hope I have understood your example, otherwise correct me
thanks for your help
thanks for your submission but I think it is not good for my work, I had already done such a thing, if I understand correctly yours is a mathematical average made on 150 samples, and having a loop of 1 mS it can be said that the result that you could theoretically see on a display would be every 150mS, unfortunately my times are much longer as I receive new data only every 200mS so with an average set to 50 I have a new value to send to the display every 10Sec, I would need it a FIFO type average, that when I filled the buffer, I update the oldest data with the new one and recalculate the result, and I would have an update every 200mS
I hope I have understood your example, otherwise correct me
thanks for your help
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: AVERAGE FLOATING POINT
Here's an example using a FIFO list of data (just random data here...)
The macro AddValue does all the work - main just pumps in data and displays debug to UART (with a lomg delay that could be reduced for simulation...)
Martin
The macro AddValue does all the work - main just pumps in data and displays debug to UART (with a lomg delay that could be reduced for simulation...)
Martin
-
- Valued Contributor
- Posts: 784
- Joined: Fri Jun 06, 2014 3:53 pm
- Has thanked: 186 times
- Been thanked: 205 times
-
- Valued Contributor
- Posts: 1208
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 70 times
- Been thanked: 440 times
Re: AVERAGE FLOATING POINT
No problem, hope it is useful
If speed is important then make the sum global and subtract the existing value (buffer[pos]) before adding the new value... Then you can remove the loop too...
Math
If speed is important then make the sum global and subtract the existing value (buffer[pos]) before adding the new value... Then you can remove the loop too...
Math