Hi, Scoupe

An elegant way would be to compare the instant value of the signal to its mean value ( a R/C ladder with 0.2 or 0.5s time constant is enough ) of your signal ...

So, the reference level will always being adjusted to your signal level ...

That is what I use for Light detection ( RPM optical meters ...) to be aware of ambient light

Alain