Finding a change in a signal I am looking to some C algorithm(for MCU), where I have these signals :


First graph you can see that there is an event in the middle and it goes back to normal, second and third there is some event at a certain point.
Any of them can happen per session(= when I turn the device there will be 1 behavior)

I have to find  real time when the event begin and ends, and it has to be FAST.


All maximums in all 3 graphs are more or less the same (with 2% diff)
I don't know the values before hand but I can calibrate the "no event" state.
I need 1 algorithm to all of them.


I can do all sorts of basic stuff with averages and LPF, but I guess there is more clever and generic way to do so (?)

Something that can cover all cases and do what my eyes do - I can just tell where is the event.
You need to be sure about:


Noise power is bounded
The power of the signal step is higher than 4 times that noise power.


If the noise power is bounded and the change in the signal level is higher than 4 times that noise power (from the pictures it seems to be so, I mean, the step is more than twice the max value of noise), why not take the derivative of the signal? something like:

step = abs(x[n] - x[n-1]);
if (step &gt; threshold)
{
  // Event has happened: 
  // 1. Take timer value
  event_time = get_time();
  // 2. Update the state machine
  state = (state == START_STATE) ? STOP_STATE : START_STATE;
}


Well, the get_timer() is specific to your MCU and there are better ways to implement a Finite State Machine, but that is the idea. It is fast and fulfills the requirements, I would not go further.