Average period of input signal and regenerate a signal according to the cycle

  • How to implement the following functions.

    That applet takes n signals to calculate the average value, and this n can be set by itself. If n is 20, the applet will not output the first signal until it receives 20 signals, and then each output signal is the average value calculated by taking down 20 signals.