Goal: give a moving average of a measurement like belt throughput, i.e. smooth or dampen the input signal so it doesn't fluctuate too much
This can be implemented in 3 combinators only, but I use slightly more to make it more understandable:
This displays the throughput of the belt as items/minute, counter courtesy of DaveMcW (viewtopic.php?f=193&t=19825&start=60#p282391)
All red wires are control, green wires are content
The main work is done by the central combinator, which embodies the main formula explained above: V_new = V_old - V_old/S + Input = V_old - V_old*N + Input
The addition is implemented by putting all components together on the input side.
- V_old is its own output (of the previous tick)
- V_old * N is the output of the bottom combinator (memory decay)
- Input is the V output of the top combinator (input)
Thus, every tick calculates a new version of V to which input is added and a fraction of the previous output is removed. The resulting variable V can be seen as the exponential average times the smoothing factor.
The combinator settings itself are the simple 'memory cell' / counter, where the output is copied to the input unless the red reset signal is nonzero:
Input: The topmost combinator scales up the input value (everything) and outputs it as V (for value):
The bottom combinator divides the current value of V by N, which is the negative value of the smoothing factor (so -100 if the smoothing factor is 100):
N is calculated by multiplying the constant value S by -1 in the constant and arithmetic combinators on the left hand side:
(the red signal is the reset signal: set to 1 to reset the counter, set back to zero to resume counting)
The final combinator scales down the value by dividing by the smoothing constant S:
In this case it ouputs to A because the counter wants its input on A, but of course you can put it on whatever you want.
Here is a more compact version for 'copy paste' use. Input is anything on the green signal to the topleft; output is set on the bottom right, here A on the red signal:
(note that instead of a red reset signal this has a green control signal so you can reset by simply switching off the combinator; also, I manually calculate N=S*-1 to get rid of one combinator)
As said above, none of this is original, but I hope the explanation and blueprint string might be of use. If there are any mistakes or inefficiencies please let me know!