Ok, yes I do remember FFT from college and have a vague idea of what it is doing. Your mention and a little reading on the inter webs helped me recall more - not sure if these are happy memories…
So, let’s give your modified approach a try and see what we can learn. This is a super basic example so, some of this is likely overkill. Still good to try.
Step 0 - I am measuring three analog values (temp inside the enclosure, temp in the soil and soil moisture). All change slowly and I am not in a rush so, I will sample once a second.
Step 1- I took 12 samples over 12 seconds and look at what they would be without filtering. Looks like there is more noise than I thought so - filtering it is.
0000233651 [app] INFO: Internal: 25.91C, Soil 28.63C, Moisture 82.00
0000234652 [app] INFO: Internal: 25.83C, Soil 26.63C, Moisture 82.08
0000235653 [app] INFO: Internal: 26.23C, Soil 27.72C, Moisture 82.19
0000236655 [app] INFO: Internal: 26.15C, Soil 28.53C, Moisture 82.13
0000237656 [app] INFO: Internal: 25.99C, Soil 26.56C, Moisture 81.97
0000238656 [app] INFO: Internal: 26.23C, Soil 28.74C, Moisture 81.95
0000239657 [app] INFO: Internal: 25.99C, Soil 26.56C, Moisture 81.97
0000240658 [app] INFO: Internal: 26.15C, Soil 28.70C, Moisture 82.21
0000241660 [app] INFO: Internal: 26.15C, Soil 27.96C, Moisture 81.95
0000242661 [app] INFO: Internal: 26.07C, Soil 27.40C, Moisture 81.97
0000243661 [app] INFO: Internal: 26.15C, Soil 28.46C, Moisture 81.97
0000244663 [app] INFO: Internal: 26.15C, Soil 27.30C, Moisture 82.24
Step 1.5 - I want to be able to collect a large number of samples and only connect to Particle occasionally to send. This could result in significant savings in power consumption. For this reason, I would like to take the data I need to collect, perform the smoothing and then store the one smoothed value in memory for the next connection event.
Step 2.0 - Trying the box car approach. I took the average of the 12 data points and compared it to the value I would get by simply looking at the integer value. Looks like averaging does help smooth out the data and would result in a different integer value about 50% of the time.
Internal S-Temp S-Moist Does Int equal Avg Int
25.91 28.63 82.00 Bad Bad Good
25.83 26.63 82.08 Bad Bad Good
26.23 27.72 82.19 Good Good Good
26.15 28.53 82.13 Good Bad Good
25.99 26.56 81.97 Bad Bad Bad
26.23 28.74 81.95 Good Bad Bad
25.99 26.56 81.97 Bad Bad Bad
26.15 28.70 82.21 Good Bad Good
26.15 27.96 81.95 Good Good Bad
26.07 27.40 81.97 Good Good Bad
26.15 28.46 81.97 Good Bad Bad
26.15 27.30 82.24 Good Good Good
Max 26.23 28.74 82.24
Min 25.83 26.56 81.95
Average 26.08 27.77 82.05
StDev 0.12 0.83. 0.11
I believe that, this may be good enough. Simply taking the average seems to create smooth value.
I looked at the Particle libraries for calculating a moving average - no clear winner I could see. Any advice would be appreciated. @gusgonnet , I looked at the library you shared but, the code was last updated 7 years ago which is a red flag for me. I also prefer to use libraries that are in the particle library system and - ideally - are both popular and validated:
search for “Average”
Step 2 - I tried getting the FFT for this data but, I don’t know if this is appropriate / reasonable for data collected at a 1/sec rate for values that change slowly. I thought it would be fun to try the steps though.
I don’t have MatLab or anything, so I went to an FFT calculator site on the web here:
I loaded up the values above and got the following graphs but, if I am being honest, I don’t know what to make of this. Perhaps sampling a faster moving signal and at higher rates would give a more insightful picture.
For this example, it feels like taking a handful of samples and then looking at the average might be good enough.
Thank you @italex , @bko and @gusgonnet for this thread. It has been interesting.