4

Based on a continuous realtime event stream (where time of every event is easily known, but each event has no value, they are all identical), how program a filter/process that would output a continuous smooth event rate? By continuous I meant that it could for example be plotted as a graph, which instead of just times of each event, would give information about estimated event rate at each particular time. I know that "smooth" can probably be ambiguous, but I am looking for the simplest way to do this to make the resulting graph look smooth. For example there should not be any big spikes at each event.

Cray
  • 2,178
  • 17
  • 26

2 Answers2

2

By averaging. for example everytime you get an event add one to a. every second remove 1/60 of a. it will give you a simple average with a sliding window of about one minute.

Markus Mikkolainen
  • 3,329
  • 16
  • 21
  • "everytime you get an event add one to a" - that will produce spikes at the time of each event, the ones I mentioned I would like to avoid. – Cray Jul 31 '12 at 01:05
  • very little spikes unless your events are very uncommon. – Markus Mikkolainen Jul 31 '12 at 01:07
  • 2
    if you want a fancy solution, maybe design a kalman filter to approximate the event rate? – Markus Mikkolainen Jul 31 '12 at 01:13
  • This solution is not working at all. It will take many events to converge to the correct rate unless you start with a good approximation for a. Assuming you have one event per second and you start with a = 0 you will need 350 events until you get within 3% of the correct rate value which is 1 / second. – scharette Aug 05 '14 at 23:01
2

This can be implemented with a moving average. Take your last N events where N is the size of your averaging window. Compute the time difference between the first and the last of these N events. If you are measuring in seconds and want the rate in event per minute you would then divide 60 seconds by your time difference expressed in seconds and you multiply by N-1.

currentAvgRate = (N-1) * 60 / (time different between last N events)

The greater the value of N the smoother your curve will be, but also the less it will react to local changes.

scharette
  • 525
  • 1
  • 5
  • 19